Thanks, but the source code doesn't seem to do what I described. Ignoring updating stops and take profit in reverseLong, we are left with:
// if MaxTrades is not reached, open a new trade
if(NumOpenLong < MaxTrades)
return enterLong();
// otherwise, close any opposite trades
else if(!mode(HEDGING))
exitShort();
Perhaps I am off base, but wouldn't this have the action of closing all short positions only if the number of long positions open is equal to Max? I don't understand the "otherwise" - shouldn't it close all opposite in all situations? I was expecting something more like:
// close all opposite trades
if(NumOpenShort > 0)
exitShort();
// if MaxTrades is not reached, open a new trade
if(NumOpenLong < MaxTrades)
return enterLong();
Or am I in error?