//@version=5 strategy("Fibonacci Strategy with Adjustable Stops and Take Profits",…
- User
//@version=5 strategy("Fibonacci Strategy with Adjustable Stops and Take Profits", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=1)
// Input for the lookback period herculesPeriod = input(14, title="Hercules Period")
// Inputs for the Fibonacci retracement levels pythagorasLevel = input(0.382, title="Pythagoras Level") euclidLevel = input(0.618, title="Euclid Level") archimedesLevel = input(0.5, title="Archimedes Level")
// Input for the second Fibonacci level multiplier secondFiboMultiplier = input(1.5, title="Second Fibonacci Multiplier")
// Inputs for the LSMA indicator pythagoreanTheoryLength = input(32, title="Pythagorean Theory Length") lsmaOffset = input(0, title="LSMA Offset")
// Inputs for adjustable take profit and stop loss levels takeProfit1Multiplier = input(1.0, title="Take Profit 1 Multiplier") takeProfit2Multiplier = input(1.0, title="Take Profit 2 Multiplier") stopLoss1Multiplier = input(1.0, title="Stop Loss 1 Multiplier") stopLoss2Multiplier = input(1.0, title="Stop Loss 2 Multiplier")
// Calculate the highest and lowest price during the lookback period highestHigh = ta.highest(high, herculesPeriod) lowestLow = ta.lowest(low, herculesPeriod)
// Calculate the Fibonacci retracement levels takeProfitLevel1 = lowestLow + (highestHigh - lowestLow) * pythagorasLevel * takeProfit1Multiplier stopLossLevel1 = highestHigh * stopLoss1Multiplier // Changed to highestHigh entryLevel1 = lowestLow + (highestHigh - lowestLow) * archimedesLevel
// Calculate the second Fibonacci retracement levels using the adjustable multiplier takeProfitLevel2 = lowestLow + (highestHigh - lowestLow) * pythagorasLevel * secondFiboMultiplier * takeProfit2Multiplier stopLossLevel2 = lowestLow + (highestHigh - lowestLow) * euclidLevel * secondFiboMultiplier * stopLoss2Multiplier entryLevel2 = lowestLow + (highestHigh - lowestLow) * archimedesLevel * secondFiboMultiplier
// Calculate the LSMA indicator lsma = ta.linreg(close, pythagoreanTheoryLength, lsmaOffset) lsma2 = ta.linreg(lsma, pythagoreanTheoryLength, lsmaOffset) eq = lsma - lsma2 zlsma = lsma + eq
var float breakEvenPrice = na var float fiboLevelStopPrice = na
// Trading logic if (ta.crossover(close, entryLevel1) and close > zlsma) strategy.entry("Buy", strategy.long, comment="Entry") breakEvenPrice := entryLevel1
if (ta.crossover(close, takeProfitLevel1)) strategy.close("Buy", qty_percent = 50, comment="Take Profit 1") fiboLevelStopPrice := takeProfitLevel1
if (not na(breakEvenPrice)) if (close > breakEvenPrice) stopLossLevel1 := breakEvenPrice
if (ta.crossover(close, takeProfitLevel2)) strategy.close("Buy", qty_percent = 50, comment="Take Profit 2") stopLossLevel1 := fiboLevelStopPrice
if (ta.crossunder(close, stopLossLevel1)) strategy.close("Buy", qty_percent = 50, comment="Stop Loss 1")
if (ta.crossunder(close, stopLossLevel2)) strategy.close("Buy", comment="Full Stop Loss")
- Assistant