Hi there,
I'm looking for some help with a problem in my code. I'm writing a system that switches sell instructions based on whether a ticker's index is falling above or below it's moving average.
I believe I'm coding it correctly as you would with if statements, but I'm finding that the backtest is very slow to run and Amibroker also runs out of memory when I backtest it on an entire stock market. (I'm using the 32 bit version).
Am I coding it correctly? If so, is there another way to code it so that it can run more efficiently and won't run out of memory?
Thanks in advance.
TwoFiftyHigh = Ref( HHV( C, 250), -1 );
TwoFiftyLow = Ref( LLV( C, 250), -1 );
IndexChart = "SPX";
ic = Foreign( IndexChart, "C" );
MAperiod = 200;
IndexMA = MA(ic, MAperiod);
IndexMAtrend = IIf(ic > IndexMA, True, False);
IndexMAdowntrend = IIf(ic < IndexMA, True, False);
signalHighestSince = 0.9*HighestSince(IndexMAdowntrend,H,1);
tenpcStopLoss = IIf(C<=signalHighestSince,True, False);
Buy = Close > TwoFiftyHigh & IndexMAtrend ;
Sell = 0;
for( i = 1; i < BarCount; i++ )
{
if ( IndexMAdowntrend[ i ] == True )
{
_TRACE ("downTrend");
Sell[ i ] = tenpcStopLoss[i];
SellPrice[ i ] = C[ i ];
}
if ( IndexMAdowntrend[ i ] == False ){
_TRACE ("upTrend");
Sell[ i ] = Close[i] < TwoFiftyLow[i];
SellPrice[ i ] = C[ i ];
}
}
SetOption("MaxOpenPositions", 20);
SetPositionSize(5, spsPercentOfEquity);