0 Views
0 Downloads
0 Favorites
FrAMAcolor
ÿþ 



#property indicator_chart_window

#property indicator_buffers 2

#property indicator_plots   1

//--- ?>AB@>5=85 iFrAMA

#property indicator_label1  "iFrAMA"

#property indicator_type1   DRAW_COLOR_LINE

#property indicator_color1  clrBlack, clrBlue,clrSnow

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1

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

//| 5@5G8A;5=85 A?>A>1>2 A>740=8O EM=4;0                            |

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





input int                  ma_period=14;                 // ?5@8>4 CA@54=5=8O

int                  ma_shift=0;                   // A<5I5=85

ENUM_APPLIED_PRICE   applied_price=PRICE_CLOSE;    // B8? F5=K

string               symbol=" ";                   // A8<2>;

ENUM_TIMEFRAMES      period=PERIOD_CURRENT;        // B09<D@59<

//--- 8=48:0B>@=K9 1CD5@

double         iFrAMABuffer[];

double                     FrAmaBufferColor[];

//--- ?5@5<5==0O 4;O E@0=5=8O EM=4;0 8=48:0B>@0 iFrAMA

int    handle;

//--- ?5@5<5==0O 4;O E@0=5=8O

string name=symbol;

//--- 8<O 8=48:0B>@0 =0 3@0D8:5

string short_name;

//--- 1C45< E@0=8BL :>;8G5AB2> 7=0G5=89 2 8=48:0B>@5 Fractal Adaptive Moving Average

int    bars_calculated=0;

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- ?@82O7:0 <0AA820 : 8=48:0B>@=><C 1CD5@C

   SetIndexBuffer(0,iFrAMABuffer,INDICATOR_DATA);

   SetIndexBuffer(1,FrAmaBufferColor,INDICATOR_COLOR_INDEX);

//--- 704048< A<5I5=85

   PlotIndexSetInteger(0,PLOT_SHIFT,ma_shift);

//--- >?@545;8<AO A A8<2>;><, =0 :>B>@>< AB@>8BAO 8=48:0B>@

   name=symbol;

//--- C40;8< ?@>15;K A;520 8 A?@020

   StringTrimRight(name);

   StringTrimLeft(name);

//--- 5A;8 ?>A;5 MB>3> 4;8=0 AB@>:8 name =C;520O

   if(StringLen(name)==0)

     {

      //--- 2>7L<5< A8<2>; A 3@0D8:0, =0 :>B>@>< 70?CI5= 8=48:0B>@

      name=_Symbol;

     }

//--- A>74048< EM=4; 8=48:0B>@0



      handle=iFrAMA(name,period,ma_period,ma_shift,applied_price);



//--- 5A;8 =5 C40;>AL A>740BL EM=4;

   if(handle==INVALID_HANDLE)

     {

      //--- A>>1I8< > =5C40G5 8 2K2545< =><5@ >H81:8

      PrintFormat("5 C40;>AL A>740BL EM=4; 8=48:0B>@0 iFrAMA 4;O ?0@K %s/%s, :>4 >H81:8 %d",

                  name,

                  EnumToString(period),

                  GetLastError());

      //--- @01>B0 8=48:0B>@0 7025@H05BAO 4>A@>G=>

      return(INIT_FAILED);

     }

//--- ?>:065< =0 :0:>9 ?0@5 A8<2>;/B09<D@59< @0AAG8B0= 8=48:0B>@ iFrAMA

   short_name=StringFormat("iFrAMA(%s/%s, %d, %d, %s)",name,EnumToString(period),

                           ma_period,ma_shift,EnumToString(applied_price));

   IndicatorSetString(INDICATOR_SHORTNAME,short_name);

//--- =>@<0;L=>5 2K?>;=5=85 8=8F80;870F88 8=48:0B>@0

   return(INIT_SUCCEEDED);

  }

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

//| Custom indicator iteration function                              |

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

