- www.mql5.com
Hi everyone,
I noticed a strange behavior. The documentation states that when a custom indicator uses the simplified version of the OnCalculate function, the built-in variable _AppliedTo is set to the price series selected in the "Parameters" tab of the dialog box that is displayed when the indicator is added, and when the indicator uses the complicated version of the OnCalculate function, _AppliedTo is set to zero.
So, within OnInit, I ask the code to print the value of _AppliedTo, both as a string with the EnumToString function and as an integer. I realized that if the "Parameters" tab is not selected upon addition (to see which price series is selected), _AppliedTo is set to zero according to the output even though the documentation states otherwise. But when the "Parameters" tab is selected (without actually touching the combo box), the _AppliedTo is set correctly. The capture of the log is attached to the message.
Beside that, it seems that the indicators are created correctly with the _AppliedTo variable set to zero. So, for instance, the iMA function succeeds with the last parameter (applied_price of type ENUM_APPLIED_PRICE) set to zero. The EnumToString output seems to indicate that zero does not belong to the ENUM_APPLIED_PRICE enumeration.
Thank you.
Hi everyone,
I noticed a strange behavior. The documentation states that when a custom indicator uses the simplified version of the OnCalculate function, the built-in variable _AppliedTo is set to the price series selected in the "Parameters" tab of the dialog box that is displayed when the indicator is added, and when the indicator uses the complicated version of the OnCalculate function, _AppliedTo is set to zero.
So, within OnInit, I ask the code to print the value of _AppliedTo, both as a string with the EnumToString function and as an integer. I realized that if the "Parameters" tab is not selected upon addition (to see which price series is selected), _AppliedTo is set to zero according to the output even though the documentation states otherwise. But when the "Parameters" tab is selected (without actually touching the combo box), the _AppliedTo is set correctly. The capture of the log is attached to the message.
Beside that, it seems that the indicators are created correctly with the _AppliedTo variable set to zero. So, for instance, the iMA function succeeds with the last parameter (applied_price of type ENUM_APPLIED_PRICE) set to zero. The EnumToString output seems to indicate that zero does not belong to the ENUM_APPLIED_PRICE enumeration.
0 is correct as nothing is selected, so the default is used : Close prices. It doesn't, _AppliedTo return an int, not an enum, not the value of ENUM_APPLIED_PRICE.
That is readily apparent in the _AppliedTo predefined variable documention:
//+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,Label1Buffer,INDICATOR_DATA); // Getting the type of data used for indicator calculation Print("_AppliedTo=",_AppliedTo); Print(getIndicatorDataDescription(_AppliedTo)); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Description of data used for indicator calculation | //+------------------------------------------------------------------+ string getIndicatorDataDescription(int data_id) { string descr=""; switch(data_id) { case(0):descr="It's first type of OnCalculate() - no data buffer"; break; case(1):descr="Indicator calculates on Close price"; break; case(2):descr="Indicator calculates on Open price"; break; case(3):descr="Indicator calculates on High price"; break; case(4):descr="Indicator calculates on Low price"; break; case(5):descr="Indicator calculates on Median Price (HL/2)"; break; case(6):descr="Indicator calculates on Typical Price (HLC/3)"; break; case(7):descr="Indicator calculates on Weighted Price (HLCC/4)"; break; case(8):descr="Indicator calculates Previous Indicator's data"; break; case(9):descr="Indicator calculates on First Indicator's data"; break; default: descr="Indicator calculates on data of indicator with handle="+string(data_id); break; } //--- return descr; }
- www.mql5.com
- 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 everyone,
I have a problem. If I use the simplified version of OnCalculate, I receive the price series as an array of doubles in the OnCalculate parameters. This is the price series selected by the user in the "Parameters" tab of the dialog box displayed when the indicator is added to the chart. But in this case I don't know, in the OnInit function, how to figure out what price series the user selected when the indicator was added to the chart. I need this information because I must create handles to technical indicators using that same price series (ENUM_APPLIED_PRICE constant).
Thanks.
PS: by the way, the Price Constants documentation page look flawed to me because the example code creates a handle to the RSI indicator using explicitly the PRICE_CLOSE constant, regardless of what price series the user may have chosen (the simplified version of OnCalculate is used). So, if the user chose the open prices, the code will use close prices. The terminal will not display the indicator the user expects.