//+------------------------------------------------------------------+ //| 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); //------------------------------------------------------------------------------------ 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 (Result<iMaxPeriod) Result=0; else Result=Result+iMaxPeriod; return(Result); } //------------------------------------------ StartCounter -------------------------- bool StartCounter(string WindowName,int iPreCount,int& iCalcCount,int iMaxPeriod) { if ((iPreCount>iCalcCount)||(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<iMaxPeriod) Result=iMaxPeriod; return(Result+iMaxPeriod); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~ Style active Line ~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void SetupChartLine(int Index,double& ViewAy[],int Style,int Width,string Label) { switch(Style) { case 0 : SetIndexStyle(Index,DRAW_LINE,STYLE_SOLID,Width);break; case 1 : SetIndexStyle(Index,DRAW_HISTOGRAM,STYLE_SOLID,Width);break; case 2 : SetIndexStyle(Index,DRAW_ARROW,STYLE_SOLID,Width);break; default : SetIndexStyle(Index,DRAW_LINE,STYLE_SOLID,Width);break; } if (Label!="") SetIndexLabel(Index,Label); SetIndexBuffer(Index,ViewAy); return(0); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sample
Analysis
Market Information Used:
Series array that contains close prices for each bar
Indicator Curves created:
Implements a curve of type DRAW_LINE
Implements a curve of type DRAW_HISTOGRAM
Implements a curve of type DRAW_ARROW
Indicators Used:
Custom Indicators Used:
Order Management characteristics:
Other Features:
It issuies visual alerts to the screen