this is a somewhat simplified version of what I am trying to accomplish.
When having correctly identified a trend, I want to look for candles and buy at the next open.
That works for now.
I want to set SL and TP depending on the size of that candle.
When price drops below the low (for short high) of the candle, I want to exit the trade.
When price crosses above 1.25 x the size of the candle, I want to close the position.
Can anyone help?
Im quite new to this..
All the best,
Though it doesn't stop out correctly.
Therefore I'm still stuck with the question:
How can I use the previous candle size as basis for TP/SL calculation?
Would be greatful for your help!
All the best,
clockwork = barssince(condition for buy)
clockwork = strategy.openpositions==0 and strategy.openpositions==1 and bullishengulfing condition
this should store the bar for when the conditions were true
EngSize = clockwork.low - clockwork.high
stopLoss = cross(close, clockwork.low)
TakeProfit = cross(close, EngSize * 1.25)
That's basically the code I am looking for. Just cant get the syntax right... :/
EngSize = high - low
stoplong = low
profitlong = close + EngSize*1.25
strategy.close("Close Long", from_entry = "Long", when = close < stoplong, comment="SL")
strategy.close("Close Long", from_entry = "Long", when = close > profitlong, comment="TP")
So, even though it seems to be correct, it doesnt work. Very frustrating.
What I did:
clockwork = barssince(bullEngulfing)
Engsize = abs(open(clockwork) - close (clockwork)) / syminfo.mintick
execProfitTarget = cross(close, close + Engsize)
execStopLoss = cross(close, close - Engsize)