I have an issue with Entry and Exit in a Multi Time Frame Strategy when an Exit Condition and Entry Condition fires on the same bar. I don't believe the problem is due to the Multi Time Frame as I set the entries/exits on the condition of BarsInProgress =0. I'm attempting to manage the position/direction using local variables, but I'm sure there may be a cleaner way to do this. On the same OnBarUpdate event, can the strategy Exit one direction and Enter the other, as I've coded in the code below?
Logs from the Executions tab;
Time E/X Position Name
8:40:56 Entry 1L LONG_ENTRY
9:10:41 Exit - Sell
9:10:41 Entry 1S Close Position
9:10:42 Entry 2S SHORT_ENTRY
9:49:40 Exit 1S Buy to cover
if (BarsInProgress == 0)
{
//Exit Conditions
if (_position = true)
{
if (_longposition = true)
{
if (exit_condition)
{
ExitLong("LONG_ENTRY");
_longposition = false;
_position = false;
}
}
if (_shortposition = true)
{
if (exit_condition)
{
ExitShort("SHORT_ENTRY");
_shortposition = false;
_position = false;
}
}
}
//Entry Conditions
if (_position == true) return;
if (long_entry_condition)
{
EnterLong("LONG_ENTRY");
_longposition = true;
_position = true;
}
if (short_entry_condition)
{
EnterShort("SHORT_ENTRY");
_shortposition = true;
_position = true;
}
}
Comment