//+-----------+ //| LSMA | //+-----------+ #property copyright "Copyright 2005 Ron Thompson" #property link "http://www.forexmt4.com/" /* This indicator uses LSMA and colors it red when falling and green when rising. There is some buffer magic that makes this work. The order of the buffers and colors is important. Removing green exposes red removing red exposes green removing neither shows yellow (!?!) */ //---- indicator settings #property indicator_chart_window #property indicator_buffers 8 #property indicator_color1 Yellow #property indicator_color2 Green #property indicator_color3 Red #property indicator_color4 Green #property indicator_color5 Red #property indicator_color6 LawnGreen #property indicator_color7 Red #property indicator_color8 Yellow //---- buffers double ExtMapBuffer1[]; //Yellow double ExtMapBuffer2[]; //Green double ExtMapBuffer3[]; //Red double XBuffer[]; //White double ZBuffer[]; //White double ExtMapBuffer6[]; //Green double ExtMapBuffer7[]; //Red double ExtMapBuffer8[]; //Yellow extern int extRperiod = 58; extern double extSlope = 6.0; extern int extDraw4HowLong = 500; extern bool showarrows=false; extern bool showarrowvalues=false; // bar open handling int bartime; //Objects int uniq=0; //+-----------+ //| Init | //+-----------+ int init() { ObjectsDeleteAll(); SetIndexBuffer(0,ExtMapBuffer1); //Yellow SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2); SetIndexBuffer(1,ExtMapBuffer2); //Green SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 2); SetIndexBuffer(2,ExtMapBuffer3); //Red SetIndexStyle(2, DRAW_LINE, STYLE_SOLID, 2); // 233 up arrow // 234 down arrow // 158 little dot // 159 big dot // 168 open square // 120 box with X SetIndexStyle(3,DRAW_ARROW); SetIndexBuffer(3, XBuffer); //Green SetIndexArrow(3,233); SetIndexStyle(4,DRAW_ARROW); SetIndexBuffer(4, ZBuffer); //Red SetIndexArrow(4,234); SetIndexBuffer(5,ExtMapBuffer6); //Green SetIndexStyle(5, DRAW_ARROW); SetIndexArrow(5,233); SetIndexBuffer(6,ExtMapBuffer7); //Red SetIndexStyle(6, DRAW_ARROW); SetIndexArrow(6,234); SetIndexBuffer(7,ExtMapBuffer8); //Yellow SetIndexStyle(7, DRAW_ARROW); SetIndexArrow(7,120); Print("Init complete"); } //+-----------+ //| DE-Init | //+-----------+ int deinit() { int i; for( i=0; i= 0; pos--) { //save previous value wtp = wt; //get next bar LSMA wt = LSMA(pos); //calculate difference wd = (wt-wtp)/Point; // draw actual LSMA line ExtMapBuffer1[pos] = wt; //yellow ExtMapBuffer2[pos] = wt; //green ExtMapBuffer3[pos] = wt; //red if (wtp < wt+(pSlope)) //rising, remove RED { ExtMapBuffer3[pos] = EMPTY_VALUE; } if (wtp > wt-(pSlope)) //falling, remove GREEN { ExtMapBuffer2[pos] = EMPTY_VALUE; } if(showarrows) { // Draw arrows that reflect the REAL difference levels sColor="YELLOW"; if (wd > 0.0 && wd > extSlope ) //rising { sColor="GREEN"; ExtMapBuffer6[pos]=wt;//+(10*Point); } if (wd < 0.0 && wd < (extSlope*(-1)) ) //falling { sColor="RED"; ExtMapBuffer7[pos]=wt;//+(10*Point); } if (sColor=="YELLOW") //static - within slope { ExtMapBuffer8[pos]=wt;//+(10*Point); } } if(showarrowvalues) { ObjectCreate("myx"+DoubleToStr(uniq,0), OBJ_TEXT, 0, Time[pos], wt ); ObjectSetText("myx"+DoubleToStr(uniq,0),DoubleToStr(wd,0),15,"Arial",White); uniq++; } }//for }//start double LSMA(int mybar) { int i; double sum=0; double lengthvar = ( extRperiod + 1.0 ) / 3.0; for(i = extRperiod; i >= 1 ; i--) { sum += ( i - lengthvar)*Open[extRperiod - i + mybar]; } return(sum * 6 / (extRperiod*(extRperiod + 1)) ); }