-
Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
Next time, post in the correct place. The moderators will likely move this thread there soon. -
There is no high or close. There is a predefined High[] and Close[] arrays. Perhaps you should read the manual.
Hello guys, Can someone help me to convert a litle Code from pine script to MQL4 ?
Hello . I assumed your ema1 and ema2 are the same ema of highs and lows . If otherwise you can adjust it in the settings.
Cheers
#property strict #property indicator_separate_window #property indicator_maximum 1.1 #property indicator_minimum -1.1 #property indicator_buffers 1 #property indicator_plots 1 //--- plot H1v1 #property indicator_label1 "H1v1" #property indicator_type1 DRAW_LINE #property indicator_color1 clrRed #property indicator_style1 STYLE_SOLID #property indicator_width1 1 input bool wicks=false;//wicks input int ema1_period=7;//EMA1 period input int ema1_price=PRICE_HIGH;//EMA1 Prices used input int ema2_period=7;//EMA2 period input int ema2_price=PRICE_LOW;//EMA2 Prices used //--- indicator buffers double H1v1Buffer[]; int deflekt=0; int OnInit() { SetIndexBuffer(0,H1v1Buffer); deflekt=(int)MathMax(ema1_period,ema2_period); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| 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[]) { //--- int to_calc=rates_total-prev_calculated; if(to_calc==rates_total){ to_calc=rates_total-2-deflekt; } for(int i=to_calc;i>=0;i--) { //ema1 double ema1=iMA(_Symbol,_Period,ema1_period,0,MODE_EMA,ema1_price,i); //ema2 double ema2=iMA(_Symbol,_Period,ema2_period,0,MODE_EMA,ema2_price,i); //Hlv1 := (wicks ? high : close) > EMA1 ? 1 : (wicks ? low : close) < EMA2 ? -1 : Hlv1[1] double p1=wicks?High[i]:Close[i]; double p2=wicks?Low[i]:Close[i]; double h1v1=p1>ema1?1.00:(p2<ema2?-1.00:H1v1Buffer[i+1]); H1v1Buffer[i]=h1v1; } //--- return value of prev_calculated for next call return(rates_total); }
Hello . I assumed your ema1 and ema2 are the same ema of highs and lows . If otherwise you can adjust it in the settings.
Cheers
Thank you , you are best,I changed the indicator a little , I want to call the buffer in Expert with icustom , but 2147483647 or blank value received from up and down bufer... why ? can you help me..
I always get help from you, you are very generous#property copyright "Copyright 2095, Galactic Outreach Division Corps." #property link "https://www.mql5.com" #property version "1.00" #property strict #property indicator_chart_window #property indicator_buffers 5 #property indicator_plots 5 //--- plot up //--- plot up #property indicator_label1 "up_line" #property indicator_type1 DRAW_LINE #property indicator_color1 clrRoyalBlue #property indicator_style1 STYLE_SOLID #property indicator_width1 2 //--- plot down #property indicator_label2 "Down_line" #property indicator_type2 DRAW_LINE #property indicator_color2 clrCrimson #property indicator_style2 STYLE_SOLID #property indicator_width2 2 #property indicator_label3 "Up" #property indicator_type3 DRAW_ARROW #property indicator_color3 clrRoyalBlue #property indicator_width3 2 //--- plot down #property indicator_label4 "Down" #property indicator_type4 DRAW_ARROW #property indicator_color4 clrCrimson #property indicator_width4 2 input bool wicks=false;//wicks extern string lchannel_setting=" '''''''''''''' LOW MA Settings ''''''''''''''''"; extern int low_period =20; extern int low_shift =0; extern ENUM_MA_METHOD low_method=MODE_SMA; extern ENUM_APPLIED_PRICE low_APPLIEDP=PRICE_LOW; extern string hchannel_setting=" '''''''''''''' High MA Settings ''''''''''''''''"; extern int high_period =20; extern int high_shift =0; extern ENUM_MA_METHOD high_method=MODE_SMA; extern ENUM_APPLIED_PRICE high_APPLIEDP=PRICE_HIGH; //--- input parameters input int breath_room=200;//breathing room in points double H1v1Buffer[]; double lowEMA_1[],highEMA_1[]; double down[],up[]; int deflekt=0; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping //--- indicator buffers mapping //SetIndexEmptyValue(0,0.0);//so that 0.0 draws nothing // SetIndexEmptyValue(1,0.0); SetIndexBuffer(0,lowEMA_1); SetIndexBuffer(1,highEMA_1); SetIndexBuffer(2,up); SetIndexArrow(2,217); SetIndexBuffer(3,down); SetIndexArrow(3,218); SetIndexBuffer(4,H1v1Buffer); deflekt=(int)MathMax(high_period,low_period); //--- //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| 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[]) { //--- int to_calc=rates_total-prev_calculated; if(to_calc==rates_total){ to_calc=rates_total-2-deflekt; } for(int i=to_calc;i>=0;i--) { double lowEMA_11=iMA(_Symbol,PERIOD_CURRENT,low_period,low_shift,low_method,low_APPLIEDP,i); double highEMA_11=iMA(_Symbol,PERIOD_CURRENT,high_period,high_shift,high_method,high_APPLIEDP,i); lowEMA_1[i]=lowEMA_11; highEMA_1[i]=highEMA_11; double p1=wicks?High[i]:Close[i]; double p2=wicks?Low[i]:Close[i]; double h1v1=p1>highEMA_11?1.00:(p2<lowEMA_11?-1.00:H1v1Buffer[i+1]); H1v1Buffer[i]=h1v1; if(H1v1Buffer[i]==1&&H1v1Buffer[i+1]==-1){ up[i]=Low[i]-((double)breath_room)*_Point; } else if(H1v1Buffer[i]==-1&&H1v1Buffer[i+1]==1){ down[i]=High[i]+((double)breath_room)*_Point; } } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+
Thank you , you are best,I changed the indicator a little , I want to call the buffer in Expert with icustom , but 2147483647 or blank value received from up and down bufer... why ? can you help me..
I always get help from you, you are very generous
You need to be resetting the up and down buffers once you enter the bar calculation , i can't see anything else wrong .
for(int i=to_calc;i>=0;i--) { up[i]=0.0; down[i]=0.0;
You need to be resetting the up and down buffers once you enter the bar calculation , i can't see anything else wrong .
i do that but Nothing changed in the expert, indicator alone works properly and there are no problems but i cant call up and down in expert
its expert code i use icustom to call buffer its true ?
void CheckForSignal() { static datetime candleTime=0; if(candleTime != iTime(_Symbol,timeframe,0)) { double buyy = iCustom(_Symbol,PERIOD_CURRENT,"names",2,1); double selll = iCustom(_Symbol,PERIOD_CURRENT,"names",3,1); Print("iCustom HANDLE "+buyy+" ERR? "+GetLastError()); Comment( "second line\n"+buyy, "\n"+ "third line\n"+selll); if(buyy !=0) EnterTrade(OP_BUY); else if(selll !=0) EnterTrade(OP_SELL); candleTime=iTime(_Symbol,timeframe,0); } }
i do that but Nothing changed in the expert, indicator alone works properly and there are no problems but i cant call up and down in expert
its expert code i use icustom to call buffer its true ?
Hmm , add these in the indicator oninit too maybe : (i'm sorry my focus is elsewhere)
ArrayFill(up,0,ArraySize(up),0.0); ArrayFill(down,0,ArraySize(down),0.0);

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello guys, Can someone help me to convert a litle Code from pine script to MQL4 ?