milad

milad

//@version=5
strategy("Multi-Indicator Bot with Trendline", overlay=true)

// Input parameters
rsiLength = input.int(14, title="RSI Length")
macdFast = input.int(12, title="MACD Fast Length")
macdSlow = input.int(26, title="MACD Slow Length")
macdSignal = input.int(9, title="MACD Signal Length")
stopLossPerc = input.float(2.0, title="Stop Loss (%)", minval=0.1)
takeProfitPerc = input.float(4.0, title="Take Profit (%)", minval=0.1)

// Trendline settings
trendLookback = input.int(20, title="Trendline Lookback Period")

// Valuum Indicator (e.g., volume check)
volumeCondition = volume > ta.sma(volume, 20)

// Ichimoku Indicator
= ta.ichimoku()
priceAboveCloud = close > spanA and close > spanB
conversionBaseCross = ta.crossover(conversion, base)

// RSI Indicator
rsi = ta.rsi(close, rsiLength)
rsiOversold = rsi < 30
rsiOverbought = rsi > 70

// MACD Indicator
= ta.macd(close, macdFast, macdSlow, macdSignal)
macdCrossUp = ta.crossover(macdLine, signalLine)
macdCrossDown = ta.crossunder(macdLine, signalLine)

// Calculate trendlines
highTrend = ta.highest(high, trendLookback)
lowTrend = ta.lowest(low, trendLookback)

// Plot trendlines
line.new(x1=bar_index - trendLookback, y1=highTrend, x2=bar_index, y2=highTrend, color=color.red, width=2, extend=extend.right, title="High Trendline")
line.new(x1=bar_index - trendLookback, y1=lowTrend, x2=bar_index, y2=lowTrend, color=color.green, width=2, extend=extend.right, title="Low Trendline")

// Entry and exit conditions
longCondition = priceAboveCloud and conversionBaseCross and rsiOversold and macdCrossUp and volumeCondition and close > lowTrend
shortCondition = not priceAboveCloud and rsiOverbought and macdCrossDown and not volumeCondition and close < highTrend

if (longCondition)
strategy.entry("Long", strategy.long)
// Draw an upward arrow for entry
plotshape(series=longCondition, location=location.belowbar, color=color.green, style=shape.labelup, title="Buy Signal", text="BUY")

if (shortCondition)
strategy.entry("Short", strategy.short)
// Draw a downward arrow for entry
plotshape(series=shortCondition, location=location.abovebar, color=color.red, style=shape.labeldown, title="Sell Signal", text="SELL")

// Stop Loss and Take Profit
strategy.exit("Exit Long", from_entry="Long", stop=close * (1 - stopLossPerc / 100), limit=close * (1 + takeProfitPerc / 100))
strategy.exit("Exit Short", from_entry="Short", stop=close * (1 + stopLossPerc / 100), limit=close * (1 - takeProfitPerc / 100))

// Plot exit signals as arrows
exitLongCondition = strategy.position_size > 0 and close = close * (1 + stopLossPerc / 100)

plotshape(series=exitLongCondition, location=location.abovebar, color=color.orange, style=shape.labeldown, title="Exit Long", text="EXIT")
plotshape(series=exitShortCondition, location=location.belowbar, color=color.yellow, style=shape.labelup, title="Exit Short", text="EXIT")

Read More

Share:

Latest News