what's the best practice for stop-loss execution that reflects the correct order in which the data formed the Close[0] bar? the problem I am seeing in one of my system is that, many time, especially when I run an optimiser in strategy analyser, the system is giving me entry and exit on the same bar (say 5 min bar).
My setting is:
Calculate= Calculate.OnBarClose;
else if (State == State.Configure)
{
AddDataSeries(Data.BarsPeriodType.Day, 1);
AddDataSeries(Data.BarsPeriodType.Week, 1);
SetProfitTarget("Target1", CalculationMode.Ticks, Target1*10);
SetProfitTarget("Target2", CalculationMode.Ticks, Target2*10);
SetProfitTarget("Target3", CalculationMode.Ticks, Target3*10);
SetProfitTarget("Target1S", CalculationMode.Ticks, Target1*10);
SetProfitTarget("Target2S", CalculationMode.Ticks, Target2*10);
SetProfitTarget("Target3S", CalculationMode.Ticks, Target3*10);
SetStopLoss(CalculationMode.Ticks, ST*10);
}
5 min bar open = 1.67
5 min bar high = 2
5 min bar low = 1
5 min bar close = 1.67
and my entry was 1.55 and my stop-loss was 1, but my entry happened AFTER the low had occurred. So in this example, based on the configurations I mentioned above, is my stop-loss in n8 being hit?
If it is being hit and there is not other solution besides following your recommended intrabar sample file, tick replay, or market replay; would the below solution suffice if I want my stops to be executed in the correct order? Theoretically even the below is not sufficient because I'm waiting an entire bar to be completed before my stop-loss order is going to be submitted.
if( condition) EnterShort(...); if(Position.MarketPosition == MarketPosition.Short && BarsSinceEntry() >1) ExitShortStop(...);
Another solution that might work:
private void StopManager()
{
if (Position.MarketPosition == MarketPosition.Flat)
{
SetStopLoss(CalculationMode.Ticks, ST*10);
}
else if (Position.MarketPosition == MarketPosition.Long)
{
if (Position.MarketPosition == MarketPosition.Long
&& Close[0] < Position.AveragePrice)
{
SetStopLoss(CalculationMode.Ticks, ST*10);
}
else if (Position.MarketPosition == MarketPosition.Long
&& Close[0] > Position.AveragePrice + Target1 * 0.0001)
{
SetStopLoss(CalculationMode.Price, Position.AveragePrice);
}
else if (Position.MarketPosition == MarketPosition.Long
&& Close[0] > Position.AveragePrice + Target2 * 0.0001)
{
SetStopLoss(CalculationMode.Price, Position.AveragePrice + Target1 * 0.0001);
}
}

Comment