//+------------------------------------------------------------------+ //| geL2WMA.mq4 | //| Copyright © 2007, ver 1.0 | //| Forte928 | //+------------------------------------------------------------------+ #property copyright "Forte928" #property link "" #define IndicatorName "geL2WMA" #property indicator_chart_window //#property indicator_separate_window #property indicator_buffers 3 #property indicator_color1 Tomato #property indicator_color2 Yellow #property indicator_color3 Wheat extern int L2WMAPrd =8; extern int Shift =0; extern int Counter =2000; //double FreqTOL =0.0001;//Tolerance of frequency calculation for Method 1 double FxView1[]; double FxView2[]; double FxView3[]; double FxView4[]; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~V~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Work Variables ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ double TimeBuf1[]; double TimeBuf2[]; double TimeBuf3[]; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~V~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Initialization program Buffers ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void InitBufferam(int iBufferSize) { ArrayResize(TimeBuf1,iBufferSize); ArrayResize(TimeBuf2,iBufferSize); ArrayResize(TimeBuf3,iBufferSize); return; } void EmptyBufferam() { ArrayInitialize(TimeBuf1,EMPTY_VALUE); ArrayInitialize(TimeBuf2,EMPTY_VALUE); ArrayInitialize(TimeBuf3,EMPTY_VALUE); // --> return; } void DoneBufferam() { ArrayResize(TimeBuf1,0); ArrayResize(TimeBuf2,0); ArrayResize(TimeBuf3,0); return; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~V~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Program Constants ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ int MaxPeriod=0; int CalcCount=0; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Custom indicator initialization function ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ int init() { //---- initialization program values -------------------------------- MaxPeriod=MathMax(L2WMAPrd,L2WMAPrd); InitBufferam(MaxCounter(Counter,MaxPeriod)); CalcCount=InitCounter(Counter,MaxPeriod); //---- initialization indicators ------------------------------------- SetupChartLine(0,FxView1,0,1,"L2WMA"+L2WMAPrd);// SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1); SetIndexBuffer(0,ValueBuf0); SetupChartLine(1,FxView2,0,1,"Line2");// SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1); SetIndexBuffer(0,ValueBuf0); SetupChartLine(2,FxView3,0,1,"Line3");// SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1); SetIndexBuffer(0,ValueBuf0); SetupChartLine(3,FxView4,0,1,"Line4");// SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1); SetIndexBuffer(0,ValueBuf0); IndicatorShortName(IndicatorName+"("+L2WMAPrd+")"); IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)); //---- return(0); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~V~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Custom indicator deinitialization function ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ int deinit() { //---- DoneBufferam(); //---- return(0); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~V~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Start defination ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ int start() { if (!StartCounter(IndicatorName,Counter,CalcCount,MaxPeriod)) return(-1); int counted_bars = IndicatorCounted(); if(counted_bars < 0) return(-1); if(counted_bars > 0) counted_bars--; int CalcCount = Bars - counted_bars; if(counted_bars==0) CalcCount-=1+L2WMAPrd; //------------------------------------------------------------------------------------ InitBufferam(CalcCount); EmptyBufferam(); //+-------------------------- Begin Cycle ---------------------------------------------------+\\ for (int Rx=CalcCount-1;Rx>=0;Rx--){ double SumRx=0; double WeightRx=0; double SumLx=0; for (int Px=L2WMAPrd-1;Px>=0;Px--) { double SumPx=0; double WeightPx=0; for (int Sx=Px;Sx>=0;Sx--) { SumPx=SumPx+Close[Rx+Sx]*(Px-Sx+1); // формирование суммы для L2WMA внутрений цикл WeightPx=WeightPx+(Sx+1); } SumRx=SumRx+SumPx/WeightPx*(L2WMAPrd-Px); // формирование суммы для L2WMA внешний цикл // SumLx=SumLx+Close[Rx+Px]*(L2WMAPrd-Px); // формирование суммы для LWMA WeightRx=WeightRx+(Px+1); } TimeBuf1[Rx]=SumRx/WeightRx; // TimeBuf2[Rx]=SumLx/WeightRx; } ArrayCopy(FxView1,TimeBuf1,Shift,0,CalcCount); // ArrayCopy(FxView2,TimeBuf2,Shift,0,CalcCount); //---- return(0); } //----------------------------------------------------------------------------------------------- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~ InitCounter ~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ int InitCounter(int iPreCount,int iMaxPeriod) { // Rule 1 //if ((Result==0)||(Result>Bars)) Result=Bars; int Result=MaxCounter(iPreCount,iMaxPeriod); // Rule 2 if ((Result+iMaxPeriod)>Bars) Result=Bars-iMaxPeriod; // Rule 3 if (ResultiCalcCount)||(iPreCount==0)) iCalcCount=InitCounter(iPreCount,iMaxPeriod); if (iCalcCount==0) { Alert(WindowName+" "+Symbol()+"("+Period()+") - Limited Calculate Period"); return(false); } return(true); //int iBarCount=IndicatorCounted(); //if (iBarCount>0) return(true); //Print("StartCounter"); return(false); } //------------------------------------------ StartCounter -------------------------- int MaxCounter(int iPreCount,int iMaxPeriod) { int Result=iPreCount; // Rule 1 //if ((Result==0)||(Result>Bars)) Result=Bars; if (Result==0) Result=Bars-1; if (Result