AMA_STL__Color

Author: Copyright © 2006, MetaQuotes Software Corp.
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
AMA_STL__Color
ÿþ//+------------------------------------------------------------------+

//|                                     AMA STL_Russian_Color_my.mq4 |

//|                      Copyright © 2006, MetaQuotes Software Corp. |

//|                                        http://www.metaquotes.net |

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

#property copyright "Copyright © 2006, MetaQuotes Software Corp."

#property link      "http://www.metaquotes.net"



#property indicator_chart_window

#property indicator_buffers 2

#property indicator_color1 DodgerBlue

#property indicator_color2 Tomato

#property indicator_width1 3

#property indicator_width2 3

//----

extern int Range=9;

extern int FastMA = 2;

extern int SlowMA = 30;

extern int CountBars=200;

extern int filter=25;

//----

double Up[];

double Down[];

double trend[];

double fAMA[];

double mAMA[];

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

//| Custom indicator initialization function                         |

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

int init()

  {

   IndicatorBuffers(5);

   SetIndexStyle(0,DRAW_LINE);

   SetIndexStyle(1,DRAW_LINE);

   SetIndexBuffer(0,Up);

   SetIndexBuffer(1,Down);

   SetIndexBuffer(2,trend);

   SetIndexBuffer(3,fAMA);

   SetIndexBuffer(4,mAMA);

   return(0);

  }

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

//| Custom indicator deinitialization function                       |

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

int deinit()

  {

//----

   return(0);

  }

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

//| Custom indicator iteration function                              |

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

int start()

  {

   if(CountBars>Bars) CountBars=Bars;

   SetIndexDrawBegin(0,Bars-CountBars+SlowMA+1);

   SetIndexDrawBegin(1,Bars-CountBars+SlowMA+1);

//int counted_bars = IndicatorCounted();

   int cb,i;

   double  k1,k2,Noise,ER,SSC,AMA,sdAMA,dAMA;

//----



   k1 = 2.0 / (SlowMA + 1);

   k2 = 2.0 / (FastMA + 1) - k1;

   AMA= Close[CountBars-Range];

   mAMA[CountBars-Range]=Close[CountBars-Range+1];

//----

   for(cb=CountBars; cb>=0; cb--)

     {

      Noise=0;

      //----

      for(i=cb; i<=cb+Range-1; i++)

        {

         Noise=Noise+MathAbs(Close[i]-Close[i+1]);

        }

      //----

      if(Noise!=0)

        {

         ER=MathAbs(Close[cb]-Close[cb+Range])/Noise;

        }

      else

        {

         ER=0;

        }

      SSC = (ER*k2 + k1);

      AMA = AMA + NormalizeDouble(SSC*SSC*(Close[cb] - AMA), 4);

      mAMA[cb]=AMA;

      //----

      if(filter<1)

        {

         fAMA[cb]=mAMA[cb];

        }

      else

        {

         for(i=cb; i<=cb+SlowMA-1; i++)

           {

            sdAMA=sdAMA+MathAbs(mAMA[i]-mAMA[i+1]);

           }

         dAMA=mAMA[cb]-mAMA[cb+1];

         //----

         if(dAMA>=0)

           {

            if(dAMA<NormalizeDouble(filter*sdAMA/(100*SlowMA),4) && 

               High[cb]<=High[Highest(NULL,0,MODE_HIGH,4,cb)]+10*Point)

              {

               fAMA[cb]=fAMA[cb+1];

              }

            else

              {

               fAMA[cb]=mAMA[cb];

              }

           }

         else

           {

            if(MathAbs(dAMA)<NormalizeDouble(filter*sdAMA/(100*SlowMA),4) && 

               Low[cb]>Low[Lowest(NULL,0,MODE_LOW,4,cb)]-10*Point)

              {

               fAMA[cb]=fAMA[cb+1];

              }

            else

              {

               fAMA[cb]=mAMA[cb];

              }

           }

         sdAMA=0.0;

        }

     }

//----     

   for(i=CountBars; i>=0; i--)

     {



      trend[i]=trend[i+1];

      if(fAMA[i]> fAMA[i+1]) trend[i] =1;

      if(fAMA[i]< fAMA[i+1]) trend[i] =-1;



      if(trend[i]>0)

        {

         Up[i]=fAMA[i];

         if(trend[i+1]<0) Up[i+1]=fAMA[i+1];

         Down[i]=EMPTY_VALUE;

        }

      else

      if(trend[i]<0)

        {

         Down[i]=fAMA[i];

         if(trend[i+1]>0) Down[i+1]=fAMA[i+1];

         Up[i]=EMPTY_VALUE;

        }



     }

   return(0);

  }

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

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---