This article contains the detailed knowledge.
Thanks.
Hi,
This article is really interesting and open new opportunities to manage indicators.
Since I'm a beginner in MQL5, I've tried to implement the possibility to apply an indicator to another. I've written a little code which only duplicate
an adaptative moving average hoping to use it on any indicator of the chart.
Unfortunately, in the list of parameters which appears when you launch the indicator I don't have the case "apply to : previuos indicator's data".
How the code should be organised to have the possibility to apply it to another indicator ?
Here is my code:
#property indicator_separate_window #property indicator_minimum 1.3 #property indicator_maximum 1.35 //#property indicator_chart_window #property indicator_buffers 2 #property indicator_plots 1 //--- plot dMA #property indicator_label1 "dAMA" #property indicator_type1 DRAW_LINE #property indicator_color1 Red #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- input parameters input int AMAPeriod=9; input int FastEMA=2; input int SlowEMA=20; //--- indicator buffers double AMABuffer[]; double dAMABuffer[]; int h_dAMA; int h_AMA; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,dAMABuffer,INDICATOR_DATA); SetIndexBuffer(1,AMABuffer,INDICATOR_CALCULATIONS); //PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,MAPeriod+1); h_AMA=iAMA(_Symbol,PERIOD_CURRENT,AMAPeriod,FastEMA,SlowEMA,0,PRICE_CLOSE); if(h_AMA == INVALID_HANDLE) { Print("AMA indicator initialization error, Code = ", GetLastError()); return(-1); } ArraySetAsSeries(AMABuffer,true); ArraySetAsSeries(dAMABuffer,true); PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,MathMax(AMAPeriod,SlowEMA)); //--- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, // size of the price[] array const int prev_calculated,// number of bars processed at the previous call const int begin, // where the significant data start from const double &price[] // array for calculation ) { if(BarsCalculated(h_AMA)<rates_total) return(0); //--- we can copy not all data int to_copy; if(prev_calculated>rates_total || prev_calculated<=0) { to_copy=rates_total; if(CopyBuffer(h_AMA,0,0,to_copy,AMABuffer)<=0) return(0); for (int i=0;i<to_copy-MathMax(AMAPeriod,SlowEMA);i++) { dAMABuffer[i]=AMABuffer[i]; } } else { to_copy=rates_total-prev_calculated+MathMax(AMAPeriod,SlowEMA)-1; //--- last value is always copied to_copy++; if(CopyBuffer(h_AMA,0,0,to_copy,AMABuffer)<=0) return(0); for (int i=0;i<to_copy;i++) { dAMABuffer[i]=AMABuffer[i]; } } //--- try to copy Print(dAMABuffer[0]); //to see if we go till the end //--- return value of prev_calculated for next call //--- //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+
Hi,
I've understood the problem: you are only able to apply one indicator to another which is in the same window.
Do you have an idea on how to apply one indicator (and to display it in a separate window) to another which is in the main window?
thanks
Bests
Hi,
This is a very good article but I have some questions.
1. Only the indicators that uses the short form of the OnCalculate() function call, can be applaied to another indicator or the indicators that use the long form of the OnCalculate() function call can be applied too? If so , haw can be applied one indicator with long form of the OnCalculate() function call, to another indicator???
2. Applying one indicator to another (TSI over RSI) generates some display problems (see attached image). While RSI is plotted from 0 to 100 the second indicator (TSI) have values below 0 too , values wich are not visibile on the chart. Wich is the problem and why the chart don't properly adjust to display correctly both indicators. Can we solve this problem or it's a MetaTrader bug???
Hi,
This is a very good article but I have some questions.
1. Only the indicators that uses the short form of the OnCalculate() function call, can be applaied to another indicator or the indicators that use the long form of the OnCalculate() function call can be applied too? If so , haw can be applied one indicator with long form of the OnCalculate() function call, to another indicator???
2. Applying one indicator to another (TSI over RSI) generates some display problems (see attached image). While RSI is plotted from 0 to 100 the second indicator (TSI) have values below 0 too , values wich are not visibile on the chart. Wich is the problem and why the chart don't properly adjust to display correctly both indicators. Can we solve this problem or it's a MetaTrader bug???
1. Yes only indicator that uses the short form of OnCalculate can be applied to another indicator data.
2. You have to edit to properties of RSI indicator and change "Fixed minimum" on the Scale tab to -50 instead of 0.
Hi,
Using a simple chart, I can drag Indicator A on a sub window. Indicator B can be dragged into Indicator A and "Apply To" can be "Previous Indicator Data".
Both Indicator A and B are Custom Indicators.
When trying to Code EA, if using a standard MA for indicator B, you can pass the indicator handle in Applied Price. However, for Custom Indicators, the method is to pass it as the last parameter for the creation of Indicator B.
1. What are the things to look out for in Indicator B to know if it will accept the assignment of an indicator handle as the data series to process on?
2. In the EA, if Indicator B continues to open in main window and attaches to Price Close, what can i check?
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
New article Applying One Indicator to Another is published:
Do you want to improve an indicator for its correct application to the other indicator's data? In this article we'll review all the steps required for such modification.
Author: MetaQuotes