int OnCalculate(const int rates_total,

                const int prev_calculated,

                const datetime &time[],

                const double &open[],

                const double &high[],

                const double &low[],

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[])

  {

//--- :>;8G5AB2> :>?8@C5<KE 7=0G5=89 87 8=48:0B>@0 iFrAMA

   int values_to_copy;

//--- C7=05< :>;8G5AB2> @0AAG8B0==KE 7=0G5=89 2 8=48:0B>@5

   int calculated=BarsCalculated(handle);

   if(calculated<=0)

     {

      PrintFormat("BarsCalculated() 25@=C; %d, :>4 >H81:8 %d",calculated,GetLastError());

      return(0);

     }

//--- 5A;8 MB> ?5@2K9 70?CA: 2KG8A;5=89 =0H53> 8=48:0B>@0 8;8 87<5=8;>AL :>;8G5AB2> 7=0G5=89 2 8=48:0B>@5 iFrAMA

//--- 8;8 5A;8 =5>1E>48<> @0AAG8B0BL 8=48:0B>@ 4;O 42CE 8;8 1>;55 10@>2 (7=0G8B GB>-B> 87<5=8;>AL 2 8AB>@88)

   if(prev_calculated==0 || calculated!=bars_calculated || rates_total>prev_calculated+1)

     {

      //--- 5A;8 <0AA82 iFrAMABuffer 1>;LH5, G5< 7=0G5=89 2 8=48:0B>@5 iFrAMA =0 ?0@5 symbol/period, B> :>?8@C5< =5 2A5

      //--- 2 ?@>B82=>< A;CG05 :>?8@>20BL 1C45< <5=LH5, G5< @07<5@ 8=48:0B>@=KE 1CD5@>2

      if(calculated>rates_total)

         values_to_copy=rates_total;

      else

         values_to_copy=calculated;

     }

   else

     {

      //--- 7=0G8B =0H 8=48:0B>@ @0AAG8BK205BAO =5 2 ?5@2K9 @07 8 A <><5=B0 ?>A;54=53> 2K7>20 OnCalculate())

      //--- 4;O @0AG5B0 4>1028;>AL =5 1>;55 >4=>3> 10@0

      values_to_copy=(rates_total-prev_calculated)+1;

     }

//--- 70?>;=O5< <0AA82 iFrAMABuffer  7=0G5=8O<8 87 8=48:0B>@0 Fractal Adaptive Moving Average

//--- 5A;8 FillArrayFromBuffer 25@=C;0 false, 7=0G8B 40==K5 =5 3>B>2K - 7025@H05< @01>BC

   if(!FillArrayFromBuffer(iFrAMABuffer,ma_shift,handle,values_to_copy))

      return(0);

//--- AD>@<8@C5< A>>1I5=85

//string comm=StringFormat("%s ==>  1=>2;5=> 7=0G5=89 2 8=48:0B>@5 %s: %d",

//TimeToString(TimeCurrent(),TIME_DATE|TIME_SECONDS),

//short_name,

//values_to_copy);

//--- 2K2545< =0 3@0D8: A;C651=>5 A>>1I5=85

//Comment(comm);

   for(int i=0; (i<=values_to_copy && i<rates_total-1  && !IsStopped()); i++)

     {



      //Print (i +" "+FrAmaBuffer[i]+" " +FrAmaBuffer[i+1]);

      if(iFrAMABuffer[i]<iFrAMABuffer[i+1])

        { FrAmaBufferColor[i]=1;}

      else

         if(iFrAMABuffer[i]>iFrAMABuffer[i+1])

           {FrAmaBufferColor[i]=2;}

         else

           {

            //Print (i +" "+iFrAMABuffer[i]+" " +iFrAMABuffer[i+1]);

            FrAmaBufferColor[i]=0;

           };

     };





//--- 70?><=8< :>;8G5AB2> 7=0G5=89 2 8=48:0B>@5 Fractal Adaptive Moving Average

   bars_calculated=calculated;

//--- 25@=5< 7=0G5=85 prev_calculated 4;O A;54CNI53> 2K7>20

   return(rates_total);

  }

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

//| 0?>;=O5< 8=48:0B>@=K9 1CD5@ 87 8=48:0B>@0 iFrAMA                |

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

bool FillArrayFromBuffer(double &values[],  // 8=48:0B>@=K9 1CD5@ 7=0G5=89 Fractal Adaptive Moving Average

                         int shift,         // A<5I5=85

                         int ind_handle,    // EM=4; 8=48:0B>@0 iFrAMA

                         int amount         // :>;8G5AB2> :>?8@C5<KE 7=0G5=89

                        )

  {

//--- A1@>A8< :>4 >H81:8

   ResetLastError();

//--- 70?>;=O5< G0ABL <0AA820 iFrAMABuffer 7=0G5=8O<8 87 8=48:0B>@=>3> 1CD5@0 ?>4 8=45:A>< 0

   if(CopyBuffer(ind_handle,0,-shift,amount,values)<0)

     {

      //--- 5A;8 :>?8@>20=85 =5 C40;>AL, A>>1I8< :>4 >H81:8

      PrintFormat("5 C40;>AL A:>?8@>20BL 40==K5 87 8=48:0B>@0 iFrAMA, :>4 >H81:8 %d",GetLastError());

      //--- 7025@H8< A =C;52K< @57C;LB0B>< - MB> >7=0G05B, GB> 8=48:0B>@ 1C45B AG8B0BLAO =5@0AAG8B0==K<

      return(false);

     }

//--- 2A5 ?>;CG8;>AL

   return(true);

  }

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

//| Indicator deinitialization function                              |

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

//void OnDeinit(const int reason)

//  {

////--- ?>G8AB8< 3@0D8: ?@8 C40;5=88 8=48:0B>@0

//   Comment("");

//  }

Comments