Download MetaTrader 5

Display immediatly from OnCalculate (?)

To add comments, please log in or register
Thierry Ramaniraka
339
Thierry Ramaniraka  
Hello,
Here is my goal :
Immediatly hide/show Moving Averages after click on button.
But, now, it always waits a tick, as the function is placed in "OnCalculate".

How can I do it please ?
Here is my code :
int OnInit()
{ 
   TLR_Moving_Averages_Settings();
   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[])
{
        // Display the Moving averages, but only after tick...
        // I need it to show immediatly after click on button.
        TLR_Display_Moving_Averages(rates_total,prev_calculated);
        
   return(rates_total);
}

//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{
   // I guess i need it to be placed here but :
   
   // Do not works because of obvious false parameters
   TLR_Display_Moving_Averages(rates_total,prev_calculated);
   
   // Do not works because of wrong parameters
   TLR_Display_Moving_Averages();
Any idea / solution ?

Regards.
Naguisa Unada
219
Naguisa Unada  

You can turn on and off instantaneously by switching colors.

I uploaded a sample to refer it.

Attention: 

Do not open a new thread each time you ask questions. You should continue to use the same thread.

Files:
Sample_4.mq4 11 kb
Thierry Ramaniraka
339
Thierry Ramaniraka  
Naguisa Unada:

Attention: 

Do not open a new thread each time you ask questions. You should continue to use the same thread.

ah, ok.
I tought i have because the subject was not the same. Thank you.

Naguisa Unada:

You can turn on and off instantaneously by switching colors.

I uploaded a sample to refer it.

Yes, smart idea...I didn't tought about it.
I prefere true "hide/show", but if i think i will do it like your suggestion.

Thank you.

EDIT : You really liked the button code provided ! :)
Thierry Ramaniraka
339
Thierry Ramaniraka  
Naguisa Unada:

You can turn on and off instantaneously by switching colors.

I uploaded a sample to refer it.

Attention: 

Do not open a new thread each time you ask questions. You should continue to use the same thread.

The probleme with your smart/fast suggestion is that technically, the moving averages are still on the graph and are detectabled on "Mouse Over".
Even if we cannot see them.
Can we to the indicateur undetectable on the graph by "Mouse Over" ?

If you have another idea to realy hide/show on click...
-------

PS : And another question please, is there a way to hide the color buffers options in the indicator pop up window ?

Naguisa Unada
219
Naguisa Unada  

If you display moving averages as objects instead of using buffers, you should be able to achieve these purpose.

Thierry Ramaniraka
339
Thierry Ramaniraka  
Naguisa Unada:

If you display moving averages as objects instead of using buffers, you should be able to achieve these purpose.

ah ok...Thank you Veeery much :)

Thierry Ramaniraka
339
Thierry Ramaniraka  
Naguisa Unada:

If you display moving averages as objects instead of using buffers, you should be able to achieve these purpose.

Have you, an good example to do it please....?

Naguisa Unada
219
Naguisa Unada  

I have ever seen a program created by other before, but I have never programmed it myself.

I think that it is not difficult because it only draws lines.

Thierry Ramaniraka
339
Thierry Ramaniraka  

It's always a buffer question ... :/
https://www.mql5.com/en/docs/customind/indicators_examples/draw_line
Maybe i will do it your way to not uselessly waste time.


Thank you again.

Documentation on MQL5: Custom Indicators / Indicator Styles in Examples / DRAW_LINE
Documentation on MQL5: Custom Indicators / Indicator Styles in Examples / DRAW_LINE
  • www.mql5.com
//|                                                    DRAW_LINE.mq5 | //|                        Copyright 2011, MetaQuotes Software Corp. | //|                                              https://www.mql5.com | //| Custom indicator initialization function                         |...
Emma Schwatson
1638
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. 
#property strict
#property indicator_chart_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",0,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
339
Thierry Ramaniraka  
Mark Watkins:
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. 

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

Regards.

12
To add comments, please log in or register