I am creating a strategy where I enter a trade based on following conditions.
1. Two moving averages cross each other
2. Once a cross over happens, I want the ES to move at least 5 points in the favor of crossover, i.e. if it is a long side signal, I want ES to go up by 5 points and then enter the trade
3. If the above conditions are met and a trade is placed (and it could result in profit or loss), I want the system to wait until the next crossover before placing the next trade.
So far I was able to come up with the following code, but it is not working as I expect it to.
Can you help me to figure out what is wrong?
#region Variables
// Wizard generated variables
private int vma1 = xxx; // Default setting for Vma1
private int vma2 = xxx; // Default setting for Vma2
private int vma3 = xxx; // Default setting for Vma3
private int vma1vol = xxx; // Default setting for Vma1volatility
private int vma2vol = xxx; // Default setting for Vma2volatility
private int vma3vol = xxx; // Default setting for Vma3volaltility
private int stoplossticks = 24; // Default setting for Stoplossticks
private int profittargetticks = 100; // Default setting for Profittargetticks
private double LongValue = 0;
private double ShortValue = 0;
private double LongHighestGain = 0;
private double ShortHighestGain = 0;
protected override void OnBarUpdate()
{
if (CurrentBar < 500)
return;
//VALUE CALCULATIONS
if(CrossAbove((T3(28,1,0.7)),(VMA(vma1,vma1vol)),1 ))
{
LongValue =Close[0];
}
double CurrentLongTradeHighestGain = High[0] - LongValue;
LongHighestGain = Math.Max(LongHighestGain, CurrentLongTradeHighestGain);
//LONG CRITERIA
if ((T3(28, 1, 0.7)[0] > VsVMA2(vma1,vma1vol).VMA[0])
&& LongHighestGain >=5)
{
EnterLong(1,"Long");
}
if(CrossBelow((T3(28,1,0.7)),(VMA(vma2,vma2vol)),1 ))
{
ExitLong(1,"Long Exit","Long");
}
Comment