-
CopyHigh(_Symbol,_Period,i,3,highBuffer); CopyLow(_Symbol,_Period,i,3,lowBuffer); CopyOpen(_Symbol,_Period,i,3,openBuffer); CopyClose(_Symbol,_Period,i,3,closeBuffer);
You ask for three items.
-
bool up_condition1 = (openBuffer[2]>closeBuffer[2]) && …
You read three items. -
if(prev_calculated ==0) limit = rates_total; else limit = rates_total - prev_calculated; for(int i=1 ; i < limit; i++)
But, the first run prev_calculated is zero, so limit is Bars, and when i=Bars-1, there aren't three items to read. Your lookback is two.
How to do your lookbacks correctly.
William Roeder:
Thanks William, I resolved the error. Added a int lookback and made the following changes to the code
- You ask for three items.
- You read three items.
- But, the first run prev_calculated is zero, so limit is Bars, and when i=Bars-1, there aren't three
items to read. Your lookback is two.
How to do your lookbacks correctly.
if(prev_calculated ==0) limit = rates_total-lookback+1; else limit = rates_total - prev_calculated; for(int i=1 ; i < limit; i++)It is working fine now.
Any other suggestions on how to make this code more efficient?
Good day MQL5 team I believe has the CCanndlePattern Class some where in the code base
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
I am pretty new to the MQL5 platform. I built a custom indicator to identify Hammer and shooting star patterns on the chart. The indicator buffer at a particular index is filled with 1.0 after a hammer appears and -1.0 after shooting star appears. Everything seemed to be working fine when I dropped the indicator on the chart. The next step was to create an EA which loads this indicator and places buy or sell order based on the value in the indicator buffer, i.e 1.0 for buy order and -1.0 for sell order. I'm facing an issue while backtesting that EA.
This is the error I face:
2019.09.06 09:25:01.918 Core 1 2019.06.01 00:00:00 array out of range in 'Hammer.mq5' (92,42)
Also any feedback on the code would be appreciated since I'm new to this and want to learn how to code things in an efficient way.
The following is the code for the Hammer pattern:
The following is the code for EA which loads this indicator: