Navigation´╝ÜHome > Content >

LSMA200vote_Ron_v02b.mq4

Time: 2010-02-27 | Download file:LSMA200vote_Ron_v02b.mq4

//+-----------+
//| LSMA      |
//+-----------+
#property  copyright "Copyright 2005 Ron Thompson"
#property  link      "http://www.forexmt4.com/"


// indicator settings
#property  indicator_separate_window



// buffers
#property indicator_buffers   1
#property indicator_color1  White

// user input
extern int xbars = 500;
extern int PeriodGo = 1;
extern int PeriodStop = 200;
extern int WhichLSMA = 1;

// bar counting
datetime bartime=0;


// Objects
int     uniq=0;

// LSMA
int per;

// buffers
double buff1[]; 


//+-----------+
//| Init      |
//+-----------+
int init()
  {
   // 233 up arrow
   // 234 down arrow
   // 158 little dot
   // 159 big dot
   // 168 open square
   // 120 box with X
   
   ObjectsDeleteAll();

   SetIndexBuffer(0,buff1);
   SetIndexStyle(0, DRAW_LINE);
   //SetIndexArrow(0,159);

   
   Print("Init complete");
  }

//+-----------+
//| DE-Init   |
//+-----------+
int deinit()
  {
   ObjectsDeleteAll();
   
   Print("DE-Init complete");
  }


//+-----------+
//| Each Tick |
//+-----------+
int start()
  {   
   int    pos;

   int    vote;

   double wt;  //LSMA current value
   double wtp;  //LSMA previous value


   // draw once at open of bar 
   if(bartime==Time[0]) return(0);
   bartime=Time[0];

   ObjectsDeleteAll();
   uniq=0;
   
   for(pos = xbars; pos >= 0; pos--)
     {
      vote=0;
      for(per = PeriodGo; per <= PeriodStop; per++)
        { 
         wtp=wt;
         if (WhichLSMA == 1) wt  = LSMA(pos); else wt = iLsma(pos);


         if(wtwtp) vote--;
   
        }//for pos
        
      buff1[pos]=vote;
      //draw number on chart
      //ObjectCreate ("myx"+DoubleToStr(pos,0)+"_"+DoubleToStr(uniq,0), OBJ_TEXT, 0, Time[pos], wt );
      //if(wtwtp) ObjectSetText("myx"+DoubleToStr(pos,0)+"_"+DoubleToStr(uniq,0), ".",24,"Arial",LimeGreen);
      //uniq++;

     }//for per

  }//start

double LSMA(int mybar)
  {
   int    i;
   double sum=0;
   double lengthvar = ( per + 1.0 ) / 3.0;
   
   for(i = per; i >= 1  ; i--)
     {
      sum += ( i - lengthvar)*Open[per - i + mybar];
     }
   return(sum * 6 / (per*(per + 1)) );
  }         

double iLsma(int mybar)
{
   double wt;
   
   double ma1=iMA(NULL,0,per,0,MODE_SMA ,PRICE_OPEN,mybar);
   double ma2=iMA(NULL,0,per,0,MODE_LWMA,PRICE_OPEN,mybar);
   wt = 3.0*ma2-2.0*ma1;
   return(wt);
}  

 

Recommend