Trying to add code to stop trading if up or down 500 for the day. Seems simple, but I seem to be incapable of making it work. Can you tell me what I am doing wrong?
Here are the code snippets:
if(Bars.FirstBarOfSession && FirstTickOfBar)
{
DailyProfit = 0;
}
This should reset the variable DailyProfit at the beginning of each day
When a trade is exited this code is executed:
{
DailyProfit = DailyProfit + Position.GetProfitLoss(Close[0], PerformanceUnit.Currency);
ExitShort("SysXS", "");
return;
}
This should increment/decrement the variable DailyProfit by the amount gained/lost on the Current Trade.
If the conditions are not met for an exit the following code should be executed:
if (Position.MarketPosition == MarketPosition.Long
&& DailyProfit + Position.GetProfitLoss(Close[0], PerformanceUnit.Currency)>500)
{
ExitLong("XLProfitMade", "");
return;
}
Code exists to check for similar conditions long or short, up 500 or down 500 and need not be shown here as it is virtually identical. It also contains a flag that tells the entry conditions not to take a new trade, and that flag is reset in the opening segment and not shown here.
So where is my error? The code will execute if an INDIVIDUAL TRADE reaches the 500 +/-, but I am wanting to quit for the day if the entire day's P/L is +/- 500.
Help please?
Thanks,
Jamie

Comment