please i am in the early stages of putting together a simple crossover strategy where a momentum indicator has influence on.
The challenge is that when the market is in a deadlock where momentum keeps oscillating within a single bar, my strategy keeps opening and closing trades within the same bar. sometimes opening trades in the opposite direction and closing depending on how the momentum indicator moves.
this problem is somewhat solved when i set my strategy to 'On Bar Close' but this is not an option for me.
please can you help in executing one trade per bar and ignore any other conditions that may be satisfied to open or close a trade within the same bar?
i have attached a photo of what i am trying to explain
my code so far is as below, but doesn't seem to work;
// Set 1
if ((EMA1[0] > EMA2[0])
&& (MQMomentum1.Fast[0] > MQMomentum1.Slow[0]))
{
BarBrush = Brushes.DarkBlue;
EnterLong(Convert.ToInt32(DefaultQuantity), @"");
}
if (IsFirstTickOfBar);
{
doOnce = true;
}
// Set 2
if ((EMA1[0] < EMA2[0])
&& (MQMomentum1.Fast[0] < MQMomentum1.Slow[0]))
{
BarBrush = Brushes.Azure;
EnterShort(Convert.ToInt32(DefaultQuantity), @"");
if (IsFirstTickOfBar);
doOnce = true;
}
// Set 3
if ((MQMomentum1.Fast[0] < MQMomentum1.Slow[0])
&& (EMA1[0] > EMA2[0]))
{
ExitLong(Convert.ToInt32(DefaultQuantity), "", "");
}
// Set 4
if ((MQMomentum1.Fast[0] > MQMomentum1.Slow[0])
&& (EMA1[0] < EMA2[0]))
{
ExitShort(Convert.ToInt32(DefaultQuantity), "", "");
}
}
Comment