简体   繁体   中英

Having proble with strategy.exit

I'm making an indicator. The problem is when i add it to the chart the exit does not work properly. when my indicator buys it immediately sells one candle after i bought in.

I'm making an indicator where i want to sell at a loss or a profit. I'm using 2 ternary oparators. One that i call longStop and the other one is called longProfit.I already tried the stop/limit/profit/loss function but not a single one seems to work so far.

//@version=4
strategy("Daily ATR Stop", overlay=true)
//========================================================long entery.
high1 = high[100]
high2 = highest(high, 99)
long = float(na)
long := high2 < high1 ? high1 : long[1]
long_cond = crossover(close, long)

if long_cond
    strategy.entry("My Long Entry Id", strategy.long)

//long profit//
low1 = low[30]
low2 = lowest(low,29)
longProfit = float(na)
longProfit := low1 < low2 ? low1 : longProfit[1]
atrLkb = input(7, minval=1, title='ATR Stop Period')
atrRes = input("D", type=input.resolution, title='ATR Resolution')
atrMult = input(1, step=0.25, title='ATR Stop Multiplier')
atr = security(syminfo.tickerid, atrRes, atr(atrLkb))
longStop = float(na)
longStop := long_cond and strategy.position_size <= 0 ? close - atr * 
atrMult : longStop[1]
// i have a problem whith the exit part  
strategy.exit("exit","My Long Entry Id", stop=longStop, 
profit=longProfit)

plot(longProfit)
plot(longStop)
plot(long)

在此处输入图片说明

Your profit target seems to be very low.

It's a good thing that you plot longProfit and longStop , but have you ever looked at what values they have? I recommend you giving different colors to diffferent plot, so you can see which is which.

Here is a screenshot of your strategy where you have "problem". Green line is your profit target, and red line is your stop target.

在此处输入图片说明

As you can see, price is above your profit target and you are actually taking profit.

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