LSMA Question

 

Trying to pin point when downward trend stops and upward trend begins.

.

Here's the LSMA code:

.

//+------------------------------------------------------------------+
//| |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| https://www.metaquotes.net// |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005"
#property link "https://www.metaquotes.net//"

//---- indicator settings
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 Lime
#property indicator_color3 White

//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];

extern int Rperiod = 25;
int Draw4HowLong, shift, i, loopbegin, length, c, width;
double sum[], lengthvar, tmp, wt[], CNT[];
string FoundColor, ArrowUpA;


//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- 3 additional buffers are used for counting.

IndicatorBuffers(6);

//---- drawing settings
SetIndexBuffer(2,ExtMapBuffer1);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexBuffer(0,ExtMapBuffer3);
SetIndexBuffer(3,sum);
SetIndexBuffer(4,wt);
SetIndexBuffer(5,CNT);

SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,3);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,3);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,3);

//---- initialization done

return(0);
}

int start()

{ Draw4HowLong = Bars-Rperiod - 5;
length = Rperiod;
loopbegin = Draw4HowLong - length - 1;



for(shift = loopbegin; shift >= 0; shift--)

{
sum[1] = 0;

for(i = length; i >= 1 ; i--)

{
lengthvar = length + 1;
lengthvar /= 3; //Dividing the y variable(lengthvar) by x(3) y /= x;
tmp = 0;
tmp = ( i - lengthvar)*Close[length-i+shift];
sum[1]+=tmp; //Adding x(0) to the y variable(tmp) y += x;
}

wt[shift] = sum[1]*6/(length*(length+1));



//========== COLOR CODING ===========================================

ExtMapBuffer3[shift] = wt[shift]; //White

ExtMapBuffer2[shift] = wt[shift]; //Lime

ExtMapBuffer1[shift] = wt[shift]; //Red

if (wt[shift+1] > wt[shift])

{
CNT[1] = 2;
ExtMapBuffer2[shift+1] = EMPTY_VALUE;


}

if (wt[shift+1] < wt[shift])

{
CNT[1] = 1;
ExtMapBuffer1[shift+1] = EMPTY_VALUE;

}

else

{
CNT[1] = 3;
ExtMapBuffer1[shift+1]=CLR_NONE; //EMPTY_VALUE;
ExtMapBuffer2[shift+1]=CLR_NONE; //EMPTY_VALUE;


}


}

return(0);
}
//+------------------------------------------------------------------+

.

.

.

I created another buffer (#5) as a way to capture a val at the time of each "if statement" which should be each of the colors of the LSMA. I set CNT[1] to 1 for RED, 2 for LIME and 3 for WHITE.

.

But, with all my attempts to bring this value into my EA;

.

.

double LSMA5 = iCustom(NULL,0,"LSMA",5,0); //---- LSMA Buffer 5

Alert("LSMA5 = " + LSMA5);

.

.

All I get is;

.

Alert: LSMA5 = 2147483647.00000000

.

.

Can someone tell me what I'm doing wrong? Can someone show me how to capture the point when a downward trend changes to an upward trend? Or, the point when the colors change?

.

.

.

Thanks!

 

"Can someone show me how to capture the point when a downward trend changes to an upward trend?"

The actual point! hmmm???

If you managed to predict this point with you indicator I will be impressed!

Sorry I am not trying to put you down, but I do believe everybody on this forum would like to know the answer to this conumdrum. The actual point where the trend changes!! WOW!! Ambitious indeed.

Maybe you are being a bit optimistic. Maybe you should just wait a while and then find a confirmation point where you can with some degree of confidence ASSUME that the trend has already changed some time ago.

Anyway, goodluck with finding the actual point where the trend change.

whocares

 

Try making buffers count consistent it might be confusing the MT4 interpreter.

#property indicator_buffers 6

Reason: