Am using a for loop to Buy and Sell from a MA cross (right now).  Have added a 
"StaticPositionHeld" flag.  I do not want to use EXREM.  If the 
"StaticPositionHeld" flag == 0, then only a Buy can occur.  If the 
"StaticPositionHeld" flag == 1, then only a Sell can occur.  Problem is on 
charts with just 2 months of minute data; the Buy Array value persists several 
bars and is value ~4.09.  It should be 1 bar in duration and the value 1.  
After about 1000 bars things start to behave, and the rest of the chart is 
visually okay.  On much larger charts of minute data this problem is not 
apparent.

To add to the confusion if additional (not relevant) lines are added.  The 
problem goes away.  Below is the code that corrupts the Buy Array.  If the 
comment // are removed, then the code works.  I have a *.jpg of the corrupted 
plots.  I'd be happy to emails them out.  Can anyone explain this to me?  It 
would be very much appreciated!

-Ron 

SetTradeDelays(1, 1, 1, 1);
SetBarsRequired(sbrAll, sbrAll);
SetPositionSize(100, 4);

BuyCond = Cross(MA(Close, 15), MA(Close, 20));
SellCond = Cross(MA(Close, 20), MA(Close, 15));

for(i = 0; i < BarCount; i++) {
        if ( i == 0) {
                StaticVarRemove("Static*");
                StaticVarSet("StaticPositionHeld", 0); 
        }
        if(StaticVarGet("StaticPositionHeld") == 0) { 
//              PositionHeld[i] = 0;
                Buy[i] = BuyCond[i];
                if (Buy[i] == True) { 
                        StaticVarSet("StaticPositionHeld", 1);
//                      PositionHeld[i] = 1;
                }
        }
        else {
//              PositionHeld[i] = 1;
                Sell[i] = SellCond[i];
                if(Sell[i] == True) {
                        StaticVarSet("StaticPositionHeld", 0);
//                      PositionHeld[i] = 0;
                }
        }
}

"BarIndex = " + BarIndex();
Plot(Buy, "Buy Array", colorGreen, styleLine);
Plot(Sell, "Sell Array", colorRed, styleLine);
              

Reply via email to