I need help with converting from mql4 to mql5 for fractal indicator
//+------------------------------------------------------------------+ //| Advance Fractal Zones AI.mq5 | MQL5 //| Copyright 2023, Ahmed Ibrahim | //| https://www.mql5.com/en/users/ahmedgouda0 | //+------------------------------------------------------------------+ #property copyright "Copyright 2023, Ahmed Ibrahim" #property link "https://www.mql5.com/en/users/ahmedgouda0" #property version "1.00" #property indicator_chart_window #property indicator_buffers 2 #property indicator_plots 2 #property indicator_label1 "Factal Up" #property indicator_type1 DRAW_ARROW #property indicator_color1 clrRed //--- plot DownFractal #property indicator_label2 "Fractal Down" #property indicator_type2 DRAW_ARROW #property indicator_color2 clrBlue double BufferUpFractal[]; double BufferDownFractal[]; //+------------------------------------------------------------------+ //| Inputs //+------------------------------------------------------------------+ input ENUM_TIMEFRAMES timeframe = PERIOD_H1; //Main Timeframe input int LeftCandle = 5; //Left Candles input int RightCandle = 5; //Right Candles input int fraPoints = 0; //Fractal Distance input double Allowence = 10; //Allowence Points Above/Below Zone input color BuyZoneClr = clrBlue; //Buy Zone Color input color SellZoneClr = clrRed; //Sell Zone Color input string z ="================= Signal =================";//S input bool SignalAlert = true; //Signal Alert input bool MobileNotify = true; //Enable Mobile Notifications input color Uparrowclr = clrBlue; //Up Arrow Color input int UpPoints = 0; //Up Arrow points input color Dnarrowclr = clrRed; //Down Arrow Color input int DnPoints = 0; //Down Arrow points //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,BufferUpFractal,INDICATOR_DATA); SetIndexBuffer(1,BufferDownFractal,INDICATOR_DATA); //--- setting a buffers parameters PlotIndexSetInteger(0,PLOT_ARROW,119); PlotIndexSetInteger(0,PLOT_LINE_WIDTH,4); PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0); PlotIndexSetInteger(1,PLOT_ARROW,119); PlotIndexSetInteger(1,PLOT_LINE_WIDTH,4); PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0); IndicatorSetInteger(INDICATOR_DIGITS,2); //--- return(INIT_SUCCEEDED); } void OnDeinit (const int reason){ //ObjectDelete(0,"Factal Up"); //ObjectDelete(0,"Factal Down"); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { if(prev_calculated<1) { ArrayInitialize(BufferUpFractal,0.0); ArrayInitialize(BufferDownFractal,0.0); } for(int i = iBars(NULL,timeframe) ; i >= 0 ; i--) { int HiLe = iHighest(NULL,PERIOD_CURRENT,MODE_HIGH,LeftCandle,i+1); int HiRe = iHighest(NULL,PERIOD_CURRENT,MODE_HIGH,RightCandle,i-RightCandle); int loLe = iLowest(NULL,PERIOD_CURRENT,MODE_LOW,LeftCandle,i+1); int loRe = iLowest(NULL,PERIOD_CURRENT,MODE_LOW,RightCandle,i-RightCandle); if(iHigh(NULL,timeframe,i)>iHigh(NULL,timeframe,HiLe) && iHigh(NULL,timeframe,i)>iHigh(NULL,timeframe,HiRe) ) BufferUpFractal[i]=iHigh(NULL,timeframe,i)+(fraPoints); if(iLow(NULL,timeframe,i)<iLow(NULL,timeframe,loLe) && iLow(NULL,timeframe,i)<iLow(NULL,timeframe,loRe) ) BufferDownFractal[i]=iLow(NULL,timeframe,i)-(fraPoints); } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+
what is the alternate to
int start() in mql5 ?
Fernando Carreiro #:
It depends on the type of program.
- For Indicators it is OnCalculate()
- For EAs it is OnTick()
- For Scripts it is OnStart()
I want to make a fractal indicator taking it's values from H1 and plot on the current chart .. I did it in mt4 but I can't do it on mt5 both codes are above but the mt5 version is not working
change for loop to start decrementing the loop from
int i = rates_total - 1;
Hello thanks for your time to check my post
I have made an indicator on mql4 called Advanced fractal using int start() function but when I tried to convert the indicator to mql5 It did not work as expected
If you please give a feedback for my work ..MQL4