I am locking for a code cosntruct, that helps me to control different exit times.
In my code I am having an general exit time in the near from the end of the trading day: 21:45 MEZ/MESZ (central european time/central european summer time).
Now I need different general exit times, that means for each instrument, that the position ends definitly on its. That means: if an instrument is reaching the NEXT exit time, then the strategy will stop its.
In my example I am using 4 different exit times (color: red): 08:00, 14:25, 15:25, 21,45.
1. First example is trading the DAX Future (FDAX) at EUREX. Entry zone is 9:00 until 11:30 = trade start zone. Its end is the NEXT exit time = 14:25. So in this example the trade can only have one latest exit.
2. Second example is Crude Oil (CL) at NYMEX. Entry zone is 00:00 until 17:30. So there are now 4 possible exit times. Which exit time is the correct one? Answer: it is depending from start time of the trade. Example start time at 5:17: Exit time is the next one = 8:00. Another example: start time is 8:33: Exit time is the next one = 14:25. And so on.
And at last: I would love, if I can implement a bool variable, that is deactivating an specific exit time - for example 14:25 from on to off. The result would be, that the trade in the last example will not stop at 14:25. Its new exit time is then 15:25.
Variables:
ContractsLong = 1;
ContracsShort = 1;
//Possible Entry Time Zones
MyStart1 = DateTime.Parse("00:01", System.Globalization.CultureInfo.InvariantCulture);
MyEnd1 = DateTime.Parse("23:15", System.Globalization.CultureInfo.InvariantCulture);
MyStart2 = DateTime.Parse("00:00", System.Globalization.CultureInfo.InvariantCulture);
MyEnd2 = DateTime.Parse("00:00", System.Globalization.CultureInfo.InvariantCulture);
MyStart3 = DateTime.Parse("00:00", System.Globalization.CultureInfo.InvariantCulture);
MyEnd3 = DateTime.Parse("00:00", System.Globalization.CultureInfo.InvariantCulture);
// Possible Exit Times
MyExitTime1 = DateTime.Parse("08:00", System.Globalization.CultureInfo.InvariantCulture);
MyExitTime2 = DateTime.Parse("14:25", System.Globalization.CultureInfo.InvariantCulture);
MyExitTime3 = DateTime.Parse("15:25", System.Globalization.CultureInfo.InvariantCulture);
// Definitly Exit Time from the day
MyLastestExitTime = DateTime.Parse("21:45", System.Globalization.CultureInfo.InvariantCulture);
//Bool-Variables for activating/deactivating the individual exit times
MyBoolExit1 = true;
MyBoolExit2 = true;
MyBoolExit3 = true;
MyBoolExit4 = true;
Here is the code from my 3 different entry time zones (manually fill out in Parameter-Menue, because its different for each instrument)
if (
((Times[0][0].TimeOfDay >= MyStart1.TimeOfDay)
&& (Times[0][0].TimeOfDay <= MyEnd1.TimeOfDay))
|| ((Times[0][0].TimeOfDay >= MyStart2.TimeOfDay)
&& (Times[0][0].TimeOfDay <= MyEnd2.TimeOfDay))
|| ((Times[0][0].TimeOfDay >= MyStart3.TimeOfDay)
&& (Times[0][0].TimeOfDay <= MyEnd3.TimeOfDay)))
Code of the lastest exit each trading day:
if (Times[0][0].TimeOfDay >= MyLastestExitTime.TimeOfDay)
{
if (Position.MarketPosition == MarketPosition.Long)
{
ExitLong(Convert.ToInt32(ContractsLong), @"ExitLong", @"EntryLong");
}
if (Position.MarketPosition == MarketPosition.Short)
{
ExitShort(Convert.ToInt32(ContracsShort), @"ExitShort", @"EntryShort");
}
}
Thank you for helping me!
Best regards,
Rainbowtrader

Comment