I have made a strategy that works well except the important bit which is buying and selling.
This is the relevant snippets of the code
// Variables
var float varEma20 = 0.0 //Signal Candle's 20 EMA which is gonna be used as the exit loss
var float varBuyPrice = 0.0 //Signal Candle's high + 0.01% just above candle high
var float varTakeProfit = 0.0 //Risk/Reward ratio: 2
// Buy/Sell
if (buyCondition1 and buyCondition2 and buyCondition3... == true)
strategy.order("buy", strategy.long, limit= varBuyPrice)
strategy.cancel("buy", when= close < varEma20) //cancel the buy order when a candle closes under the Signal Candle's 20 EMA
strategy.exit("buy", limit= varTakeProfit, comment="profit") //two times the risk
strategy.exit("buy", loss= varEma20, comment="loss") //loss when the price hits the Signal Candle's 20 EMA
// Drawings
plotshape(SignalCandleConfirmed ? varTakeProfit : na, title='take profit', style=shape.labeldown, location=location.absolute, color=color.new(color.green, 0), textcolor=color.new(color.white, 0), size=size.tiny)
plotshape(SignalCandleConfirmed ? varBuyPrice : na, title='buy price' , style=shape.labeldown, location=location.absolute, color=color.new(color.gray, 0), textcolor=color.new(color.white, 0), size=size.tiny)
plotshape(SignalCandleConfirmed ? varEma20 : na, title='take profit', style=shape.labeldown, location=location.absolute, color=color.new(color.red, 0), textcolor=color.new(color.white, 0), size=size.tiny)
varTakeProfit
is plotted as green dotsvarBuyPrice
⠀⠀ is plotted as grey dotsvarEma20
⠀⠀⠀⠀is plotted as red dots
The dots are plotted on the candle as long as the buy order is active:
As you can see in the picture, each variable is plotted correctly, but the buy/exit orders are not fulfilled correctly.
It seems to buys at the candle right after the Signal Candle.