So my question is:
IS there a dependecy between the chart\chart period and the onCalculate method... i.e. is it possible to get PERIOD_D1 bar values from within the onCalculate method even though our curent chart is set to PERIOD_H1 ?
Thanks
Have you used iCustom?
iCustom
The function returns the handle of a specified custom indicator.
int iCustom( string symbol, // symbol name ENUM_TIMEFRAMES period, // period string name // folder/custom indicator_name ... // list of indicator input parameters );
Here's an example use of iCustom from MQL5 reference:
Example: #property indicator_separate_window #property indicator_buffers 1 #property indicator_plots 1 //---- plot Label1 #property indicator_label1 "Label1" #property indicator_type1 DRAW_LINE #property indicator_color1 Red #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- input parameters input int MA_Period=21; input int MA_Shift=0; input ENUM_MA_METHOD MA_Method=MODE_SMA; //--- indicator buffers double Label1Buffer[]; //--- Handle of the Custom Moving Average.mq5 custom indicator int MA_handle; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,Label1Buffer,INDICATOR_DATA); ResetLastError(); MA_handle=iCustom(NULL,0,"Custom Moving Average", MA_Period, MA_Shift, MA_Method, PRICE_CLOSE // using the close prices ); Print("MA_handle = ",MA_handle," error = ",GetLastError()); //--- return(0); } //+------------------------------------------------------------------+ //| 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[]) { //--- Copy the values of the indicator Custom Moving Average to our indicator buffer int copy=CopyBuffer(MA_handle,0,0,rates_total,Label1Buffer); Print("copy = ",copy," rates_total = ",rates_total); //--- If our attempt has failed - Report this if(copy<=0) Print("An attempt to get the values if Custom Moving Average has failed"); //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+
HI,
Yes I have used iCustom. I dont think I have explained the problem well....
If I use iCustom(_Symbol, PERIOD_D1, "INDICATOR"); then this will return a handle on the indicator values for DAYS i.e. one indicator value for one day i.e. one bar will represent one day which will return one indicator value - OK.
Therefore on these terms the last 4 bars will be equal to the last four days - OK.
Now what I want to do is plot these DAY-values on an HOURLY chart.
This is where the problem comes in....
24bars on a hourly chart is equal to one day, so I expect MetaTrader to understand that the indicator value of one DAY bar should be equal to 24bars on an hourly chart.
This is not what happens, rather MetaTrader is unable to understand this and plots for example, 1st DAY bar indicator value onto 1st HOUR bar, 2nd DAY bar indicator value onto 2nd HOUR BAR, 3rd DAY bar indicator value onto 3rd HOUR BAR. This is incorrect.
What I expect to happen is:
0-24 HOURLY BARS should have the 1st DAY indicator Value.
the next...
24-48 HOURLY BARS should have the 2nd DAY indicator Value.
Hope you understand this.
- www.mql5.com
HI,
Yes I have used iCustom. I dont think I have explained the problem well....
If I use iCustom(_Symbol, PERIOD_D1, "INDICATOR"); then this will return a handle on the indicator values for DAYS i.e. one indicator value for one day i.e. one bar will represent one day which will return one indicator value - OK.
Therefore on these terms the last 4 bars will be equal to the last four days - OK.
Now what I want to do is plot these DAY-values on an HOURLY chart.
This is where the problem comes in....
24bars on a hourly chart is equal to one day, so I expect MetaTrader to understand that the indicator value of one DAY bar should be equal to 24bars on an hourly chart.
This is not what happens, rather MetaTrader is unable to understand this and plots for example, 1st DAY bar indicator value onto 1st HOUR bar, 2nd DAY bar indicator value onto 2nd HOUR BAR, 3rd DAY bar indicator value onto 3rd HOUR BAR. This is incorrect.
What I expect to happen is:
0-24 HOURLY BARS should have the 1st DAY indicator Value.
the next...
24-48 HOURLY BARS should have the 2nd DAY indicator Value.
Hope you understand this.
This is already implemented, https://www.mql5.com/en/code/177
- votes: 12
- 2010.08.25
- Armand Kilian | English Russian Spanish Portuguese
- www.mql5.com
I have the same problem in another context, it's a problem with metatrader. If no-one solves the problem here for you, put into google 'Multi timeframe metatrader". It seems to me that some programming has been done in version 4, but I can't find any in version 5.
I have got the same issue with multi timeframe indicator being removed from the chart. If it is created in separate window then it is not removed. So, I can not create and show multi timeframe moving average line on the chart.
I would appreciate an advice from mt5 developers or owner to fix this problem.
I have got the same issue with multi timeframe indicator being removed from the chart. If it is created in separate window then it is not removed. So, I can not create and show multi timeframe moving average line on the chart.
I would appreciate an advice from mt5 developers or owner to fix this problem.
This topic is from 2010.
What problem ? This a technical forum, you need to post all needed information, logs, screenshot and code if you want to report something.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I have a custom indicator, which currently plots onto a chart by using _Period.
What I want to do is have one instance of the indicator calculated on PERIOD_H1 and another instance of the indicator plotted on PERIOD_D1.
I want both indicators to be shown on a 1hour chart. As you would expect the PERIOD_H1 indicators works on the 1hour chart but the PERIOD_D1 indicator does not work on the hour chart.
The idea is that I want the PERIOD_D1 indicator to be a trend filter on a hour chart...?
Any help.
thanks