I have developed a strategy, in the strategy the trade volume would updated based on the result of previous order (winning/losing). At the beginning, I would initialize everything because I don't want the strategy be affected by the performance of the last order in the previous day. So here is my code:
//This is to get the total # of trade in the previous day
if (Times[0][0].TimeOfDay < Times[0][1].TimeOfDay)
{
AccmTrades = SystemPerformance.AllTrades.Count;
}
// This is to control Trade Volumn
if (SystemPerformance.AllTrades.Count - AccmTrades >= 1)
{
if (SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1].ProfitCurrency < 0
&& TradeNum != SystemPerformance.AllTrades.Count - 1
&& TradeVol < 10)
{
TradeVol++;
TradeNum = SystemPerformance.AllTrades.Count - 1;
Print("New Trades: " + (SystemPerformance.AllTrades.Count - AccmTrades));
Print("Trade Volumn = " + TradeVol);
}
if (SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1].ProfitCurrency > 0
&& TradeNum != SystemPerformance.AllTrades.Count - 1)
{
TradeVol = 1;
TradeNum = SystemPerformance.AllTrades.Count - 1;
}
}
The default value of TradeVol (Trade Volume) is 1, and it is supposed to start from 1. TradeNum is the trade number that label the last order as the strategy is run on each tick and I only want it update the volume once. However, when I actually start running the strategy, the first order's trade volume is always 10, and according to the log, the trade volume update code has already been triggered 10 times even there is no order at all in the new day. So I wonder how to use the AllTrades array correctly.
Thank you very much for your help!

Comment