简体   繁体   中英

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:

在此处输入图像描述

Green line is the 12 EMA configured as follows:

在此处输入图像描述

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM