some revisions on Vladimir Karputov's indicator <...>

 

This indicator shows 3 bars at the right part of the chart:

D1 BAR and other 2 ( which shows current) +1( previous ) TF choosen by user at inputs section of the codes. 

I want to publish the codes at CodeBase but many trials could not reach the publication phase so I decided to give codes at FORUM :

Thanks to Vladimir Karputov and all free CodeBase users 

//+------------------------------------------------------------------+
//|                                   Daily Bar 2 revised 3with1.mq5 |
//|                              Copyright © 2020, Vladimir Karputov |
//|                     revised by M. Nail Sertoglu                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2020, Vladimir Karputov"
#property version   "3.001"
#property description "3 bars: D1 and other 2(current)+1(previous) TF choosen by user"
#property indicator_chart_window
#property indicator_buffers 15
#property indicator_plots   3
//--- plot Daily
#property indicator_label1  "1st-TF"
#property indicator_type1   DRAW_COLOR_CANDLES
#property indicator_color1  clrAqua,clrPink
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot Second timeframe
#property indicator_label2  "2nd-TF"
#property indicator_type2   DRAW_COLOR_CANDLES
#property indicator_color2  clrLimeGreen,clrLavender
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
#property indicator_label3  "3rd-TF"
#property indicator_type3   DRAW_COLOR_CANDLES
#property indicator_color3  clrAqua,clrPink
#property indicator_style3  STYLE_SOLID
#property indicator_width3  1
//--- input parameters
input int               InpShift     = 6;           // Shift to right
input ENUM_TIMEFRAMES   Inp_perid2   = PERIOD_M15;  // 2nd timeframe
input ENUM_TIMEFRAMES   Inp_period   = PERIOD_H1;   // 3rd timeframe
input ENUM_TIMEFRAMES   InpLperiod   = PERIOD_D1;   // Longest timeframe
input bool              show_preHrs  = true;        // ?Show Prev.Period.L/H
input ENUM_TIMEFRAMES   InpPperiod   = PERIOD_H1;   // Previou Period
//--- indicator buffers
double   DailyOpenBuffer[];
double   DailyHighBuffer[];
double   DailyLowBuffer[];
double   DailyCloseBuffer[];
double   DailyColors[];
//---
double   SecondOpenBuffer[];
double   SecondHighBuffer[];
double   SecondLowBuffer[];
double   SecondCloseBuffer[];
double   SecondColors[];
//---
double   ThirdOpenBuffer[];
double   ThirdHighBuffer[];
double   ThirdLowBuffer[];
double   ThirdCloseBuffer[];
double   ThirdColors[];
//---
datetime m_prev_days   = 0;   // "0" -> D'1970.01.01 00:00';
double   m_daily_open  = 0.0, m_daily_high  = DBL_MIN, m_daily_low = DBL_MAX,  m_daily_close  = 0.0;
double   m_second_open = 0.0, m_second_high = DBL_MIN, m_second_low= DBL_MAX,  m_second_close = 0.0;
double   m_third_open  = 0.0, m_third_high  = DBL_MIN, m_third_low = DBL_MAX,  m_third_close  = 0.0;
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   string obj_name="Dfibo"+"*";
   if(ObjectFind(0,obj_name)>0)
      ObjectDelete(0,obj_name);
   ObjDelete(0,"Dfibo"+"*");
   ObjectsDeleteAll(0,-1,-1);
   Comment("");
  }
//+------------------------------------------------------------------+
bool ObjDelete(const long   chart_ID=0,         // chart's ID
               const string name="Dfibo"+"*")   // channel name
  {
//--- reset the error value
   ResetLastError();
//--- delete the channel
   if(!ObjectDelete(chart_ID,name))
     {
      Print(__FUNCTION__,
            ": failed to delete the channel! Error code = ",GetLastError());
      return(false);
     }
//--- successful execution
   return(true);
  }
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   if(Period()>PERIOD_D1)
      return(INIT_PARAMETERS_INCORRECT);
