hi,
someone should kindly help me get the last 20 lower and upper fractal handles . i have sample code below which compiles but i 'm unable to get the indicator handles to and array that gives me the low or high of the nth candle on which the fractal form. thank you
1. You are making a gross mistake: you create an indicator handle at every tick! REMEMBER: The MQL5 style implies that the indicator handle is created ONCE and must be done in OnInit.
2. An example of how to work with Fractals:
Forum on trading, automated trading systems and testing trading strategies
Vladimir Karputov, 2021.06.05 06:59
Yes, Fractals can contain '0.0' or 'EMPTY_VALUE'. Example:
Code: 'iFractals.mq5'
//+------------------------------------------------------------------+ //| iFractals.mq5 | //| Copyright © 2021, Vladimir Karputov | //+------------------------------------------------------------------+ #property copyright "Copyright © 2021, Vladimir Karputov" #property version "1.000" //--- input parameters input int InputBars=9; //--- int handle_iFractals; // variable for storing the handle of the iFractals indicator bool m_init_error = false; // error on InInit //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- forced initialization of variables m_init_error = false; // error on InInit //--- create handle of the indicator iFractals handle_iFractals=iFractals(Symbol(),Period()); //--- if the handle is not created if(handle_iFractals==INVALID_HANDLE) { //--- tell about the failure and output the error code PrintFormat("Failed to create handle of the iFractals indicator for the symbol %s/%s, error code %d", Symbol(), EnumToString(Period()), GetLastError()); //--- the indicator is stopped early m_init_error=true; return(INIT_SUCCEEDED); } //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { if(m_init_error) return; //--- double upper[],lower[]; ArraySetAsSeries(upper,true); ArraySetAsSeries(lower,true); int start_pos=0,count=6; if(!iGetArray(handle_iFractals,UPPER_LINE,start_pos,count,upper) || !iGetArray(handle_iFractals,LOWER_LINE,start_pos,count,lower)) return; //--- string text=""; for(int i=0; i<count; i++) { //--- string text_upper=""; if(upper[i]==0.0 || upper[i]==EMPTY_VALUE) text_upper=""; else text_upper=DoubleToString(upper[i],Digits()); //--- string text_lower=""; if(lower[i]==0.0 || lower[i]==EMPTY_VALUE) text_lower=""; else text_lower=DoubleToString(lower[i],Digits()); //--- text=text+IntegerToString(i)+"#: "+"Upper "+text_upper+", Lower "+text_lower+"\n"; } Comment(text); } //+------------------------------------------------------------------+ //| Get value of buffers | //+------------------------------------------------------------------+ bool iGetArray(const int handle,const int buffer,const int start_pos, const int count,double &arr_buffer[]) { bool result=true; if(!ArrayIsDynamic(arr_buffer)) { PrintFormat("ERROR! EA: %s, FUNCTION: %s, this a no dynamic array!",__FILE__,__FUNCTION__); return(false); } ArrayFree(arr_buffer); //--- reset error code ResetLastError(); //--- fill a part of the iBands array with values from the indicator buffer int copied=CopyBuffer(handle,buffer,start_pos,count,arr_buffer); if(copied!=count) { //--- if the copying fails, tell the error code PrintFormat("ERROR! EA: %s, FUNCTION: %s, amount to copy: %d, copied: %d, error code %d", __FILE__,__FUNCTION__,count,copied,GetLastError()); //--- quit with zero result - it means that the indicator is considered as not calculated return(false); } return(result); } //+------------------------------------------------------------------+
Result:
(Follow the link - at the bottom of the message there is a code 'iFractals.mq5')
1. You are making a gross mistake: you create an indicator handle at every tick! REMEMBER: The MQL5 style implies that the indicator handle is created ONCE and must be done in OnInit.
2. An example of how to work with Fractals:
(Follow the link - at the bottom of the message there is a code 'iFractals.mq5')
1. You are making a gross mistake: you create an indicator handle at every tick! REMEMBER: The MQL5 style implies that the indicator handle is created ONCE and must be done in OnInit.
2. An example of how to work with Fractals:
(Follow the link - at the bottom of the message there is a code 'iFractals.mq5')
//CODE IN MQL4 //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnStart() { double arrUp[20],arrDn[20],val=0; int count = 0; int i = 0; datetime foundUp = 0; datetime foundDn = 0; for(i=0; i<Bars; i++) { val = iFractals(NULL,0,MODE_UPPER,i); if(val!=0) { arrUp[count] = val; if(count==0) foundUp = Time[i]; count++; if(count==20) break; } } count = 0; for(i=0; i<Bars; i++) { val = iFractals(NULL,0,MODE_LOWER,i); if(val!=0) { arrDn[count] = val; if(count==0) foundDn = Time[i]; count++; if(count==20) break; } } Alert(arrDn[1]); } // how i've done it in mql5. it compiles but alert doesnt work //+------------------------------------------------------------------+ //| iFractals.mq5 | //| Copyright © 2021, Vladimir Karputov | //+------------------------------------------------------------------+ #property copyright "Copyright © 2021, Vladimir Karputov" #property version "1.000" //--- input parameters //--- int handle_iFractals; // variable for storing the handle of the iFractals indicator bool m_init_error = false; // error on InInit //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnStart() { datetime fup=0,fdn=0; //--- forced initialization of variables m_init_error = false; // error on InInit //--- create handle of the indicator iFractals handle_iFractals=iFractals(Symbol(),Period()); //--- if the handle is not created if(handle_iFractals==INVALID_HANDLE) { //--- tell about the failure and output the error code PrintFormat("Failed to create handle of the iFractals indicator for the symbol %s/%s, error code %d", Symbol(), EnumToString(Period()), GetLastError()); //--- the indicator is stopped early m_init_error=true; return(INIT_SUCCEEDED); } //--- return(INIT_SUCCEEDED); //--- double upper[],lower[]; ArraySetAsSeries(upper,true); ArraySetAsSeries(lower,true); int start_pos=0,count=6, val=0; //--- for(int i=0; i<count; i++) { val=CopyBuffer(handle_iFractals,UPPER_LINE,start_pos,count,upper); if(val!=0) { upper[count]=val; if(count==0) fup= i; count++; if(count==20) break; } } for(int i=0; i<count; i++) { val=CopyBuffer(handle_iFractals,LOWER_LINE,start_pos,count,lower); if(val!=0) { lower[count]=val; if(count==0) fdn= i; count++; if(count==20) break; } } Alert(lower[4]); } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+

Here is a forum for MQL5. Please attach your MQL5 file (you can attach using the butto
Please i have attached files for both mql4 and mql5 . the mql4 versions works fine you can use that to better understand what i want to do. thank you
Please i have attached files for both mql4 and mql5 . the mql4 versions works fine you can use that to better understand what i want to do. thank you
Your MQL5 file won't compile. Please correct the errors.
Add: This should be an ADVISOR, not a SCRIPT.
Add add: example in #1

- 2021.09.15
- www.mql5.com
this one compiled
Forum on trading, automated trading systems and testing trading strategies
help with indicator handler array
Vladimir Karputov, 2021.09.16 05:45
***
Add: This should be an ADVISOR, not a SCRIPT.
Add add: example in #1

- 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,
someone should kindly help me get the last 20 lower and upper fractal handles . i have sample code below which compiles but i 'm unable to get the indicator handles to and array that gives me the low or high of the nth candle on which the fractal form. thank you