xwhyz
xwhyz

Reputation: 1514

Set strategy.exit Limit to close when price reaches EMA

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:

enter image description here

Green line is the 12 EMA configured as follows:

enter image description here

Do you have any hints what might be wrong or where my assumptions are incorrect?

Upvotes: 0

Views: 660

Answers (1)

vitruvius
vitruvius

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

Related Questions