//--- indicator buffers mapping
   SetIndexBuffer(0,DailyOpenBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,DailyHighBuffer,INDICATOR_DATA);
   SetIndexBuffer(2,DailyLowBuffer,INDICATOR_DATA);
   SetIndexBuffer(3,DailyCloseBuffer,INDICATOR_DATA);
   SetIndexBuffer(4,DailyColors,INDICATOR_COLOR_INDEX);
   SetIndexBuffer(5,SecondOpenBuffer,INDICATOR_DATA);
   SetIndexBuffer(6,SecondHighBuffer,INDICATOR_DATA);
   SetIndexBuffer(7,SecondLowBuffer,INDICATOR_DATA);
   SetIndexBuffer(8,SecondCloseBuffer,INDICATOR_DATA);
   SetIndexBuffer(9,SecondColors,INDICATOR_COLOR_INDEX);
   SetIndexBuffer(10,ThirdOpenBuffer,INDICATOR_DATA);
   SetIndexBuffer(11,ThirdHighBuffer,INDICATOR_DATA);
   SetIndexBuffer(12,ThirdLowBuffer,INDICATOR_DATA);
   SetIndexBuffer(13,ThirdCloseBuffer,INDICATOR_DATA);
   SetIndexBuffer(14,ThirdColors,INDICATOR_COLOR_INDEX);
//--- set accuracy
   IndicatorSetInteger(INDICATOR_DIGITS,Digits());
//--- an empty value
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);
   PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,0.0);
//--- line shifts when drawing
   PlotIndexSetInteger(0,PLOT_SHIFT,InpShift);
   PlotIndexSetInteger(1,PLOT_SHIFT,InpShift-1);
   PlotIndexSetInteger(2,PLOT_SHIFT,InpShift-2);
//--- set the display of the symbol
   PlotIndexSetString(0,PLOT_LABEL,"D1 Open;"+"D1 High;"+"D1 Low;"+"D1 Close");
   string text=StringSubstr(EnumToString(Inp_period),7,-1);
   PlotIndexSetString(1,PLOT_LABEL,text+" Open;"+text+" High;"+text+" Low;"+text+" Close");
   text=StringSubstr(EnumToString(Inp_perid2),7,-2);
   PlotIndexSetString(2,PLOT_LABEL,text+" Open;"+text+" High;"+text+" Low;"+text+" Close");
