Jump to content

MA trend Indicator


Recommended Posts

Hello friends this post is edited for the second time as after searching a lot found one ma cross trend indicatort, but it is having an bug in it.

 

It would be hepfull if anybody here remove the bug and make it work better.

 

Here is the code : (simple)

 

 

#property copyright ""

#property link ""

 

 

#property indicator_chart_window

 

#property indicator_buffers 3

#property indicator_color1 Green

#property indicator_color2 Red

#property indicator_color3 Yellow

 

extern int PeriodAv=12;

extern int PeriodAv1=24;

extern int Flat=1;

extern color ColorUp=Green;

extern color ColorDown=Red;

extern color ColorFlat=Yellow;

extern int Width=2;

 

 

double Line1[], Line2[], Line3[];

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

//---- indicators

SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,Width,ColorUp);//DRAW_LINE

SetIndexBuffer(0,Line1);

SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,Width,ColorDown);

SetIndexBuffer(1,Line2);

SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,Width,ColorFlat);//DRAW_LINE

SetIndexBuffer(2,Line3);

//----

return(0);

}

//+------------------------------------------------------------------+

//| Custom indicator deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

//----

 

//----

return(0);

}

//+------------------------------------------------------------------+

//| Custom indicator iteration function |

//+------------------------------------------------------------------+

int start()

{

//----

int i, Counted_bars=IndicatorCounted();

 

i=Bars-Counted_bars-1;

 

while(i>=0)

{

double MA_0=iMA(NULL,0,PeriodAv,0,MODE_EMA,PRICE_CLOSE,i),

MA_2=iMA(NULL,0,PeriodAv1,0,MODE_EMA,PRICE_CLOSE,i+1);

 

if(MA_0>MA_2) Line1=MA_0;

else

if(MA_0<MA_2) Line2=MA_0;

else if(MA_0==MA_2)

Line3=MA_0;

i--;

}

//----

return(0);

}

//+------------------------------------------------------------------+

 

Looking for an favourable reply friends :)

Edited by checkmail
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...