Seems that I have fixed my overfill problem. My situation is this. My system is a stop and reverse system which by itself causes no overfill issue because the code that does the reversal is merely an entry in the opposite direction. However, I also have code that allows for an alternate exit which sometimes causes an overfill. Read the above discussion to understand why the overfill occurs. I inserted a boolean in the stop and reverse code that says the exit has occured. Then in the alternate exit code I check the boolean to see if it's true and if so, that alternate exit isn't triggered. then I test for a flat condition to set the boolean to false. So, far that is working as I hoped.
if (long condition is met)
{
if (Position.MarketPosition == MarketPosition.Short)
{
exitlong = false;
exitshort = true;
}
EnterLong();
}
else if (short condition is met)
{
if (Position.MarketPosition == MarketPosition.Long)
{
exitlong = true;
exitshort = false;
}
EnterShort()
}
else if (!exitlong && Position.MarketPosition == MarketPosition.Long && long exit condition is met)
ExitLong();
else if (!exitshort && Position.MarketPosition == MarketPosition.Short && short exit condition is met)
ExitShort();
I think I got all that in there correctly. Hopefully, it is good enough for you to get the idea. Just been testing it for a short while so not sure if I've accounted for all the situations where the overfill can happen. We will see.