- Is anything wrong with this snippet of code
- Questions about MQL4
- Expert advisors
It is MQL5
Are you sure?
double Maxima_Candle[]; CopyHigh(Symbol(),TimeFrame2,1,Shift2,Maxima_Candle); int position_max=ArrayMaximum(Maxima_Candle); double CL= Maxima_Candle[position_max]; double Minima_Candle[]; CopyLow(Symbol(),TimeFrame2,1,Shift2,Minima_Candle); int position_min=ArrayMinimum(Minima_Candle); double CL1= Minima_Candle[position_min]; double CL2= arrayiClose2[Shift5]; if((Ask>CL+PipsBO*_Point)&&(Ask>CL2+PipsBO*_Point)) { OrderSend(Symbol(),OP_BUY,Lot(),Ask,Slip,slb,0,CommentBuy,Magic,0,Blue); } else if((Bid<CL1-PipsBO*_Point)&&(Bid<CL2-PipsBO*_Point)) { OrderSend(Symbol(),OP_SELL,Lot(),Bid,Slip,sls,0,CommentSell,Magic,0,Red); }
Definitely looks like MQL4 to me.
Are you sure?
Definitely looks like MQL4 to me.
Sure. That could be the problem. I have asked for a translation from MQL4 to MQL5 and I have been adding features afterwards. I had learnt MQL4 so I could be missing the MQL5 logic.
What would look more like MQL5? Where am I erring?
Sure. That could be the problem. I have asked for a translation from MQL4 to MQL5 and I have been adding features afterwards. I had learnt MQL4 so I could be missing the MQL5 logic.
What would look more like MQL5? Where am I erring?
You showed the old code. Please don't try to put old code in the main section. There is ONE special section for old code.
You showed the old code. Please don't try to put old code in the main section. There is ONE special section for old code.
The Old Code? I coded this during the weekend
- Old code = MT4. Looks like MT4 to me.
Your code | Documentation |
---|---|
OrderSend( Symbol(), OP_BUY, Lot(), Ask, Slip, slb, 0, CommentBuy, Magic, 0, Blue ); | bool OrderSend( MqlTradeRequest& request, // query structure MqlTradeResult& result // structure of the answer ); |
'if without "else" ??'
'if (ask> . . . ) buy;'
'if (bid< . . .) sell;'
The code was translated using MT4Orders.mqh https://www.mql5.com/ru/code/16006, that is why it can use MT4 orders.
I have been told, for iClose, it was a matter of not using arrays or handlers but giving the access straight to the double.
As for iHigh and iLow, I guess it must be something similar, but I also guess it might need to use a buffer: CopyBuffer. Then, do I also need a handler and an array?
![MT4Orders MT4Orders](https://c.mql5.com/36/42/mt4orders.jpg)
- www.mql5.com
Try this
#property version "1.00" #define SIGNAL_BUY 1 #define SIGNAL_SELL 2 #define SIGNAL_NONE -2 datetime barstamp=0; int OnInit() { barstamp=0; return(INIT_SUCCEEDED); } void OnTick() { datetime now=iTime(_Symbol,_Period,0); //new bar if(now>barstamp){ barstamp=now; int signal=CheckForSignal(_Symbol,10,PERIOD_CURRENT,1,2); if(signal==SIGNAL_BUY){Print("BUY "+TimeToString(now,TIME_DATE|TIME_MINUTES));} if(signal==SIGNAL_SELL){Print("SELL "+TimeToString(now,TIME_DATE|TIME_MINUTES));} } //new bar } int CheckForSignal(string symbol, int total_bars, ENUM_TIMEFRAMES tf2, int shift_5, double pips_bo){ MqlRates rates[];MqlTick tick; int rates_co=CopyRates(symbol,tf2,1,total_bars,rates); int errors=0;ResetLastError(); double point=(double)SymbolInfoDouble(symbol,SYMBOL_POINT);errors+=GetLastError(); bool get_tick=SymbolInfoTick(symbol,tick); //if anything came back if(rates_co>=total_bars&&shift_5<rates_co&&errors==0&&get_tick) { double highest=rates[0].high,lowest=rates[0].low; for(int f=1;f<rates_co;f++){ if(rates[f].high>highest){highest=rates[f].high;} if(rates[f].low<lowest){lowest=rates[f].low;} } //simplification for relevance double cl=highest,cl1=lowest,cl2=rates[shift_5].close; double ask=tick.ask,bid=tick.bid; if((ask>(cl+pips_bo*point))&&(ask>(cl2+pips_bo*point))){return(SIGNAL_BUY);} if((bid<(cl1-pips_bo*point))&&(bid<(cl2-pips_bo*point))){return(SIGNAL_SELL);} } //if anything came back ends here return(SIGNAL_NONE); }
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use