CopyHigh and CopyLow for Breakouts. CopyLow DOES NOT seem to work.

 
      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);
               }
I am trying to code a Highs and Lows signal, but only the High signal seems to be working. Does anybody see any errors in there? Am I doing something terribly wrong?
 
I am quite certain that you have been told many times that topics concerning MT4 and MQL4 have their own section. Yet you keep ignoring me.
In future please post in the correct section.
I will move your topic to the MQL4 and Metatrader 4 section this time (again), next time I will just delete your topic..
 
It is MQL5
 
YThi MJ:
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.

 
Keith Watford:

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? 

 
YThi MJ :

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.

 
Vladimir Karputov:

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

 
YThi MJ: 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
  • www.mql5.com
Данная библиотека позволяет работать с ордерами в MQL5 (MT5-hedge) точно так же, как в MQL4. Т.е. ордерная языковая система (ОЯС) становится идентичной MQL4. При этом сохраняется возможность параллельно использовать MQL5-ордерную систему. В частности, стандартная MQL5-библиотека будет продолжать полноценно работать. Выбор между ордерными...
 

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);
}
Reason: