// Define the length for the lookback period length = 8
// Calculate the highest high and lowest low of the previous 'length' candles, excluding the current candle highestHigh = ta.highest(high[1], length) lowestLow = ta.lowest(low[1], length)
// Initialize a variable to track the current position var int position = 0 // 0 = no position, 1 = buy, -1 = sell
// Generate Buy and Sell signals buySignal = (close > highestHigh) and (position != 1) sellSignal = (close < lowestLow) and (position != -1)
// Update the position variable if (buySignal) position := 1 if (sellSignal) position := -1
// Plot Buy and Sell signals on the chart plotshape(series=buySignal, location=location.belowbar, color=color.green, style=shape.labelup, text="BUY") plotshape(series=sellSignal, location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")
// Debugging plots to check the highest high and lowest low plot(highestHigh, color=color.blue, title="Highest High") plot(lowestLow, color=color.orange, title="Lowest Low")
In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publications is governed by House rules. يمكنك جعله مفضلاً لاستخدامه على الرسم البياني.
هل تريد استخدام هذا النص البرمجي على الرسم البياني؟
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.