how can hide the buffer drawing candle in seperate window ?

To add comments, please log in or register
Mehrdad Shiri
4732
Mehrdad Shiri  

HI.

in separate window i draw candle

#property indicator_type1   DRAW_COLOR_CANDLES
#property indicator_color1  clrGray,clrSandyBrown,clrLimeGreen

i want to hide them. i used this:

if(!show_candle) PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_NONE);

but the result is not true . and my result will be false.

can you please help.

Lorentzos Roussos
32168
Lorentzos Roussos  
What are you trying to do ? 

You want the user to be able to switch the separate window display on or off?
Mehrdad Shiri
4732
Mehrdad Shiri  
Lorentzos Roussos:
What are you trying to do ? 

You want the user to be able to switch the separate window display on or off?

not to switch the separate window display on or off.

only want to  on or off the drawing candles drawn by plotting buffer. and keep the other's.

Lorentzos Roussos
32168
Lorentzos Roussos  
Mehrdad Shiri:

not to switch the separate window display on or off.

only want to  on or off the drawing candles drawn by plotting buffer. and keep the other's.

Try this : 


//+------------------------------------------------------------------+
//|                                                 onoff_buffer.mq5 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_plots   2
//--- plot line
#property indicator_label1  "line"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot candles
#property indicator_label2  "candles"
#property indicator_type2   DRAW_CANDLES
#property indicator_color2  clrRed,clrYellow,clrGreen
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- indicator buffers
double         lineBuffer[];
double         candlesBuffer1[];
double         candlesBuffer2[];
double         candlesBuffer3[];
double         candlesBuffer4[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
string system_tag="ITEST_";
bool show_candles=true;
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,lineBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,candlesBuffer1,INDICATOR_DATA);
   SetIndexBuffer(2,candlesBuffer2,INDICATOR_DATA);
   SetIndexBuffer(3,candlesBuffer3,INDICATOR_DATA);
   SetIndexBuffer(4,candlesBuffer4,INDICATOR_DATA);
   //create btn for test 
   ObjectsDeleteAll(0,system_tag);
   show_candles=true;
   string objname=system_tag+"switch";
   bool obji=ObjectCreate(0,objname,OBJ_BUTTON,0,0,0);
   ObjectSetString(0,objname,OBJPROP_TEXT,"Switch");
   ObjectSetInteger(0,objname,OBJPROP_XDISTANCE,20);
   ObjectSetInteger(0,objname,OBJPROP_YDISTANCE,20);
   switch_update(true);
//---
   return(INIT_SUCCEEDED);
  }
  
  void switch_update(bool new_state)
  {
  bool previous_state=show_candles;
  if(new_state==true) 
    {
    ObjectSetInteger(0,system_tag+"switch",OBJPROP_BGCOLOR,clrGreen);
    if(new_state!=previous_state)
      {
      PlotIndexSetInteger(1,PLOT_DRAW_TYPE,DRAW_CANDLES);
      ChartRedraw(0);
      }
    }
  if(new_state==false)
    {
    ObjectSetInteger(0,system_tag+"switch",OBJPROP_BGCOLOR,clrRed);
    if(new_state!=previous_state)
      {
      PlotIndexSetInteger(1,PLOT_DRAW_TYPE,DRAW_NONE);
      ChartRedraw(0);
      }
    }
  show_candles=new_state;
  }
//+------------------------------------------------------------------+
//| 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[])
  {
//---
  //initial run for test 
  if(prev_calculated==0) 
  {
  ArraySetAsSeries(lineBuffer,true);
  ArraySetAsSeries(open,true);
  ArraySetAsSeries(close,true);
  ArraySetAsSeries(high,true);
  ArraySetAsSeries(low,true);
  ArraySetAsSeries(candlesBuffer1,true);
  ArraySetAsSeries(candlesBuffer2,true);
  ArraySetAsSeries(candlesBuffer3,true);
  ArraySetAsSeries(candlesBuffer4,true);
  for(int i=1000;i>=0;i--)
  {
  lineBuffer[i]=(open[i]+close[i]+high[i]+low[i])/4;
  candlesBuffer1[i]=open[i];
  candlesBuffer2[i]=high[i];
  candlesBuffer3[i]=low[i];
  candlesBuffer4[i]=close[i];
  }
  } 
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
   
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---
  if(id==CHARTEVENT_OBJECT_CLICK&&sparam==system_tag+"switch")
    {
    bool iz=show_candles;
    if(iz==false) switch_update(true);
    if(iz==true) switch_update(false);
    }
  }
//+------------------------------------------------------------------+
Files:
Mehrdad Shiri
4732
Mehrdad Shiri  
Lorentzos Roussos:

Try this : 


thank you.

Mehrdad Shiri
4732
Mehrdad Shiri  
Lorentzos Roussos:

Try this : 


seems have problem. can you please run it on M1.



Ernst Van Der Merwe
6370
Ernst Van Der Merwe  
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers 7
#property indicator_plots   2
//--- plot Close
#property indicator_type1  DRAW_COLOR_LINE
#property indicator_color1  clrBlue,clrRed,clrYellow
#property indicator_label1  "Close"
#property indicator_width1  2
#property indicator_color2  clrBlue,clrRed,clrYellow
#property indicator_label2  "Open;High;Low;Close"
//--- input parameters
enum DRAW_TYPE
  {
   _DRAW_CANDLES=DRAW_COLOR_CANDLES,   //Candles
   _DRAW_NONE=DRAW_NONE                //None
  };
input DRAW_TYPE DrawType=_DRAW_CANDLES;
//--- indicator buffers
double         LineBuffer[];
double         LineColorBuffer[];
double         OpenBuffer[];
double         HighBuffer[];
double         LowBuffer[];
double         CloseBuffer[];
double         ColorBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   PlotIndexSetInteger(1,PLOT_DRAW_TYPE,(ENUM_DRAW_TYPE)DrawType);
//--- indicator buffers mapping
   SetIndexBuffer(0,LineBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,LineColorBuffer,INDICATOR_COLOR_INDEX);
   if(DrawType==_DRAW_CANDLES)
     {
      SetIndexBuffer(2,OpenBuffer,INDICATOR_DATA);
      SetIndexBuffer(3,HighBuffer,INDICATOR_DATA);
      SetIndexBuffer(4,LowBuffer,INDICATOR_DATA);
      SetIndexBuffer(5,CloseBuffer,INDICATOR_DATA);
      SetIndexBuffer(6,ColorBuffer,INDICATOR_COLOR_INDEX);
     }
//---
   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 begin=!prev_calculated?1:prev_calculated-1;
   for(int i=begin;i<rates_total&&!_StopFlag;i++)
     {
      LineBuffer[i]=(open[i]+high[i]+low[i]+close[i])/4;
      LineColorBuffer[i]=LineBuffer[i]>LineBuffer[i-1]?0:LineBuffer[i]<LineBuffer[i-1]?1:2;
      if(DrawType==_DRAW_CANDLES)
        {
         OpenBuffer[i]=open[i];
         HighBuffer[i]=high[i];
         LowBuffer[i]=low[i];
         CloseBuffer[i]=close[i];
         ColorBuffer[i]=close[i]>open[i]?0:close[i]<open[i]?1:2;
        }
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
Mehrdad Shiri
4732
Mehrdad Shiri  
Ernst Van Der Merwe:

thank you.

To add comments, please log in or register