stop-at
Dynamic analytical stop / target from an expression.
stop at expr target at expr
stop 10 points and target 20 percent flatten a simulated trade on a later bar. stop at and target at close the simulated trade too. Their expression is evaluated at each closed bar while in a trade, and that level is tested from the next bar. stop at joins the fixed stop, trail, and breakeven, and the tighter price wins. target at closes the whole position. None of them send a broker order. exit 50 percent reduces remaining simulated size. breakeven after 10 points, or breakeven after 1 percent, moves the protective stop to the current average entry once price has moved that far in favor. The entry bar can arm it and cannot close the trade. A later bar applies the trigger before the stop test, so one candle can both arm breakeven and hit it. The price stays armed through a partial exit and clears when the position goes flat. A fixed stop and a trail are combined with it by keeping the tighter price. ATR is not accepted on this line.
Return value
—
Example
when flat and close > ema(close, 20) buy stop at entry price - atr(14) * 2 target at entry price + atr(14) * 3 when long and bars since entry > 20 exit 50 percent