//---
   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[])

  {
   int limit=rates_total;
//--- first calculation or number of bars was changed
   if(prev_calculated==0)
     {
      //printf(" rates_total (%d) > prev_calculated (%d)",rates_total,prev_calculated);
      for(int i=0; i<rates_total; i++)
        {
         DailyOpenBuffer[i]   =0.0;
         DailyHighBuffer[i]   =0.0;
         DailyLowBuffer[i]    =0.0;
         DailyCloseBuffer[i]  =0.0;
         DailyColors[i]       =0.0;
         //---
         SecondOpenBuffer[i]  =0.0;
         SecondHighBuffer[i]  =0.0;
         SecondLowBuffer[i]   =0.0;
         SecondCloseBuffer[i] =0.0;
         SecondColors[i]      =0.0;
         //---
         ThirdOpenBuffer[i]   =0.0;
         ThirdHighBuffer[i]   =0.0;
         ThirdLowBuffer[i]    =0.0;
         ThirdCloseBuffer[i]  =0.0;
         ThirdColors[i]       =0.0;
        }
      m_daily_open   =0.0;
      m_daily_high   =DBL_MIN;
      m_daily_low    =DBL_MAX;
      m_daily_close  =0.0;
      //---
      m_second_open  =0.0;
      m_second_high  =DBL_MIN;
      m_second_low   =DBL_MAX;
      m_second_close =0.0;
      //---
      m_third_open   =0.0;
      m_third_high   =DBL_MIN;
      m_third_low    =DBL_MAX;
      m_third_close  =0.0;
     }
//--- new bar
   else
      if(rates_total>prev_calculated && prev_calculated!=0)
        {
         //printf(" rates_total (%d) > prev_calculated (%d)",rates_total,prev_calculated);
         for(int i=prev_calculated-1; i<rates_total; i++)
           {
            DailyOpenBuffer[i]   =0.0;
            DailyHighBuffer[i]   =0.0;
            DailyLowBuffer[i]    =0.0;
            DailyCloseBuffer[i]  =0.0;
            DailyColors[i]       =0.0;
            //---
            SecondOpenBuffer[i]  =0.0;
            SecondHighBuffer[i]  =0.0;
            SecondLowBuffer[i]   =0.0;
            SecondCloseBuffer[i] =0.0;
            SecondColors[i]      =0.0;
            //---
            ThirdOpenBuffer[i]   =0.0;
            ThirdHighBuffer[i]   =0.0;
            ThirdLowBuffer[i]    =0.0;
            ThirdCloseBuffer[i]  =0.0;
            ThirdColors[i]       =0.0;
           }
         m_daily_open            =0.0;
         m_daily_high            =DBL_MIN;
         m_daily_low             =DBL_MAX;
         m_daily_close           =0.0;
         //---
         m_second_open           =0.0;
         m_second_high           =DBL_MIN;
         m_second_low            =DBL_MAX;
         m_second_close          =0.0;
         //---
         m_third_open            =0.0;
         m_third_high            =DBL_MIN;
         m_third_low             =DBL_MAX;
         m_third_close           =0.0;
        }
//---
   MqlDateTime STime_curr;
   TimeToStruct(time[rates_total-1],STime_curr);
   m_daily_close  = close[rates_total-1];
   m_second_close = close[rates_total-1];
   m_third_close  = close[rates_total-1];
   for(int i=rates_total-1; i>0; i--)
     {
      MqlDateTime STime_prev;
      TimeToStruct(time[i],STime_prev);
      if(i<rates_total-1)
        {
         m_daily_open=open[i+1];
        }
      if(STime_prev.day!=STime_curr.day)
        {
         break;
        }
      if(high[i]>m_daily_high)
        {
         m_daily_high=high[i];
        }
      if(low[i]<m_daily_low)
        {
         m_daily_low=low[i];
        }
      //---
      MqlRates rates_second[];
      int start_pos=0,count=1;
      if(CopyRates(Symbol(),Inp_period,start_pos,count,rates_second)!=count)
        {
         return(0);
        }
      m_second_open=rates_second[0].open;
      m_second_high=rates_second[0].high;
      m_second_low =rates_second[0].low;
      MqlRates rates_third[];
      start_pos=0;
      count=1;
      if(CopyRates(Symbol(),Inp_perid2,start_pos,count,rates_third)!=count)
        {
         return(0);
        }
      m_third_open=rates_third[0].open;
      m_third_high=rates_third[0].high;
      m_third_low =rates_third[0].low;
     }
//---
   DailyOpenBuffer[rates_total-1]   =m_daily_open;
   DailyHighBuffer[rates_total-1]   =m_daily_high;
   DailyLowBuffer[rates_total-1]    =m_daily_low;
   DailyCloseBuffer[rates_total-1]  =m_daily_close;
   DailyColors[rates_total-1]       =(m_daily_open<m_daily_close)?0.0:1.0;
//---
//--mns
// Daily
   double day_range  = (m_daily_high - m_daily_low) / _Point;
   double sdiff      = day_range*_Point;
   double smax       = m_daily_high;
   double smin       = m_daily_low;
   double D0fibo1000 = smax;
   double D0fibo0786 = smin + sdiff * .786;
   double D0fibo0618 = smin + sdiff * .618;
   double D0fibo0500 = smin + sdiff * .5;
   double D0fibo0382 = smin + sdiff * .382;
   double D0fibo0214 = smin + sdiff * .214;
   double D0fibo0000 = smin;
   double tp50       = D0fibo0500+(((m_daily_high-D0fibo0500)/2)/2);
   double bt50       = D0fibo0500-(((D0fibo0500-m_daily_low)/2)/2);
   string sname;
   /*      sname="Dfibo_.786";
         ObjectCreate(0,sname,OBJ_ARROWED_LINE,0,0,0);
         ObjectSetInteger(0,sname,OBJPROP_COLOR,clrPink);
         ObjectSetInteger(0,sname,OBJPROP_WIDTH,1);
         ObjectSetInteger(0,sname,OBJPROP_BACK,false);
         ObjectSetDouble(0,sname,OBJPROP_PRICE,0,D0fibo0786);
         ObjectSetInteger(0,sname,OBJPROP_TIME,0,TimeCurrent());
         ObjectSetDouble(0,sname,OBJPROP_PRICE,1,D0fibo0786);
         ObjectSetInteger(0,sname,OBJPROP_TIME,1,iTime(_Symbol, InpLperiod, 0));
         sname="Dfibo_.214";
         ObjectCreate(0,sname,OBJ_ARROWED_LINE,0,0,0);
         ObjectSetInteger(0,sname,OBJPROP_COLOR,clrPink);
         ObjectSetInteger(0,sname,OBJPROP_WIDTH,1);
         ObjectSetInteger(0,sname,OBJPROP_BACK,false);
         ObjectSetDouble(0,sname,OBJPROP_PRICE,0,D0fibo0214);
         ObjectSetInteger(0,sname,OBJPROP_TIME,0,TimeCurrent());
         ObjectSetDouble(0,sname,OBJPROP_PRICE,1,D0fibo0214);
         ObjectSetInteger(0,sname,OBJPROP_TIME,1,iTime(_Symbol, InpLperiod, 0));
   */
   sname="Dfibo_.5";
   ObjectCreate(0,sname,OBJ_ARROWED_LINE,0,0,0);
   ObjectSetInteger(0,sname,OBJPROP_COLOR,clrPink);
   ObjectSetInteger(0,sname,OBJPROP_WIDTH,1);
   ObjectSetInteger(0,sname,OBJPROP_BACK,false);
   ObjectSetDouble(0,sname,OBJPROP_PRICE,0,D0fibo0500);
   ObjectSetInteger(0,sname,OBJPROP_TIME,0,TimeCurrent());
   ObjectSetDouble(0,sname,OBJPROP_PRICE,1,D0fibo0500);
   ObjectSetInteger(0,sname,OBJPROP_TIME,1,iTime(_Symbol, InpLperiod, 0));
   sname="Dfibo_.0";
   ObjectCreate(0,sname,OBJ_ARROWED_LINE,0,0,0);
   ObjectSetInteger(0,sname,OBJPROP_COLOR,clrRed);
   ObjectSetInteger(0,sname,OBJPROP_WIDTH,2);
   ObjectSetInteger(0,sname,OBJPROP_BACK,false);
   ObjectSetDouble(0,sname,OBJPROP_PRICE,0,D0fibo0000);
   ObjectSetInteger(0,sname,OBJPROP_TIME,0,TimeCurrent());
   ObjectSetDouble(0,sname,OBJPROP_PRICE,1,D0fibo0000);
   ObjectSetInteger(0,sname,OBJPROP_TIME,1,iTime(_Symbol, InpLperiod, 0));
   sname="Dfibo_1.0";
   ObjectCreate(0,sname,OBJ_ARROWED_LINE,0,0,0);
   ObjectSetInteger(0,sname,OBJPROP_COLOR,clrAqua);
   ObjectSetInteger(0,sname,OBJPROP_WIDTH,2);
   ObjectSetInteger(0,sname,OBJPROP_BACK,false);
   ObjectSetDouble(0,sname,OBJPROP_PRICE,0,D0fibo1000);
   ObjectSetInteger(0,sname,OBJPROP_TIME,0,TimeCurrent());
   ObjectSetDouble(0,sname,OBJPROP_PRICE,1,D0fibo1000);
   ObjectSetInteger(0,sname,OBJPROP_TIME,1,iTime(_Symbol, InpLperiod, 0));
// H1 BAR
   int    dow           = 1; // ** previous **
   double hr1_open      = iOpen(_Symbol, InpPperiod, dow);
   double hr1_high      = iHigh(_Symbol, InpPperiod, dow);
   double hr1_low       = iLow(_Symbol,  InpPperiod, dow);
   double hr1_close     = iClose(_Symbol,InpPperiod, dow);
   double hr1_range     = (hr1_high - hr1_low) / _Point;
   double hr1_pivot     = (hr1_high+hr1_low+iClose(_Symbol, InpPperiod, 0))/3;
//-- prev H1 low & high
   if(show_preHrs==true)
     {
      sname="preTF.up";
      ObjectCreate(0,sname,OBJ_ARROW_RIGHT_PRICE,0,0,0);
      ObjectSetInteger(0,sname,OBJPROP_COLOR,clrGray);
      ObjectSetInteger(0,sname,OBJPROP_WIDTH,1);
      ObjectSetInteger(0,sname,OBJPROP_BACK,false);
      ObjectSetDouble(0,sname,OBJPROP_PRICE,0,hr1_high);
      ObjectSetInteger(0,sname,OBJPROP_TIME,0,TimeCurrent());
      ObjectSetDouble(0,sname,OBJPROP_PRICE,1,hr1_high);
      ObjectSetInteger(0,sname,OBJPROP_TIME,1,iTime(_Symbol, PERIOD_H1, 1));
      sname="preTF.dn";
      ObjectCreate(0,sname,OBJ_ARROW_RIGHT_PRICE,0,0,0);
      ObjectSetInteger(0,sname,OBJPROP_COLOR,clrGray);
      ObjectSetInteger(0,sname,OBJPROP_WIDTH,1);
      ObjectSetInteger(0,sname,OBJPROP_BACK,false);
      ObjectSetDouble(0,sname,OBJPROP_PRICE,0,hr1_low);
      ObjectSetInteger(0,sname,OBJPROP_TIME,0,TimeCurrent());
      ObjectSetDouble(0,sname,OBJPROP_PRICE,1,hr1_low);
      ObjectSetInteger(0,sname,OBJPROP_TIME,1,iTime(_Symbol, PERIOD_H1, 1));
      //------
     }
//--mns
//---
   SecondOpenBuffer[rates_total-1]  =m_second_open;
   SecondHighBuffer[rates_total-1]  =m_second_high;
   SecondLowBuffer[rates_total-1]   =m_second_low;
   SecondCloseBuffer[rates_total-1] =m_second_close;
   SecondColors[rates_total-1]      =(m_second_open<m_second_close)?0.0:1.0;
//---
   ThirdOpenBuffer[rates_total-1]   =m_third_open;
   ThirdHighBuffer[rates_total-1]   =m_third_high;
   ThirdLowBuffer[rates_total-1]    =m_third_low;
   ThirdCloseBuffer[rates_total-1]  =m_third_close;
   ThirdColors[rates_total-1]       =(m_third_open<m_third_close)?0.0:1.0;
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//|  RightPrice creation                                             |
//+------------------------------------------------------------------+
void CreateRightPrice(long chart_id,// chart ID
                      string   namF,              // object name
                      int      nwin,              // window index
                      datetime time,              // price level time
                      double   price,             // price level
                      color    Color              // Text color
                     )

  {
//----
   ObjectCreate(chart_id,namF,OBJ_ARROW_RIGHT_PRICE,nwin,time,price);
   ObjectSetInteger(chart_id,namF,OBJPROP_COLOR,Color);
   ObjectSetInteger(chart_id,namF,OBJPROP_BACK,true);
   ObjectSetInteger(chart_id,namF,OBJPROP_WIDTH,2);
//----
  }
//+------------------------------------------------------------------+
//|  RightPrice reinstallation                                       |
//+------------------------------------------------------------------+
void SetRightPrice(long chart_id,// chart ID
                   string   namE,              // object name
                   int      nwin,              // window index
                   datetime time,              // price level time
                   double   price,             // price level
                   color    Color              // Text color
                  )
  {
//----
   if(ObjectFind(chart_id,namE)==-1)
      CreateRightPrice(chart_id,namE,nwin,time,price,Color);
   else
      ObjectMove(chart_id,namE,0,time,price);
//----
  }
//+------------------------------------------------------------------+
 

1. Discussion about Market products is prohibited on the forum.

2. -

Forum on trading, automated trading systems and testing trading strategies

When you post code please use the CODE button (Alt-S)!

Use the CODE button


 
Sergey Golubev #:

1. Discussion about Market products is prohibited on the forum.

2. -


It is not a market product as the member tried to publish it in the free code base 

 
Carlos Albert Barbero Marcos #:

It is not a market product as the member tried to publish it in the free code base 

Surely correct answer; I could not publish the code using codeBase; hope someone may find it is useful