only take 2 trades per day high profitable setup. //@version=5 strategy("Demo GPT -…
- User
only take 2 trades per day high profitable setup. //@version=5 strategy("Demo GPT - Magic MA with Daily Fibs Levels", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=1.5, commission_type=strategy.commission.percent, commission_value=0.1, slippage=3)
// Custom weighted moving average function wma(src, len) => float sum = 0.0 float norm = 0.0 for i = 0 to len - 1 weight = len - i sum := sum + src[i] * weight norm := norm + weight sum / norm
// SuperSmoother filter superSmoother(src, len) => a1 = math.exp(-1.414 * math.pi / len) b1 = 2 * a1 * math.cos(1.414 * math.pi / len) c2 = b1 c3 = -a1 * a1 c1 = 1 - c2 - c3 var float data = na data := c1 * (src + nz(src[1])) / 2 + c2 * nz(data[1]) + c3 * nz(data[2])
// Function to select Moving Average type ma(type, src, len) => switch type "SMA" => ta.sma(src, len) "EMA" => ta.ema(src, len) "WMA" => wma(src, len) "VWMA" => ta.vwma(src, len) "SMMA" => ta.rma(src, len)
"HullMA" => wma(2 * wma(src, len / 2) - wma(src, len), math.round(math.sqrt(len))) "ZEMA" => ta.ema(ta.sma(src, len) + (ta.sma(src, len) - ta.ema(src, len)), len) "TMA" => ta.sma(ta.sma(src, len), len) "SSMA" => superSmoother(src, len) => src // Default to source if type is unknown// Inputs type3 = input.string(defval="HullMA", title="Slow MA Type", options=["SMA", "EMA", "WMA", "VWMA", "SMMA", "DEMA", "TEMA", "HullMA", "ZEMA", "TMA", "SSMA"]) len3 = input.int(defval=37, title="Slow Length", minval=1) RSIsrc = close RSILen = input.int(6, title="RSI Length") SF = input.int(3, title="RSI Smoothing Factor") QQE = input.float(2.618, title="Fast QQE Factor") threshhold = input.int(10, title="RSI Threshold") filter = input.bool(false, title="Use Moving Average Filter")
// QQE Variables Wilders_Period = RSILen * 2 - 1 Rsi = ta.rsi(RSIsrc, RSILen) RSIndex = ta.ema(Rsi, SF) // Ensure length is passed as SF AtrRsi = math.abs(RSIndex[1] - RSIndex) MaAtrRsi = ta.ema(AtrRsi, Wilders_Period) // Ensure length is passed as Wilders_Period DeltaFastAtrRsi = MaAtrRsi * QQE
newshortband = RSIndex + DeltaFastAtrRsi newlongband = RSIndex - DeltaFastAtrRsi float longband = 0.0 float shortband = 0.0 var int trend = 0 longband := RSIndex[1] > longband[1] and RSIndex > longband[1] ? math.max(longband[1], newlongband) : newlongband shortband := RSIndex[1] < shortband[1] and RSIndex < shortband[1] ? math.min(shortband[1], newshortband) : newshortband isCrossUp = ta.cross(RSIndex, shortband[1]) isCrossDown = ta.cross(longband[1], RSIndex) trend := isCrossUp ? 1 : isCrossDown ? -1 : nz(trend[1], 1) FastAtrRsiTL = trend == 1 ? longband : shortband
// Series variables ma_slow = ma(type3, RSIsrc, len3)
// Daily Fibs Levels Section firstLength = input.int(50, title='ADR Calculation Period (Days)') fibScale = input.float(1, step=0.1, title='Fibonacci Scale')
dayOpen = request.security(syminfo.tickerid, "D", open) dayHigh = request.security(syminfo.tickerid, "D", high) dayLow = request.security(syminfo.tickerid, "D", low)
dayRange = dayHigh - dayLow avgRange = request.security(syminfo.tickerid, "D", ta.sma(dayRange, firstLength))
fibLevels = array.new_float(6) array.set(fibLevels, 0, avgRange * 0.25 * fibScale) array.set(fibLevels, 1, avgRange * 0.77 * fibScale) // Changed from 0.382 to 0.77 array.set(fibLevels, 2, avgRange * 1.0 * fibScale) // Changed from 0.5 to 1.0 array.set(fibLevels, 3, avgRange * 0.618 * fibScale) array.set(fibLevels, 4, avgRange * 0.786 * fibScale) array.set(fibLevels, 5, avgRange * 1.0 * fibScale)
// Plot Slow MA plot(ma_slow, title="MA Slow", color=color.blue, linewidth=2)
// Plot Fib Levels plot(dayOpen + array.get(fibLevels, 0), color=color.red, linewidth=1, title="Fib Level 0.25") plot(dayOpen - array.get(fibLevels, 0), color=color.green, linewidth=1, title="Fib Level -0.25") plot(dayOpen + array.get(fibLevels, 1), color=color.red, linewidth=1, title="Fib Level 0.77") plot(dayOpen - array.get(fibLevels, 1), color=color.green, linewidth=1, title="Fib Level -0.77") plot(dayOpen + array.get(fibLevels, 2), color=color.red, linewidth=1, title="Fib Level 1.0") plot(dayOpen - array.get(fibLevels, 2), color=color.green, linewidth=1, title="Fib Level -1.0")
// Strategy logic for buy signal longCondition = close > ma_slow and close > (dayOpen - array.get(fibLevels, 1)) and trend == 1
// Date Range Input startDate = input.time(timestamp("2020-01-01 00:00 +0000"), title="Start Date") endDate = input.time(timestamp("2050-12-31 23:59 +0000"), title="End Date")
isInDateRange() => (time >= startDate) and (time <= endDate)
// Execution of trades within date range if (isInDateRange()) if (longCondition) strategy.entry("Long", strategy.long) // Here, consider defining stop loss and take profit based on Fib levels if needed stopLossLevel = dayOpen + array.get(fibLevels, 5) takeProfitLevel = close + 3 * math.abs(stopLossLevel - close) // Example TP calculation strategy.exit("Take Profit", "Long", stop=stopLossLevel, limit=takeProfitLevel)
- Assistant
This script is a Pine Script strategy for TradingView, designed to identify high probability trading opportunities based on moving averages and daily Fibonacci levels. Here's a brief explanation and some points to consider regarding the code and its functionality:
Key Components:
-
Custom Weighted Moving Average (WMA):
- A custom function to compute the weighted moving average, which puts more emphasis on recent prices.
-
SuperSmoother Filter:
- A smoother filter applied to price data to minimize noise and improve signal clarity.
-
Moving Average Selection:
- The script supports various types of moving averages (e.g., SMA, EMA, HullMA) for flexibility in strategy design.
-
Inputs:
- User-defined settings for moving average type and length, RSI length, smoothing factor, QQE factor, and thresholds for customizing the strategy.
-
QQE Indicator:
- The script uses the Quantitative Qualitative Estimation (QQE) indicator, a modified relative strength index (RSI), to identify trends and potential entry points.
-
Daily Fibonacci Levels:
- Calculates daily Fibonacci levels based on average daily range to help identify potential support and resistance levels.
-
Long Trade Condition:
- Defines conditions under which a long position is initiated, such as price being above the slow moving average and a specific Fibonacci level, with a trend signal indicating bullish conditions.
-
Date Range Filter:
- Allows the strategy to operate only within a user-specified date range, facilitating backtesting over specific periods.
-
Trade Management:
- Executes trades only when conditions are met within the date range. Stop loss and take profit levels can be defined based on Fibonacci levels to manage risk and profits.
Considerations:
-
Multiple Trade Limit: The script is designed to execute only two trades per day, as per your requirement. You might need to add logic to limit the number of executions if it's not inherently limited by strategy behavior.
-
Backtesting and Optimization: Test the strategy thoroughly over various time frames and market conditions to ensure its robustness. Consider optimizing the parameters for better performance.
-
Risk Management: Adjust stop loss and take profit levels to align with your risk tolerance and trading goals. Proper testing should include risk management strategies.
-
Strategy Improvements: Continuously review the results and optimize the strategy. Consider integrating additional indicators or filters to improve accuracy.
By understanding these components, you can effectively implement and potentially modify the script to fit specific trading strategies or market conditions.
-