I corrected the prints, now it returns this:
It Shows:
Up/Down Trades Count: 1
Total Profits: 589.1
I have selected the Hours from 11:40 to 12:00.
At 11:36:00 the Count and Total Profits should be 0 and 0 (the strategy hasn't executed any trades yet and would start at 11:40).
I don't get why it does not reset these values.
Can you please take a look at the script and advise on the simplest solution to this?
These prints don't print:
Print(" ");
Print(Times[0][0] + " 0. lossesCount: " + lossesCount);
Print(Times[0][0] + " 0. winsCount: " + winsCount);
Print(Times[0][0] + " 0. tradesProfits: " + tradesProfits);
Print(Times[0][0] + " 0. bottomLineTrades: " + bottomLineTrades);
protected override void OnBarUpdate()
{
if (CurrentBar < BarsRequiredToTrade)
return;
bool dayTimeFilter = (
Time[0].DayOfWeek >= DayFrom
&& Time[0].DayOfWeek <= DayTo
);
bool hoursTimeFilter = (
// Format example
/// ( ToTime(Time[0]) >= 00000 && ToTime(Time[0]) < 240000 )
/// || ( ToTime(Time[0]) >= 140000 && ToTime(Time[0]) < 154500 )
(
ToTime(Time[0]) >= ToTime(HourFrom)
&& ToTime(Time[0]) < ToTime(HourTo)
)
);
lossesCount = SystemPerformance.AllTrades.LosingTrades.Count;
winsCount = SystemPerformance.AllTrades.WinningTrades.Count;
tradesProfits = SystemPerformance.AllTrades.TradesPerformance.NetProfit;
if(Bars.IsFirstBarOfSession)
{
//reset daily trades counter
DailyTrades = 0;
//currentTrades holds the value of AllTrades.Count at the time of session start
SessionStartTradeCount = SystemPerformance.AllTrades.TradesCount;
Print(" ");
Print(Times[0][0] + " Reset on start of new session. DailyTradesCounter: " + DailyTrades);
Print(Times[0][0] + " Reset on start of new session. SessionStartTradeCount: " + SessionStartTradeCount);
lossesCount = 0;
winsCount = 0;
tradesProfits = 0;
bottomLineTrades = 0;
Print(" ");
Print(Times[0][0] + " 0. lossesCount: " + lossesCount);
Print(Times[0][0] + " 0. winsCount: " + winsCount);
Print(Times[0][0] + " 0. tradesProfits: " + tradesProfits);
Print(Times[0][0] + " 0. bottomLineTrades: " + bottomLineTrades);
}
//calculate DailyTrades value
Print(" ");
Print(Times[0][0] + " SystemPerformance.AllTrades.TradesCount: " + SystemPerformance.AllTrades.TradesCount);
Print(Times[0][0] + " SessionStartTradeCount: " + SessionStartTradeCount);
DailyTrades = SystemPerformance.AllTrades.TradesCount - SessionStartTradeCount;
Print(Times[0][0] + " Current TradesCounter value: " + DailyTrades);
// Accesses the first/last losing trade in the strategy (oldest trade is at index 0)
// and prints out the profit as a percentage to the output window
if ( SystemPerformance.AllTrades.LosingTrades.Count > 0
|| SystemPerformance.AllTrades.WinningTrades.Count > 0
)
{
bottomLineTrades = (-1 * lossesCount) + winsCount;
Draw.TextFixed(this, "tradesstats",
"\n"+"Up/Down Trades Count: "+bottomLineTrades.ToString()+"\n"+
"Total Profits: "+tradesProfits.ToString(),
TextPosition.TopRight, Brushes.Magenta,
tradesstats, Brushes.Transparent,Brushes.Black,100);
Print(" ");
Print(Times[0][0] + " 1. lossesCount: " + lossesCount);
Print(Times[0][0] + " 1. winsCount: " + winsCount);
Print(Times[0][0] + " 1. tradesProfits: " + tradesProfits);
Print(Times[0][0] + " 1. bottomLineTrades: " + bottomLineTrades);
}
if (
dayTimeFilter
&& hoursTimeFilter
)
{
//logic to enter and exit trades, just so we can see our counter update
if (CrossAbove(smaFast, smaSlow, 1))
EnterLong();
else if (CrossBelow(smaFast, smaSlow, 1))
EnterShort();
}
}

Comment