Most of the time it works without any issues but occasionally it sends an extra order to close the position and I end up with one contract in the opposite direction. To clarify, if I am short 2 contracts, and there are two successive closes on the secondary data series above my stop level, it will close the position but 3 contracts will execute putting me in a 1 contract long position. This new position is not managed And therefore has no stop associated with it.
It is not entering a new position based on any logic that I have created because I have a user input boolean for both long or short trades. In the example above the strategy is set to only trade short because the box for long is not checked.
Here is a section of the short side logic. The “Short” is the user input bool that must be checked for a short trade to be taken. The “TT” is a user variable bool that stands for trade taken which changes to true once a stop is triggered or a second target is hit. This is to prevent the strategy from executing another entry. It is designed to only take one entry and then stop once the trade is completed.
if ((Position.MarketPosition == MarketPosition.Flat)
&& (CrossAbove(Close, Entry1 - FrontRun, 1))
&& (Short == true)
&& (TT == false))
{
EnterShort(Convert.ToInt32(DefaultQuantity), @"Entry1");
}
// Set 8
if ((Position.MarketPosition == MarketPosition.Short)
&& (Entry2Val != 0)
&& (CrossAbove(Close, Entry2Val - FrontRun, 1)))
{
EnterShort(Convert.ToInt32(DefaultQuantity), @"Entry2");
}
// Set 9
if ((Position.MarketPosition == MarketPosition.Short)
&& (CrossAbove(Close, Stop, 1))
&& (Stop != 0))
{
ExitShort(Convert.ToInt32(DefaultQuantity), "", "");
TT = true;
//CloseStrategy("My Strategy");
}
// Set 10
if ((Position.MarketPosition == MarketPosition.Short)
&& (Closes[1][1] > SoftStop)
&& (Closes[1][2] > SoftStop))
{
ExitShort(Convert.ToInt32(DefaultQuantity), "", "");
TT = true;
}
Comment