Im an trying to set the STOP value during a trade to be a percentage of the highest high of the price since entering the trade. That way if the price reaches a maximum during the trade, the trade would be closed if the price falls below the given percentage of that maximum (e.g. 95%).
Im trying to program this in a trade managment function (TMF) slightly modified from the example in the Zorro help. The trade should be closed if the price falls below 95% of the maximum price in the trade
int AdjustMax()
{
if(TradeIsOpen and TradeResult > 0)
TradeStopLimit = 0.95*HH(TradeTime);
return 0;
}
When I am testing this, Zorro always crashes with the following error:
BADFREE2: SYS
To me this looks like a memory overflow or someting related. For this reason I checked which values are accepted as a argument of HH. This seems to work fine for periods until 82 bars, with bigger numbers Zorro crashes.
What is happening? How could I change the code? Is there a dedicated function to achieve what I want, which I missed?