The intention of my code below should give values to ExitShortLimit() for each iteration of EntriePerTrade and them Short TP 1, Short TP 2, etc.
The expected result is:
Short TP 1 = 40 ticks from price
Short TP 2 = 60 ticks from price
Short TP 3 = 80 ticks from price
Short TP 4 = 100 ticks from price
But for some reason each iteration is accumulating the previous value giving this result:
Short TP 1 = 40 ticks from price
Short TP 2 = 100 ticks from price
Short TP 3 = 180 ticks from price
Short TP 4 = 280 ticks from price
Is there a problem with the logic? I am using the print functions to debug, all the calculations appear to be correct from the print functions.
The expected result is:
Short TP 1 = 40 ticks from price
Short TP 2 = 60 ticks from price
Short TP 3 = 80 ticks from price
Short TP 4 = 100 ticks from price
But for some reason each iteration is accumulating the previous value giving this result:
Short TP 1 = 40 ticks from price
Short TP 2 = 100 ticks from price
Short TP 3 = 180 ticks from price
Short TP 4 = 280 ticks from price
Is there a problem with the logic? I am using the print functions to debug, all the calculations appear to be correct from the print functions.
C#:
int EntriesPerTrade = 4
int[] TakeProfitLevels = new int[EntriesPerTrade];
TakeProfitLevels[0] = 40;
TakeProfitLevels[1] = 60;
TakeProfitLevels[2] = 80;
TakeProfitLevels[3] = 100;
if (execution.Order.OrderState == OrderState.Filled)
{
double takeProfitShortLevels;
double takeProfitLongLevels;
for (int i = 0; i < EntriesPerTrade; i++)
{
PrintTo = PrintTo.OutputTab2;
takeProfitShortLevels = execution.Order.AverageFillPrice - TakeProfitLevels[i] * TickSize;
Print(string.Format("{0} AverageFillPrice: {1} - TakeProfitLevels[i]: {2} * TickSize: {3} takeProfitShortLevels: {4}" + " " + i, Time[0], execution.Order.AverageFillPrice, TakeProfitLevels[i], TickSize, takeProfitShortLevels));
takeProfitLongLevels = execution.Order.AverageFillPrice + TakeProfitLevels[i] * TickSize;
Print(string.Format("{0} AverageFillPrice: {1} + TakeProfitLevels[i]: {2} * TickSize: {3} takeProfitLongLevels: {4}" + " " + i, Time[0], execution.Order.AverageFillPrice, TakeProfitLevels[i], TickSize, takeProfitLongLevels));
// Handle short position TP and SL
ExitShortLimit(0, true, execution.Order.Filled, takeProfitShortLevels, "Short TP " + i, "Short " + i);
Print(Time[0] + "ExitShortLimit at limit price: " + takeProfitShortLevels + " " + i);
ExitShortStopLimit(0, true, execution.Order.Filled, execution.Order.AverageFillPrice + InitialSLAmount, execution.Order.AverageFillPrice, "Initial Short SL " + i, "Short " + i);
// Handle long position TP and SL
ExitLongLimit(0, true, execution.Order.Filled, takeProfitLongLevels, "Long TP " + i, "Long " + i);
Print(Time[0] + "ExitLongLimit at limit price: " + takeProfitLongLevels + " " + i);
ExitLongStopLimit(0, true, execution.Order.Filled, execution.Order.AverageFillPrice - InitialSLAmount, execution.Order.AverageFillPrice, "Initial Long SL " + i, "Long " + i);
Print(Time[0] + " " + execution.Order.AverageFillPrice + " short levels: " + i + " " + takeProfitShortLevels);
Print(Time[0] + " " + execution.Order.AverageFillPrice + " short levels: " + i + " " + takeProfitLongLevels);
}
}