progress chukwu:
Please help me correct this code error on line 59.
Here is the code in the attachment.
The error is 'WPR_Period' - cannot convert enum
Please post your code properly. Use the >code-button<
Your usage of indicators is wrong. You need to create the indicator once in OnInit. You get a handle, use the handle with CopyBuffer to get the data.
Your parameters are wrong, you place the cursor on the function name and then press F1 to open the documentation.
+------------------------------------------------------------------+ //| CrossIndicator.mq5 | //| Copyright 2023, OpenAI. All rights reserved. | //| https://www.openai.com/ | //+------------------------------------------------------------------+ #property indicator_chart_window #property indicator_buffers 2 #property indicator_color1 Blue #property indicator_color2 Red // Input parameters input int CCI_Period = 14; input int WPR_Period = 14; // Indicator buffers double CCI_Buffer[]; double WPR_Buffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { // Set indicator buffers SetIndexBuffer(0, CCI_Buffer); SetIndexBuffer(1, WPR_Buffer); // Set indicator labels IndicatorSetString(INDICATOR_SHORTNAME, "CCI-WPR Cross"); return INIT_SUCCEEDED; } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double &price[]) { int limit = rates_total - prev_calculated; // Check if enough bars are available for both indicators int bars_required = MathMax(CCI_Period, WPR_Period); if (prev_calculated == 0) bars_required += 1; if (bars_required > rates_total) return 0; // Not enough bars, wait for more data // Calculate CCI values for (int i = limit; i >= 0; i--) { CCI_Buffer[i] = iCCI(Symbol(), 0, CCI_Period, i); WPR_Buffer[i] = iWPR(Symbol(), WPR_Period, i); // Check for indicator cross if (i > 0) { if (CCI_Buffer[i] > WPR_Buffer[i] && CCI_Buffer[i - 1] <= WPR_Buffer[i - 1]) Alert("CCI-WPR cross detected: UP"); if (CCI_Buffer[i] < WPR_Buffer[i] && CCI_Buffer[i - 1] >= WPR_Buffer[i - 1]) Alert("CCI-WPR cross detected: DOWN"); } } return rates_total; }
Dominik Christian Egert #:
Please post your code properly. Use the >code-button<
Your usage of indicators is wrong. You need to create the indicator once in OnInit. You get a handle, use the handle with CopyBuffer to get the data.
Your parameters are wrong, you place the cursor on the function name and then press F1 to open the documentation.
This
iWPR(Symbol(), WPR_Period, i);
Should be
iWPR(Symbol(), 0, WPR_Period, i);
You are right, I supposed it to be MQL4 but it is MQL5...
So @progress chukwu as you can see in a lot of free code around here, on MQL5 you need to declare and assign indicator handles into OnInit, and CopyBuffers into OnTick/OnCalculate.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Please help me correct this code error on line 59.
Here is the code in the attachment.
The error is 'WPR_Period' - cannot convert enum