//+------------------------------------------------------------------+ //| DigitalF-T01.mq5 | //| Copyright © 2006, XXX | //| | //+------------------------------------------------------------------+ //--- Copyright #property copyright "Copyright © 2006, XXX" //--- Copyright #property link "" //--- Indicator version #property version "1.00" //--- drawing the indicator in a separate window #property indicator_separate_window //--- four buffers are used for indicator calculation and drawing #property indicator_buffers 4 //---- three plots are used #property indicator_plots 3 //+----------------------------------------------+ //| DigitalF-T01 drawing parameters | //+----------------------------------------------+ //--- drawing indicator 1 as a line #property indicator_type1 DRAW_LINE //---- DarkOrchid color is used as the color of the indicator basic line #property indicator_color1 clrDarkOrchid //---- the line of the indicator 1 is a continuous curve #property indicator_style1 STYLE_SOLID //--- indicator 1 line width is equal to 2 #property indicator_width1 2 //---- displaying of the the indicator label #property indicator_label1 "DigitalF-T01" //+----------------------------------------------+ //| Trigger indicator drawing parameters | //+----------------------------------------------+ //--- drawing indicator 2 as a line #property indicator_type2 DRAW_LINE //---- red color is used for the indicator signal line #property indicator_color2 clrRed //---- the line of the indicator 2 is a continuous curve #property indicator_style2 STYLE_SOLID //--- indicator 2 line width is equal to 2 #property indicator_width2 2 //---- displaying of the the indicator label #property indicator_label2 "Trigger" //+-----------------------------------+ //| Cloud drawing parameters | //+-----------------------------------+ //---- drawing the indicator as a colored cloud #property indicator_type3 DRAW_FILLING //---- the following colors are used as the indicator colors #property indicator_color3 clrPaleGreen,clrHotPink //+----------------------------------------------+ //| Declaration of enumeration | //+----------------------------------------------+ enum Applied_price_ //Type of constant { PRICE_CLOSE_ = 1, //Close PRICE_OPEN_, //Open PRICE_HIGH_, //High PRICE_LOW_, //Low PRICE_MEDIAN_, //Median Price (HL/2) PRICE_TYPICAL_, //Typical Price (HLC/3) PRICE_WEIGHTED_, //Weighted Close (HLCC/4) PRICE_SIMPL_, //Simple Price (OC/2) PRICE_QUARTER_, //Quarted Price (HLOC/4) PRICE_TRENDFOLLOW0_, //TrendFollow_1 Price PRICE_TRENDFOLLOW1_, //TrendFollow_2 Price PRICE_DEMARK_ //Demark Price }; //+----------------------------------------------+ //| Indicator input parameters | //+----------------------------------------------+ input uint halfchanel=25; // Trigger ratio input Applied_price_ IPC=PRICE_CLOSE_; // Price constant input int Shift=0; // Horizontal shift of the indicator in bars //+----------------------------------------------+ //--- declaration of dynamic arrays that //--- will be used as indicator buffers double DigBuffer[]; double TriggerBuffer[]; double UpBuffer[]; double DnBuffer[]; double dHalfchanel; //--- declaration of the integer variables for the start of data calculation int min_rates_total; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //--- initialization of variables of the start of data calculation min_rates_total=24; int sh=int(MathRound(60*(23*60+59)/PeriodSeconds())+1); min_rates_total=MathMax(min_rates_total,sh); dHalfchanel=halfchanel*_Point; //--- set the DigBuffer[] dynamic array as an indicator buffer SetIndexBuffer(0,DigBuffer,INDICATOR_DATA); //---- shifting the indicator 1 horizontally by Shift PlotIndexSetInteger(0,PLOT_SHIFT,Shift); //---- shifting the starting point of the indicator 1 drawing by min_rates_total PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total); //--- setting the indicator values that won't be visible on a chart PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE); //---- set TriggerBuffer[] dynamic array as an indicator buffer SetIndexBuffer(1,TriggerBuffer,INDICATOR_DATA); //---- shifting the indicator 2 horizontally by Shift PlotIndexSetInteger(1,PLOT_SHIFT,Shift); //---- shifting the starting point of the indicator 2 drawing by min_rates_total PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,min_rates_total+1); //--- setting the indicator values that won't be visible on a chart PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE); //---- set UpBuffer[] dynamic array as an indicator buffer SetIndexBuffer(2,UpBuffer,INDICATOR_DATA); //---- shifting the indicator 1 horizontally by Shift PlotIndexSetInteger(2,PLOT_SHIFT,Shift); //---- shifting the starting point of the indicator 1 drawing by min_rates_total PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,min_rates_total); //--- setting the indicator values that won't be visible on a chart PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,EMPTY_VALUE); //---- set DnBuffer[] dynamic array as an indicator buffer SetIndexBuffer(3,DnBuffer,INDICATOR_DATA); //---- shifting the indicator 1 horizontally by Shift PlotIndexSetInteger(3,PLOT_SHIFT,Shift); //---- shifting the starting point of the indicator 1 drawing by min_rates_total PlotIndexSetInteger(3,PLOT_DRAW_BEGIN,min_rates_total); //--- setting the indicator values that won't be visible on a chart PlotIndexSetDouble(3,PLOT_EMPTY_VALUE,EMPTY_VALUE); //--- initializations of a variable for the indicator short name string shortname; StringConcatenate(shortname,"DigitalF-T01(",halfchanel,", ",EnumToString(IPC),", ",Shift,")"); //--- Creation of the name to be displayed in a separate sub-window and in a pop up help IndicatorSetString(INDICATOR_SHORTNAME,shortname); //--- Determining the accuracy of displaying the indicator values IndicatorSetInteger(INDICATOR_DIGITS,_Digits); //--- } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, // number of bars in history at the current tick const int prev_calculated,// amount of history in bars at the previous tick const datetime &time[], const double &open[], const double& high[], // price array of price maximums for the indicator calculation const double& low[], // price array of minimums of price for the indicator calculation const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { //--- checking if the number of bars is enough for the calculation if(rates_totalrates_total || prev_calculated<=0) // checking for the first start of calculation of an indicator first=24; // starting number for calculation of all bars else first=prev_calculated-1; // starting index for calculation of new bars //--- the main loop of calculation of the digital filter for(bar=first; barrates_total || prev_calculated<=0) first=min_rates_total; //--- the main loop of calculation of the trigger line for(bar=first; bar=close[barX]) TriggerBuffer[bar]=close[barX]+dHalfchanel; if(DigBuffer[bar]Open[bar])return(High[bar]); else { if(Close[bar]Open[bar])return((High[bar]+Close[bar])/2.0); else { if(Close[bar]Open[bar]) res=(res+High[bar])/2; if(Close[bar]==Open[bar]) res=(res+Close[bar])/2; return(((res-Low[bar])+(res-High[bar]))/2); } //--- default: return(Close[bar]); } //--- } //+------------------------------------------------------------------+