Display immediatly from OnCalculate (?) - page 2

 
Thierry Ramaniraka:

Thank you, higher than my actual knowledge with class and include.
But i kep it.

Regards.

By now you should know how to use the debugger to step through code you don't well understand in order to see how it works.

 
Mark Watkins:

By now you should know how to use the debugger to step through code you don't well understand in order to see how it works.

Ok I didn't know.
I will give it a try.


 
Emma Schwatson:
Use SetIndexEmptyValue to something like EMPTY_VALUE. Then if you don't want to plot the buffer just set all the elements to EMPTY_VALUE. Example indicator. 

Hi there,
I am trying to make my panel buttons in a subwindow. So far so good...but
When i want to show the moving average, it displays in the subwindow, instead of main chart.



I really try to find a solution...But with no success.
Can someone show the way to do it please ?


 
here is the code provided by Emma Schwatson
I just change the button's subwindow parameter to "1".
#property strict
//#property indicator_chart_window
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot _
#property indicator_label1  "_"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- indicator buffers
double         _Buffer[];

#include <ChartObjects\ChartObjectsTxtControls.mqh>
#include <Indicators\Trend.mqh>

class MyMA : public CiMA
{
   int m_size;
public: 
   MyMA():m_size(0){}
   int size()
   { 
      if(m_size == 0)
         for(;Main(m_size)>0.0; m_size++);
      return m_size;
   }
};

input int InpMaPeriod = 50;

CChartObjectButton button;
MyMA ma;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,_Buffer);
   SetIndexEmptyValue(0,EMPTY_VALUE);
   ArrayInitialize(_Buffer, EMPTY_VALUE);
   ArraySetAsSeries(_Buffer,true);
   
   if(!button.Create(0,"button",1,120,50,120,50) 
      || !button.Description("ToggleMA")
      || !button.Corner(CORNER_RIGHT_LOWER)
   )
      return INIT_FAILED;
      
   if(!ma.Create(_Symbol,(ENUM_TIMEFRAMES)_Period,InpMaPeriod,0,MODE_SMA,PRICE_CLOSE))
      return INIT_FAILED;
      
  
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   if(button.State() && ma.size() > 0)
      _Buffer[0] = ma.Main(0);
   return 0;
}
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{
   if(id==CHARTEVENT_OBJECT_CLICK && sparam==button.Name())
   {
      if(button.State())
         for(int i = fmin(ma.size()-1,3000);i>=0;i--)
            _Buffer[i] = ma.Main(i);
      else
         ArrayInitialize(_Buffer,EMPTY_VALUE);
   }
}
 
Thierry Ramaniraka:
here is the code provided by Emma Schwatson
I just change the button's subwindow parameter to "1".
#property indicator_chart_window
//#property indicator_separate_window
 
Thierry Ramaniraka: Immediatly hide/show Moving Averages after click on button.
But, now, it always waits a tick, as the function is placed in "OnCalculate".

It updates in OnCalculate because that is where the terminal expects buffers and objects to be changed and it calls redraw for you on return.

OnTimer and OnChartEvent do not call ChartRedraw (or WindowRedraw.)

 
Naguisa Unada:

It doesn't work, because if my chart is totally naked, when I drag/drop my indicator, we will not see the button because it will draw in the subwindow1 with is'nt even exist.

I really need to keep 

#property indicator_separate_window

and "force" draw the MAs int he main chart...

Any suggestion ?

 
whroeder1:

It updates in OnCalculate because that is where the terminal expects buffers and objects to be changed and it calls redraw for you on return.

OnTimer and OnChartEvent do not call ChartRedraw (or WindowRedraw.)

I used DRAW NONE to solve it.

 
Since it is necessary to prepare the buffer on the main chart, "#property indicator_chart_window" is required.
A button object can be created in any window, but you can not do it in a window which does not exist.
Reason: