I tried to automate my strategy using webhook. For this, when entering an alarm, I need to determine whether it is buy or sell from the “side”: “{{strategy.order.comment}}” section. I used the Strategy.entry and strategy.exit commands for this, but my indicator was broken.
Here is the strategy code:
if(longsignal)
strategy.entry("BUY",strategy.long,comment="BUY")
if(shortsignal)
strategy.exit("exit","BUY",comment="SELL",limit=close)
Here is the all code:
//@version=5
//author “IG : @Yilmaztakil”
indicator(‘DignitySignals’, overlay = true)
//EMA
fast_ema = ta.ema(close, 9)
slow_ema = ta.ema(close, 18)
//MACD
fastInput = 12
slowInput = 26
[macdLine, signalLine, histLine] = ta.macd(close, fastInput, slowInput, 9)
//Supertrend
atrPeriod = 10
factor = 3
[supertrend, direction] = ta.supertrend(factor, atrPeriod)
//SMA
shortAverage = ta.sma(close, 50)
longAverage = ta.sma(close, 200)
//Line Plots
LineColorUp = direction < 0 ? color.rgb(0, 255, 8) : na
SuperTrendUpPlot = plot(supertrend, color = LineColorUp, linewidth = 2, editable = false ,title = "SuperTrendUpPlot")
LineColorDown = direction >= 0 ? color.rgb(255, 0, 0) : na
SuperTrendDownPlot = plot(supertrend, color = LineColorDown, linewidth = 2, editable = false ,title = "SuperTrendDownPlot")
candleColor = direction < 0 ? color.rgb(0, 255, 8) : color.rgb(255, 0, 0)
plotcandle(direction ? open : na, direction ? high : na, direction ? low : na, direction ? close : na, color=candleColor, editable = false, title = "CandleChartColor", wickcolor = color.white)
//plotcandle(open, high, low, close, color = candleColor, editable = false)
bodyMiddle = plot((open + close) / 2, display=display.none, editable = false)
fillColor = direction < 0 ? color.rgb(0, 255, 8) : color.rgb(255, 0, 0)
fill(bodyMiddle ,SuperTrendUpPlot, color.new(fillColor, 80), fillgaps = false, editable = false)
//Condition
longentry = fast_ema > slow_ema and macdLine > signalLine and close > supertrend
shortentry = fast_ema < slow_ema and macdLine < signalLine and close < supertrend
var pos = 0
if longentry and pos <= 0
pos := 1
if shortentry and pos >= 0
pos := -1
longsignal = pos == 1 and (pos != 1)[1]
shortsignal = pos == -1 and (pos != -1)[1]
if(longsignal)
strategy.entry("BUY",strategy.long,comment="BUY")
if(shortsignal)
strategy.exit("exit","BUY",comment="SELL",limit=close)
//StrategyTest
//signal = longsignal ? 1 : shortsignal ? -1 : na
//plot(signal, "Strategy Optimizer Signal")
//Setting Reminder
alertcondition (longsignal, title = "Buy Alert", message = "Buy")
alertcondition(shortsignal, title = "Sell Alert", message = "Sell")
//Visulize Signals
plotshape(longsignal, style = shape.triangleup, color = #00ff00, text = "BUY", textcolor = #FFFFFF, editable = false, location = location.belowbar, size = size.normal)
plotshape(shortsignal, style = shape.triangledown, color = #FF0000, text = "SELL", textcolor = #FFFFFF, editable = false, location = location.abovebar, size = size.normal)
plot(shortAverage, color=color.rgb(0, 123, 255))
plot(longAverage, color=color.rgb(200, 0, 255))
I tried to write the entry and exit sections into alarmcondition, but it didn’t work.