Hoping someone can help me debugging this bit of code. It's a pretty
easy FOREX test system that I want to code, on my way to building a more
complex system. In this example, I define two simple moving averages and
I want to:
Go Long when MA1 rises above MA2
Sell when the price is at least 10 pips higher than the buy entry price,
and MA1 falls below MA2
Go Short when MA1 falls below MA2
Cover when the price is at least 10 pips lower than the short entry
price, and MA1 rises above MA2
I'm getting errors inside the longer If statements. And I have a feeling
there is also an easier way to do all this:
myMA1 = MA(C,4);
myMA2 = MA(C,10);
Buy = myMA1 > MyMA2;
Short = myMA1 < MyMA2;
PriceAtBuy = 0;
PriceAtShort = 0;
for( i = 0; i < BarCount; i++ )
{
if( PriceAtBuy == 0 AND Buy[ i ] )
PriceAtBuy = Buy[ i ];
if( PriceAtShort == 0 AND Short[ i ] )
PriceAtShort = ShortPrice[ i ];
if(
(myMA1 < MyMA2) AND (PriceAtBuy > 0) AND (SellPrice[ i ] >
(PriceAtBuy + 0.0010 ))
)
{
Sell[ i ] = 1;
PriceAtBuy = 0;
}
else
Sell[ i ] = 0;
if(
(myMA1 > MyMA2) AND (PriceAtShort > 0) AND (CoverPrice[ i ] <
(PriceAtShort - 0.0010 ))
)
{
Cover[ i ] = 1;
PriceAtShort = 0;
}
else
Cover[ i ] = 0;
}
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);
Short = ExRem(Short, Cover);
Cover = ExRem(Cover, Short);