I have to start by saying that I have no C# skills but have a decent ability to peice code together by looking at samples and getting a feel for how certain codes work. So with that being said, I have designed a strategy that works well for me but I would like to back test it and cannot effectively do it because I have a built-in strategy halt that kicks in when I have hit a certain profit or loss for the day.
Here is a portion of my current code:
// Checks to see if the day of the week is Monday or Friday. Only allows trading if the day of the week is not Saturday or Sunday.
if (Time[0].DayOfWeek != DayOfWeek.Saturday && Time[0].DayOfWeek != DayOfWeek.Sunday)
{
// After strategy has a PnL greater than ($profit) or less than -($loss) we will stop our strategy
if (Performance.AllTrades.TradesPerformance.Currency. CumProfit > profit
|| Performance.AllTrades.TradesPerformance.Currency.C umProfit < -loss)
{return;}
/* Checks to see if the time is during normal Market Trading hours. Time used is local time*/
if (ToTime(Time[0]) >= st && ToTime(Time[0]) < et)
{
}
Ok so if I want to backtest over several days it will not work because once it hits the PnL strategy halt, it obviously stops. I want it to backtest using the PnL, but have it stop just for the day it is testing and then move on to the next day until it hits the Profit or Loss, then on and on. So how do I code this to reset the PnL or CumProfit upon Midnight of each backtesting day or right before the beginning of a new session?
Thanks,
insomniac
p.s. The strategy is also set to start at 7:30am(mst) and end at 2:10pm(mst) or once PnL is hit, whichever comes first.
Comment