You need to read the CopyBuffer help more carefully (note the 'indicator buffer number')
int CopyBuffer( int indicator_handle, // indicator handle int buffer_num, // indicator buffer number int start_pos, // start position int count, // amount to copy double buffer[] // target array to copy );
Now look into your Expert Advisor - you are requesting data everywhere from the indicator buffer '0':
if(CopyBuffer(PLUSVIhandle,0,0,40,_plusvi) < 0) { Print("CopyBufferplusVI error =",GetLastError()); } if(CopyBuffer(MINUSVIhandle,0,0,40,_minusvi) < 0) { Print("CopyBufferminusVI error =",GetLastError()); } if(CopyBuffer(MASIGBUFFERhandle,0,0,40,_plusvimovingaverage) < 0) { Print("CopyBufferMovingaverageonPLUSVIindicator error =",GetLastError()); }
...
Now look at the indicator code: each indicator buffer has its own number:
SetIndexBuffer(0,PlusVI,INDICATOR_DATA); SetIndexBuffer(1,MinusVI,INDICATOR_DATA); SetIndexBuffer(2,MASigBuffer,INDICATOR_DATA);
- www.mql5.com
Thanks Vladimir,
now it works almost perfectly.
I will pay more attention reading the function parameters but I am a newbie of MQL5.
As concerns the EA I have observed that there is a slight difference between the values on the chart of the indicators and the values inside the journal log of the backtester.
Obviously I have looked the same symbol and the values at the same time. The difference is only of 1/100% but anyway there is a difference. Politely could you have an answer to this?
Thanks a lot
Regards
Riccardo
I don’t understand what this is about - you did not provide any information.
I don’t understand what this is about - you did not provide any information.
Thanks Vladimir for your previous answer. It almost has solved my difficulties.
The problem is that I'Ve observed that there is a slight difference between the value read on the indicator chart and the value in the journal log of the backtester.I have checked that the time frame is the same , the symbol is the same, and the input is the same.
Thanks
Kind regards
Thanks Vladimir for your previous answer. It almost has solved my difficulties.
The problem is that I'Ve observed that there is a slight difference between the value read on the indicator chart and the value in the journal log of the backtester .I have checked that the time frame is the same , the symbol is the same, and the input is the same.
Thanks
Kind regards
And again, just a picture and just text. Look at the situation from the other side: how can I read your thoughts? How do I know what you are doing? How can I know where you are clicking with the mouse? In the end, in the picture you did not select anything and did not describe anything.
If you want to hear the exact answer - take the trouble to ask a quality question :)
Here is the corrected code (you only need one handle - you don't need to create three identical handles)
//+------------------------------------------------------------------+ //| SampleMQL5.mq5 | //| Copyright Riccardo | //| | //+------------------------------------------------------------------+ #property copyright "Riccardo" #property link "" #property version "1.00" //--- int handle_iCustom; // variable for storing the handle of the iCustom indicator //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- create handle of the indicator iCustom handle_iCustom=iCustom(Symbol(),PERIOD_H1,"Vortex_modified"); //--- if the handle is not created if(handle_iCustom==INVALID_HANDLE) { //--- tell about the failure and output the error code PrintFormat("Failed to create handle of the iCustom indicator for the symbol %s/%s, error code %d", Symbol(), EnumToString(PERIOD_H1), GetLastError()); //--- the indicator is stopped early return(INIT_FAILED); } //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- release our indicator handles if(handle_iCustom!=INVALID_HANDLE) IndicatorRelease(handle_iCustom); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- dynamic arrays to store indicators values double _plusvi[],_minusvi[],_plusvimovingaverage[]; //--- setting the indexing in arrays the same as in timeseries, i.e. array element with zero //--- index will store the values of the last bar, with 1th index - the last but one, etc. ArraySetAsSeries(_plusvi, true); ArraySetAsSeries(_minusvi, true); ArraySetAsSeries(_plusvimovingaverage, true); //--- using indicators handles, let's copy the values of indicator //--- buffers to arrays, specially prepared for this purpose ResetLastError(); if(CopyBuffer(handle_iCustom,0,0,3,_plusvi) < 0) Print("CopyBufferplusVI error =",GetLastError()); ResetLastError(); if(CopyBuffer(handle_iCustom,1,0,3,_minusvi) < 0) Print("CopyBufferminusVI error =",GetLastError()); ResetLastError(); if(CopyBuffer(handle_iCustom,2,0,3,_plusvimovingaverage) < 0) Print("CopyBufferMovingaverageonPLUSVIindicator error =",GetLastError()); Comment("PlusVI[1] = ",DoubleToString(_plusvi[1],Digits()),", PlusVI[0] = ",DoubleToString(_plusvi[0],Digits()),"\n", "MinusVI[1] = ",DoubleToString(_minusvi[1],Digits()),", MinusVI[0] = ",DoubleToString(_minusvi[0],Digits()),"\n", "MASigBuffer[1] = ",DoubleToString(_plusvimovingaverage[1],Digits()),", MASigBuffer[0] = ",DoubleToString(_plusvimovingaverage[0],Digits())); } //+------------------------------------------------------------------+
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Good morning,
I have used an indicator I have found on MQL5 (The Vortex indicator (VI+ and VI-) with moving average on the VI+ curve).
Now I am trying to build an EA using this indicator and I've used the ICustom function to create the handle in the expert advisor.
Unfortunately when I backtest the EA in the strategy tester the values that I read inside the backtest journal of the VI- (MinusVI) are completely wrong.
The problem is inside the indicator or inside the EA?
Here the code of the EA:
And here the code of the Vortex Indicator modified :