Download MetaTrader 5

How to draw histogram from point to point & how to hide separate window in a certain period

To add comments, please log in or register
Ali Mojtabaei
234
Ali Mojtabaei  

Hi every one.

I wrote a simple indicator that shows lowest and highest price value for each day in a separate window.

There are two buffers that are labeled as “A” and “B” respectively for lowest and highest day price.

I’m going to develop the code in order to

1)      Add a buffer in histogram type that starts from A and ends by B in each day.

2)     Hide the separate window when the period 4 hours and higher is selected.

Please help me.


HOW TO ADD HISTOGRAM
//+------------------------------------------------------------------+
//|                                                         1001.mq4 |
//|                                                   Ali Mojtabaei. |
//|                            https://telegram.me/mqlbyAliMojtabaei |
//+------------------------------------------------------------------+
#property copyright "Ali Mojtabaei."
#property link      "https://telegram.me/mqlbyAliMojtabaei"
#property version   "1.00"
#property strict
#property indicator_separate_window
/*********************************************/
#property indicator_buffers 2
/*BUFFER 1 SETTINGS*********************************************/
#property indicator_label1 "A"
#property indicator_color1 Red
#property indicator_type1 DRAW_LINE
#property indicator_style1 STYLE_DOT
#property indicator_width1 1
/*BUFFER 2 SETTINGS*********************************************/
#property indicator_label2 "B"
#property indicator_color2 Red
#property indicator_type2 DRAW_LINE
#property indicator_style2 STYLE_DOT
#property indicator_width2 1
/*DECLEARATION BUFFER ARRAYS*********************************************/
double A[];
double B[];

int OnInit()
  {
/*SET INDEX BUFFERS*********************************************/
  if (Period()>=240)
  {
  SetIndexStyle(0, DRAW_NONE);
  SetIndexStyle(1, DRAW_NONE);
  }
  SetIndexBuffer(0,A);
  SetIndexBuffer(1,B);
   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 i , limit , totalbars , countedbars , k;
totalbars=rates_total;
countedbars=prev_calculated;
limit=totalbars-countedbars;
if (limit>=0)
limit--;
for(i=limit;i>=0;i--)
{
k=iBarShift(Symbol(),PERIOD_D1,iTime(Symbol(),Period(),i));
A[i]=iLow(Symbol(),PERIOD_D1,k);
B[i]=iHigh(Symbol(),PERIOD_D1,k);
}

   return(rates_total);
  }
whroeder1
15917
whroeder1  

Ali Mojtabaei:

1)      Add a buffer in histogram type that starts from A and ends by B in each day.

2)     Hide the separate window when the period 4 hours and higher is selected.

#property indicator_label1 "A"
#property indicator_color1 Red
#property indicator_type1 DRAW_LINE
#property indicator_style1 STYLE_DOT
#property indicator_width1 1
/*BUFFER 2 SETTINGS*********************************************/
#property indicator_label2 "B"
#property indicator_color2 Red
#property indicator_type2 DRAW_LINE
:
  SetIndexStyle(0, DRAW_NONE);
  SetIndexStyle(1, DRAW_NONE);
:
k=iBarShift(Symbol(),PERIOD_D1,iTime(Symbol(),Period(),i));
  1. So why haven't you? You didn't change the types. Why are they invisible?
  2. Can't be done!
  3. No need for a function call(s) with iTime(_Symbol,_Period,i) just use the predefined arrays, i.e. Time[i]
Ali Mojtabaei
234
Ali Mojtabaei  
whroeder1:
  1. So why haven't you? You didn't change the types. Why are they invisible?
  2. Can't be done!
  3. No need for a function call(s) with iTime(_Symbol,_Period,i) just use the predefined arrays, i.e. Time[i]


Thanks a lot whroeder1.

I'm in the beginning of the way and so I do many thing by trial and error ( for example the invisible case). I made that invisible to see if the separate window is vanished. 

To add comments, please log in or register