Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1681

 
void OpenOrder(int db = -1){

  if(db == -1){
    Print("'db' должен иметь корректное значение");
    return;
  }

  Order order;

  //Если бид в границах ДБ (его хай/лоу) то инициализируем ордер для селстопа или байстопа
  if(Bid > db_last.low && Bid < db_last.hight){
    if(db == BEAR) order.InitForSell(SELLSTOP);
    if(db == BULL) order.InitForBuy(BUYSTOP);
  }

 ...

  if(order.is_init == true)
  {
    int order_send = OrderSend(Symbol(), order.cmd, 0.01, order.open_price, 10, 
    order.sl_price, order.tp_price, "", GetMagic(order), 0, order.arrow_color);

    if(order_send == -1){
      Print(order.error_text," | ",GetLastError()," db_last.third ",db_last.third,
        " | db_last.size_open_to_low ",db_last.size_open_to_low," | order.sl_price: ",
        order.sl_price," | order.cmd ",order.cmd);
      ResetLastError();
      return;
    }
  }
}

...

int GetMagic(Order &order)
{
  int magic = 0;
  //Если должен быть открыт стопордер и если есть уже открытые или отложенные 
  //ордера, то возможно некоторые с маджиком, это надо проверить и сгенерировать 
  //для нашего ордера уникальный маджик
  if(order.cmd == OP_SELLSTOP || order.cmd == OP_BUYSTOP)
    if(OrdersTotal() >= 1)
      for(;;){
        magic++;
        for(int i = OrdersTotal(); i > 0 ; i --)
          if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES) != false) //<------------ СЮДА НЕТ ВХОЖДЕНИЯ
            if(magic != OrderMagicNumber())
              return magic;
            
      }
    //Если нет открытых или отложенных ордеров то увеличиваем значение 
    //маджика, чтобы он равнялся единице
    else if (OrdersTotal() == 0)
      return (magic + 1);
  return magic;
}
 
Good evening, I wrote a very simple indicator on the job (attached file) I would like to clarify whether there is a way to prescribe in the code instead of a red and blue line (RSI2 and RSI3 in the picture (attached as well), respectively) was a single line - and it was red if RSI2>RSI3 and blue if RSI2 < RSI3

#property indicator_color2 Red
#property indicator_color3 Blue 
                                                              
extern int RSIPERIOD=3;
extern double KOEFF1=2.5;
extern double KOEFF2=1.86; 
                                                                                                                                                                  
double Buf0[],Buf1[],Buf2[];
double D10,D11,D12;
                                                                                                                                                                                                                                                                                                                                             
int init()
  {
   IndicatorDigits(0);
   string short_name="RSITEST";           
   IndicatorShortName("RSITEST");
   
   D10=RSIPERIOD;D11=D10*KOEFF1;D12=D11*KOEFF2;;
 
   SetIndexBuffer(0,Buf0);
   SetIndexLabel (0,"Stoch "+Ds_0(D10)+")\n");
   SetIndexBuffer(1,Buf1);
   SetIndexLabel (1,"Stoch ("+Ds_0(D11)+")\n");
   SetIndexBuffer(2,Buf2);
   SetIndexLabel (2,"Stoch ("+Ds_0(D12)+")\n");
   return(0);
  }
                                                                                                               
int start()
  {
   if(Bars<=RSIPERIOD) return(0);
   int ExtCountedBars=IndicatorCounted();
   if (ExtCountedBars<0) return(-1);
   if (ExtCountedBars>0) ExtCountedBars--;
   for(int i=0;i<Bars-RSIPERIOD;i++)
      {
       Buf0[i] = iRSI(NULL,0,D10,0,i);
       Buf1[i] = iRSI(NULL,0,D11,0,i);
       Buf2[i] = iRSI(NULL,0,D12,0,i); 
      }
   return(0);
  }
string Ds_0(double DOUBLE) {return(DoubleToStr(DOUBLE,0));}
Files:
RSITEST.mq4  4 kb
 
Andrey Kipyatkov #:
Good evening, I wrote a very simple indicator on the bole (attached file) I would like to clarify whether there is a way to prescribe in the code instead of a red and blue line (RSI2 and RSI3 in the picture (attached as well), respectively) was a single line - and it was red if RSI2>RSI3 and blue if RSI2 < RSI3

in MT5 you can
 
MakarFX #:
in mt5 you can

In mt4 too :)

 
Vitaly Muzichenko #:

In mt4 too :)

EMPTY_VALUE
 
Ivan Butko #:

Given N candles backwards. Find candles of size >= X pips, remember their number and the size of each one.
Add candlesticks >= X pips to the sorted array, then look for the place of the current candlestick in the array.
 
Vitaly M
MakarFX #:
EMPTY_VALUE
uzichenko #
:

In mt4 too :)

https://docs.mql4.com/ru/constants/namedconstants/otherconstants I don't really see howEMPTY_VALUE can help me. I have 3 arrays and each one gives out rsy if I set EMPTY_VALUE it just won't give me anything. my task is to write in the code instead of red and blue line the same line - and it will be red ifRSI2>RSI3 and blue ifRSI2<RSI3
Прочие константы - Именованные константы - Константы, перечисления и структуры - Справочник MQL4
Прочие константы - Именованные константы - Константы, перечисления и структуры - Справочник MQL4
  • docs.mql4.com
Прочие константы - Именованные константы - Константы, перечисления и структуры - Справочник MQL4
 
Andrey Kipyatkov #:
https://docs.mql4.com/ru/constants/namedconstants/otherconstants I don't really understand howEMPTY_VALUE can help me. I have 3 arrays, each of them produces Rsai if I put EMPTY_VALUE it just won't give me anything. my task is to write in the code instead of red and blue line the same line - and it will be red ifRSI2>RSI3 and blue ifRSI2<RSI3
       Buf0[i] = iRSI(NULL,0,D10,0,i);
       if(iRSI(NULL,0,D11,0,i)>iRSI(NULL,0,D12,0,i))
       Buf1[i] = Buf0[i];
       else
       Buf1[i] = EMPTY_VALUE;
Files:
RSITEST-1.mq4  4 kb
 
Andrey Kipyatkov #:
https://docs.mql4.com/ru/constants/namedconstants/otherconstants I don't really see howEMPTY_VALUE can help me. I have 3 arrays and each one gives out Rsai if I set EMPTY_VALUE it just won't give me anything. my task is to write in the code instead of red and blue line the same line - and it will be red ifRSI2>RSI3 and blue ifRSI2<RSI3

Change colour as required to suit your needs

if(Open < Close) {
  SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1,clrRed);
  ...
 
Vitaly Muzichenko #:

Change the colour as needed to suit your needs

Really?!))

Have you tried it?