stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

Need advice with "Price over SMA"
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=2536
Page 1 of 1
Author:  genaja [ Sun Jun 16, 2013 6:21 pm ]
Post subject:  Need advice with "Price over SMA"

Hi Folks,

I will code a CCI Tape as indicator. But I can“t figure out a simple code line. :(


Function:
If the CCI14 was over +150 and the price goes under the BollingerMidline go short

Tape will show a orange Bar if the price was over CCI14 +150
Tape shows a red Bar if the price goes under Bollinger Midline.

But my Code will not work good. Orange Bar is showing, the red one not.
What is my mistake? Any ideas?


Code:

Code: Select all

   for(int i=0; i<limit; i++)
   {
     
     double BollingerMiddle=iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,i+1);
     double last_close=iClose(Symbol(),NULL,1);
     
      // SHORT 
      // CCI > 150 = overbougt
      if(iCCI(NULL,0,CCI1,PRICE_TYPICAL,i)>=150) 
          
        {
        ExtBuffer1[i]=1;preShort=1; 
        ExtBuffer2[i]=0;     
        ExtBuffer3[i]=0;     
        ExtBuffer4[i]=0;
        }
       
       else // cci was > 150 && Price <SMA20 = short
         if(preShort==1 && (last_close <= BollingerMiddle) ) 
           
        {
        ExtBuffer2[i]=1;
        ExtBuffer1[i]=0;     
        ExtBuffer3[i]=0;     
        ExtBuffer4[i]=0;
        }


All times are UTC Page 1 of 1