I would like to have the following strategy backtested: when the fast Moving Average crosses the slow MA above AND the fast MA is 1% higher than the slow MA gives me a buy signal that I hold for 10 days and the same for the short signal: when the Fast MA crosses the slow MA below then this is a enter short signal WHEN the fast MA is 1 Percent below the slow MA.
Now I created the code below but I would like to enter only once(!) a long or short position after the signal was created. Right now with the code below I enter all the time short and long positions as long the condition is true.
protected override void OnBarUpdate()
{
// Condition set 1
if (((SMA(Fast)[0])*1.01) > SMA(Slow)[0])
EnterLong();
// Condition set 2
if (BarsSinceEntry() == 9)
{
ExitLong("", "");
}
// Condition set 3
if (((SMA(Fast)[0])*1.01) < SMA(Slow)[0])
EnterShort();
// Condition set 4
if (BarsSinceEntry() == 9)
{
ExitShort("", "");
}
}
I would be grateful for any help or comments!
cheers, Trados

Comment