Set "SellPrice" to be that of stopModePoint amount when stop is triggered

Hi,

Whenever stop is triggered the stop out price is the "close" because I have SellPrice = Close.

But when a stop is triggered via ApplyStop:
ApplyStop( stopTypeLoss, stopModePoint, stopAmountLong, True );
I would like the SellPrice to be stopAmountLong instead of the close.

Can this be done?

Thanks!

First you should carefully read applystop scenarios of manual.
https://www.amibroker.com/guide/afl/applystop.html

Secondly (if you only want to exit at your coded stop) you should disable UI stops that may be active to exit at close
Read here

Third if there are gaps then exit will be at tradeable prices only which may be at close price level.

image
I'm trying to buy and sell at the locations indicated. The long engulfing red candle should have both a buy and sell triggered on the same candle. But it seems the sell is happening on the second day. I did read how to apply stop but i wasn't able to find any solutions to my problem.

My script is here for testing:

SetOption("InitialEquity",100000);
SetOption("MaxOpenPositions",1000);
SetOption("AccountMargin",100);// 100 = No Leverage.
SetOption("CommissionAmount",0);
SetOption("AllowSameBarExit", True );
SetTradeDelays(0,0,0,0);

twoDayHigh=HHV(high,2);  
twoDayLow=LLV(low,2);  
inside2Days = (Ref(twoDayHigh,-2)>=twoDayHigh) and (Ref(twoDayLow,-2)<=twoDayLow);  
ema8 = EMA(Close,8);  

insideBarConsolidationPlot = inside2Days  
&& Ref(High,1)>High;  
  
Plot( insideBarConsolidationPlot, "plot", ParamColor("Color", colorDefault ), styleNoTitle );   
  
Buy = Ref(insideBarConsolidationPlot,-1) && Name() == "ILMN";  
  
Cover = False;  

Sell = Cross(ema8, Close ); // close crosses blow ema8
  
SellPrice =  Close;
ShortPrice = CoverPrice = Close;  

BuyPrice = Ref(High,-1);
  
TickSize = 0.01;  
stopLevelLong = Ref(Low,-1); // use low of prior bar
stopAmountLong = BuyPrice - stopLevelLong;  
stopAmountLong = Max( TickSize, BuyPrice - stopLevelLong );  
ApplyStop( stopTypeLoss, stopModePoint, stopAmountLong, ExitAtStop = 1 );  

// Percent risk position sizing
percentRiskPerTrade = 1.5; // how much (in percent of equity) we risk in single position
riskPerShare = stopAmountLong;
numShares = percentRiskPerTrade/100*Equity()/riskPerShare;
SetPositionSize( numShares, spsShares );