Questions from Beginners MQL5 MT5 MetaTrader 5 - page 523

 
Envelopes indicator in EA, EA wrote itself, in settings I put a shift (-7). Why does EA not open orders with a negative shift inEnvelopes indicator?
 
Vagif Babaev:
Envelopes indicator in EA, EA wrote itself, in settings I put shift (-7). Why does EA not open orders with negative shift inEnvelopes indicator?
In iEnvelopes the index of a value received from the indicator buffer should not be smaller than the shift, i.e. the last value should not be less than 7.
 
demonoid123000:
Dear programmers. Can you help? I would like to attach the number of open orders to Expert Advisors. I do not know if it will help. I put these owls on several pairs and only one order is opened. If I open an order on one of the pairs the signals on the other pair are not ignored. I do not know what to do with it.

the problem is this condition

if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES)==False)

This is how it should work.

//+------------------------------------------------------------------+
//|                                                    Hippo_Buy.mq4 |
//|                                                        ut_Kanada |
//|                                            albertgod1972@mail.ru |
//+------------------------------------------------------------------+
#property copyright "ut_Kanada"
#property link      "albertgod1972@mail.ru"
#property version   "1.00"
#property strict
//===================================================================+
//                          ЗАДАНЫЕ ЗНАЧЕНИЯ                         |
//===================================================================+

extern double Lot= 0.1;
extern bool Stop = true;
extern int SL = 250;
extern int TP = 500;

extern bool BU=false;        // Переменная для включения Безубытка.

extern bool Tral = true;       // Переменная для выключения трала.
extern int putr = 100;         // Включение трала при прохождении цены putr пунктов.
extern int TrailingStop = 150; // Непосредственно сам трал.

                               //*****************************************************************************************************************
//==================================================================+
//                  Переменные для программы                        |
//==================================================================+

int TekBar = -1;             // Текущий бар.
int Or;                      // Номер ордера.
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//==================================================================+

int start()
  {

//==================================================================+
//                           Индикаторы                             |
//==================================================================+

   double TA1=NormalizeDouble(iCustom(NULL,0,"Trendsignal_Alert_Buy",3,300,true,true,0,0,false,1,0,1),Digits);

//==================================================================+
//                     Условия модификации Ордеров.                 |
//==================================================================+
   if(Tral==true)
     {
      int cnt;
      for(cnt=OrdersTotal(); cnt>=0; cnt--)
        {
         Or=OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);

         if(OrderType()==OP_SELL)
           {
            if(OrderOpenPrice()-Ask>=putr*Point)
               if(OrderStopLoss()>(Ask+Point*(TrailingStop+MarketInfo(Symbol(),MODE_SPREAD))))
                  Or=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,0);
           }

         if(OrderType()==OP_BUY)
           {
            if(Bid-OrderOpenPrice()>=putr*Point)
               if(OrderStopLoss()<(Bid-Point*(TrailingStop+MarketInfo(Symbol(),MODE_SPREAD))))
                  Or=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,0);
           }
        }
     }

//==================================================================+
//                    Условия перевода в Безубыток.                 |
//==================================================================+  

   if(BU==true)
     {
      int cnt;
      for(cnt=OrdersTotal(); cnt>=0; cnt--)
        {
         Or=OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);

         if(OrderType()==OP_SELL && OrderStopLoss()>=OrderOpenPrice())
           {
            if(OrderOpenPrice()-Ask>=putr*Point)
               if(OrderStopLoss()>(Ask+Point*(TrailingStop+MarketInfo(Symbol(),MODE_SPREAD))))
                  Or=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,0);
           }

         if(OrderType()==OP_BUY)
           {
            if(Bid-OrderOpenPrice()>=putr*Point && OrderStopLoss()<=OrderOpenPrice())
               if(OrderStopLoss()<(Bid-Point*(TrailingStop+MarketInfo(Symbol(),MODE_SPREAD))))
                  Or=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,0);
           }
        }
     }

//==================================================================+    
/*
  int q;                                             
  for(q = 1; q <= Bars; q++)
  {
   double TAq = NormalizeDouble(iCustom(NULL,0,"Trendsignal_Alert_Buy",3,300,true,true,0,0,false,1,0,q),Digits);
   if(TAq != 0)
   {
    Comment("TAq = ",TAq);
    break;
   }
  }*/
//==================================================================+
//                    Условия и Открытие Ордеров.                   |
//==================================================================+

   if(Stop==true)
     {
      if(Total_orders(_Symbol)==0)
        {
         if(TekBar==Bars)return(0);
         TekBar=Bars;
           {
            if(TA1>High[1] && TA1!=0) // Условия продажи.
               Or=OrderSend(Symbol(),OP_SELL,Lot,Bid,3,Bid+SL*Point,Bid-TP*Point,"000",0,0,Tomato);        // Продажа.               

            if(TA1<Low[1] && TA1!=0)
               Or=OrderSend(Symbol(),OP_BUY,Lot,Ask,3,Ask-SL*Point,Ask+TP*Point,"000",0,0,RoyalBlue);      // Покупка.     ;

           }
        }
     }

   if(Stop==false)
     {
      if(Total_orders(_Symbol)==0)
        {
         if(TekBar==Bars)return(0);
         TekBar=Bars;
           {
            if(TA1>High[1] && TA1!=0) // Условия продажи.
               Or=OrderSend(Symbol(),OP_SELL,Lot,Bid,3,0,0,"000",0,0,Tomato);        // Продажа.                

            if(TA1<Low[1] && TA1!=0)
               Or=OrderSend(Symbol(),OP_BUY,Lot,Ask,3,0,0,"000",0,0,RoyalBlue);      // Покупка.     
           }
        }
     }
//----   
   return(0);
  }
//+------------------------------------------------------------------+
int Total_orders(string symbol
                 //int type
                 )
  {
   int n=0;
   int total=OrdersTotal();

   for(int i=0; i<total; i++)
     {
      if(OrderSelect(i,SELECT_BY_POS))
        {
         //if(OrderType()!=type)continue;
         //if(OrderMagicNumber()!=Magic)continue;
         if(OrderSymbol()!=symbol)continue;
         n++;
        }
     }
   return(n);
  }
//+------------------------------------------------------------------+
 
angel341:
What parameter or function will help to shift the indicator up or down by n points?
Added parameter Shift, positive number shifts up, negative number shifts down.
Files:
 
Sergey Gritsay:

the problem is this condition

This is how it should work

I don't know the programming language at all...I don't understand in short. Maybe you can change these values?
 
demonoid123000:
I don't know the programming language at all... I don't understand it. Maybe you can change these values?
Then where did you get this code?
 
Sergey Gritsay:
added the Shift parameter, positive number offset upwards, negative number offset downwards.
thank you very much! I'll be testing now!!!!
 

Sergey Gritsay:
добавил параметр Shift, положительное число смещение вверх, отрицательное вниз.

Thank you very much!

 
Sergey Gritsay:

he means something like this

Does executing this function delete orders? If it is called at the beginning of the code:" if(TimeCurrent()>=D'23:50')close_all();return;" then the program does not work further, i.e. orders are not opened and the log says "stop button pressed". If I delete this one line, everything works and opens. Could you please explain what is wrong? I do not know much about details, so I just copied the body of the function.
 
toni_stark:
Does executing this function delete orders? If it is called at the beginning of the code:" if(TimeCurrent()>=D'23:50')close_all();return;" then the program does not work further, i.e. orders are not opened and the log says "stop button pressed". If I delete this one line, everything works and opens. Could you please explain what is wrong? I am not good at details, so I just copied the body of the function.
your code please