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.
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 );