I am trying to make a custom stop loss that is different for different scenarios:
In my current example:
Scenario 1: a maximum stop loss of 300 ticks
Scenario 2: a trailing stop loss of 10 ticks
Since you can't do a TrailStop and an automatic StopLoss together... I am trying to pseudo hard-code it.
Here is my code:
if(currentprofit > 20)
{
if (currentprofit > maxprofit)
{
maxprofit = currentprofit;
}
if (currentprofit < (maxprofit - 10))
{
ExitShort(@"EntryShort");
maxprofit = 0;
}
}
if (currentprofit < -300)
{
ExitShort(@"EntryShort");
}
So basically:
If my currentprofit variable is larger than maxprofit, it will update maxprofit to the new profit value. If currentprofit dips below 10 ticks, it will exit the trade. If currentprofit never hits the +20 profit, it has a safety net at -300 ticks.
The issue I am having is that max profit is always updating to current profit (i think because max profit is resetting to zero at every run of the code). I have it initialized as a "private double maxprofit = 0;" in the beginning of the strategy (before onstatechange()). Can anyone tell me how to retain this value of maxprofit through the next run of the code?
Thank you!

Comment