Reputation: 1514
I want my strategy to close whenever 4H price reaches 12 EMA but somehow it closes way above and I don't think it's possible for EMA to reach the price at which trade is getting closed.
Relevant code is quite simple:
fastMA = ta.ema(close, 12)
if strategy.position_size != 0
strategy.exit("profit", from_entry="EL", limit = fastMA, stop = high)
And this is my result on 4H chart:
Green line is the 12 EMA configured as follows:
Do you have any hints what might be wrong or where my assumptions are incorrect?
Upvotes: 0
Views: 660
Reputation: 21292
Your stop loss is getting triggered.
You set it stop=high
which means it will set your stop loss at previous bar's `high' price.
You can use the comment_profit
and comment_loss
arguments of the strategy.exit
to see which exit type was executed.
Upvotes: 1