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

 
Ivan Butko #:
Vitaly, if you don't print it, the internal calculations will show 0.00004.... or 5.666666.....e ?
Or is it the same thing?

the internal calculations only include this (an eight byte hexadecimal integer)

https://ru.wikipedia.org/wiki/Число_двойной_точности

0.00004467 = 0x3f076b81834d51ed
 
hello! does anyone know a sensible duplicator of trades from MT4 to the Quick exchange?
 

Good afternoon. Help


I have a code without checking for the presence of open orders.

Opens orders according to the logic that is laid down, but opens both buy and sell orders

void OnTick()
{
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//
   Comment( 
  "\n",                      name,
  "\n", 
  "Символ ",                 Symbol(),  
  "\n",
  "Тайм Фрейм ",             Period(),
  "\n",                      AccountCompany(),
  "\n",
  " ",                       AccountServer(),
  "\n", 
  "Lots",                    Lot,
  "\n",
  "Объем в бай ",            "BuyLots()",
  "\n", 
  "Объем в сел ",            "SellLots()",
  "\n",
  "Price ",                  Bid,
  "\n", 
  "Дата ",                   TimeToString( TimeCurrent(), TIME_DATE ),
  "\n",
  "Server Time ",            TimeToString( TimeCurrent(), TIME_SECONDS ),
  "\n", 
  "\n", "Процент просадки ", NormalizeDouble(  (AccountInfoDouble(ACCOUNT_BALANCE)-AccountInfoDouble(ACCOUNT_MARGIN_FREE))/AccountInfoDouble(ACCOUNT_BALANCE)*100, 
  2)/*, "\n" //"  CalcTP() ", CalcTP(),
,  "  t_p $ ", t_p, "  Profit() $ ", Profit(), "\n",  */); 
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//
   /*if (CountTrades() == 0 && TypeOrder(OP_BUY) && TypeOrder(OP_SELL))
      {*/
       double body = Close[1] - Open[1];
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//
//Открытие позиции Buy
    if (body > 0)
       {
        Forder = (OrderSend(_Symbol,OP_BUY,Lot,Ask,iSlippage,0,0,"Коммент",Magic,0,Blue));
        if(Forder > 0)
          {
           Print("Открыта Позиция BUY");
           if(OrderSelect(Forder, SELECT_BY_TICKET))
             {
              TP = NormalizeDouble((Ask+iTakeProfit*_Point),_Digits);
              if (OrderModify(OrderTicket(),OrderOpenPrice(),0,TP,0))
                 Print("Ордер Модифицирован BUY "); 
              else 
                 Print("Ошибка Модификации Ордера BUY = ",GetLastError());
             }
          }Print("Ошибка Открытия Позиции BUY");
       }
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//
//Открытие позиции Sell      
    if (body < 0)
       {
        Forder = (OrderSend(_Symbol,OP_SELL,Lot,Bid,iSlippage,0,0,"Коммент Sell",Magic,0,Red));
        if (Forder > 0)
           {
            Print("Открыта Позиция SELL");
            if(OrderSelect(Forder, SELECT_BY_TICKET))
              {
               TP = NormalizeDouble((Bid-iTakeProfit*_Point),_Digits);
               if (OrderModify(OrderTicket(),OrderOpenPrice(),0,TP,0))
                   Print("Ордер Модифицирован SELL "); 
               else 
                   Print("Ошибка Модификации Ордера SELL = ",GetLastError());
              }
           }Print("Ошибка Открытия Позиции SELL");
       }
     }  
 //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//      
  /* else 
   {
   
   }*/
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//
/*}*/

We are going to work with these orders.

//It does not have to check the order if it is open.


If you enable checking, then the orders are not opened as we would like them to be.
If we want to avoid counter-orders, we should check the first order to be opened and then open the same type until the last order type is closed and then go back to the logic of checking the conditions for opening, right?

int TypeOrder(int OrType)
{
 int count = 0;
  for(int i = OrdersTotal(); i>=0; i++ )
     {
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         {
          if (OrderSymbol() == _Symbol && OrderType() == OrType && OrderMagicNumber() == Magic)
             {
              count++;
             }
         }
     }return (count);
}

And how to point to this there is no understanding.
Anybody out there who can give a nudge to understand?

Thanks for any hints.

 
Alexander Avksentyev #:

Good afternoon.

void OnTick()
  {
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//
   Comment( 
  "\n",                      name,
  "\n", 
  "Символ ",                 Symbol(),  
  "\n",
  "Тайм Фрейм ",             Period(),
  "\n",                      AccountCompany(),
  "\n",
  " ",                       AccountServer(),
  "\n", 
  "Lots",                    Lot,
  "\n",
  "Объем в бай ",            "BuyLots()",
  "\n", 
  "Объем в сел ",            "SellLots()",
  "\n",
  "Price ",                  Bid,
  "\n", 
  "Дата ",                   TimeToString( TimeCurrent(), TIME_DATE ),
  "\n",
  "Server Time ",            TimeToString( TimeCurrent(), TIME_SECONDS ),
  "\n", 
  "\n", "Процент просадки ", NormalizeDouble(  (AccountInfoDouble(ACCOUNT_BALANCE)-AccountInfoDouble(ACCOUNT_MARGIN_FREE))/AccountInfoDouble(ACCOUNT_BALANCE)*100, 
  2)/*, "\n" //"  CalcTP() ", CalcTP(), "  t_p $ ", t_p, "  Profit() $ ", Profit(), "\n",  */); 
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//
   double body = Close[1] - Open[1];
   if (CountTrades() == 0 && body > 0) BuyOpen();     // Если нет открытых и сигнал бай
   if (CountTrades() == 0 && body < 0) SellOpen();    // Если нет открытых и сигнал селл
   if (CountTrades(0) > 0 && body > 0) BuyOpen();     // Если есть открытые бай и сигнал бай
   if (CountTrades(1) > 0 && body < 0) SellOpen();    // Если есть открытые селл и сигнал селл
  }  
//+------------------------------------------------------------------+
//| Подсчет открытых ордеров по типу                                 |
//+------------------------------------------------------------------+
int CountTrades(int ot=-1) 
  {
   int cnt=0;
   int i=OrdersTotal()-1;
   for(int pos=i;pos>=0;pos--)
     {
      if(OrderSelect(pos,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==_Symbol)
           {
            if(OrderMagicNumber()==MagicNum)
              {
               if(OrderType()==ot||ot==-1) cnt++;
              }
           }
        }
     }
   return(cnt);
  }
//+------------------------------------------------------------------+
void BuyOpen() //Открытие позиции Buy
  {
   Forder = (OrderSend(_Symbol,OP_BUY,Lot,Ask,iSlippage,0,0,"Коммент",Magic,0,Blue));
   if(Forder > 0)
     {
      Print("Открыта Позиция BUY");
      if(OrderSelect(Forder, SELECT_BY_TICKET))
        {
         TP = NormalizeDouble((Ask+iTakeProfit*_Point),_Digits);
         if (OrderModify(OrderTicket(),OrderOpenPrice(),0,TP,0))
            Print("Ордер Модифицирован BUY "); 
         else 
            Print("Ошибка Модификации Ордера BUY = ",GetLastError());
        }
     }
   else Print("Ошибка Открытия Позиции BUY");
  }
//+------------------------------------------------------------------+
void SellOpen() //Открытие позиции Sell  
  {
   Forder = (OrderSend(_Symbol,OP_SELL,Lot,Bid,iSlippage,0,0,"Коммент Sell",Magic,0,Red));
   if (Forder > 0)
     {
      Print("Открыта Позиция SELL");
      if(OrderSelect(Forder, SELECT_BY_TICKET))
        {
         TP = NormalizeDouble((Bid-iTakeProfit*_Point),_Digits);
         if (OrderModify(OrderTicket(),OrderOpenPrice(),0,TP,0))
            Print("Ордер Модифицирован SELL "); 
         else 
            Print("Ошибка Модификации Ордера SELL = ",GetLastError());
        }
     }
   else Print("Ошибка Открытия Позиции SELL");
  }
//+------------------------------------------------------------------+
 
MakarFX #:

Thank you. The logic was correct, make the counter only correct and specify the condition correctly

if (CountTrades() == 0 && body > 0) BuyOpen();     // Если нет открытых и сигнал бай
   if (CountTrades() == 0 && body < 0) SellOpen();    // Если нет открытых и сигнал селл
   if (CountTrades(0) > 0 && body > 0) BuyOpen();     // Если есть открытые бай и сигнал бай
   if (CountTrades(1) > 0 && body < 0) SellOpen();    // Если есть открытые селл и сигнал селл

Thank you. I'll look into it.

 
Tretyakov Rostyslav #:

Good afternoon. Here's a question. I have a trawl.

void Trail()
{
 if(iTrailStart <= 0.0)return; 
 double tp,sl_lev;
 for(int i=OrdersTotal()-1; i>=0; i--)
    {
     if(OrderSelect(i, SELECT_BY_POS,MODE_TRADES))
       {
        if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
          {
           if(OrderType() == OP_BUY) 
             {
              if(iTrailTakeProfit > 0.0)
                {
                tp=OrderTakeProfit() + NormalizeDouble(iTrailTakeProfit * Point(),_Digits);
                if(NormalizeDouble(((tp - OrderTakeProfit())) < 0.0,Digits))return;
                tp = OrderTakeProfit();
                }else tp = 0.0;
              if(OrderProfit() + OrderSwap() + OrderCommission() > MarketInfo(Symbol(), MODE_TICKVALUE) * iTrailStart * OrderLots())return;
                {
                 if(NormalizeDouble(Bid - OrderOpenPrice() <= iTrailStart * Point(),Digits))return;
                   {
                    if(OrderStopLoss()== 0.0 && NormalizeDouble((Bid-OrderStopLoss()) <= iTrailDist * Point(),_Digits))return;
                      {
                      if(iTrailStep > 0.0 && OrderStopLoss()==0.0 && NormalizeDouble((Bid - OrderStopLoss() - iTrailDist * Point() < iTrailStep * Point()),_Digits))return;
                        {
                         sl_lev = NormalizeDouble(Bid - iTrailDist * Point(),_Digits);
                         if(NormalizeDouble((Bid - sl_lev) < MarketInfo(Symbol(),MODE_STOPLEVEL) * Point,Digits))return;
                           {
                            if (!OrderModify(Forder,OrderOpenPrice(),OrderStopLoss() + iTrailStart * Point,OrderTakeProfit(),OrderExpiration()))
                            Print("Не удалось модифицировать стоплосс ордера №",OrderTicket(),". Ошибка: ",GetLastError());
                           }
                        }
                      }
                   }
                }
             }
           if(OrderType() == OP_SELL)
             {
              if(iTrailTakeProfit > 0.0)
                {
                 tp=OrderProfit() - NormalizeDouble(iTrailTakeProfit * Point(),_Digits);
                 if(NormalizeDouble((OrderTakeProfit() - tp) < 0.0,_Digits))return;
                 tp = OrderTakeProfit();
                }else tp = 0.0;
              if(OrderProfit() + OrderSwap() + OrderCommission() > MarketInfo(Symbol(), MODE_TICKVALUE) * iTrailStart * OrderLots())return;
                {
                 if(NormalizeDouble((OrderProfit() - Ask) <= iTrailStart * Point(),_Digits))return;
                   {
                    if(OrderStopLoss() == 0.0 && NormalizeDouble((OrderStopLoss() - Ask) <= iTrailDist * Point(),_Digits))return;
                      {
                       if(iTrailStep > 0.0 && OrderStopLoss() == 0.0 && NormalizeDouble((OrderStopLoss() - Ask) - iTrailDist * Point(),_Digits) < iTrailStep * Point())return;
                         {
                          sl_lev = NormalizeDouble(Ask + iTrailDist * Point(),_Digits);
                          if(NormalizeDouble((sl_lev - Ask) > MarketInfo(Symbol(),MODE_STOPLEVEL) * Point,_Digits)) return;
                            {
                            if (!OrderModify(Forder,OrderOpenPrice(),OrderStopLoss() + iTrailStart * Point,OrderTakeProfit(),OrderExpiration()))
                            Print("Не удалось модифицировать стоплосс ордера №",OrderTicket(),". Ошибка: ",GetLastError());
}}}}}}}}}}

How do I specify to my Expert Advisor to make it work?

void OnTick()
  {
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//
   Comment( 
  "\n",                      name,
  "\n", 
  " ",                       Symbol(),  
  "\n",
  "Тайм Фрейм ",             Period(),
  "\n",                      AccountCompany(),
  "\n",
  "\n ",                     AccountServer(),
  "\n", 
  "Lots\n",                  B_S_Lot(),
  "\n",
  "Price ",                  Bid,
  "\n", 
  "Дата ",                   TimeToString( TimeCurrent(), TIME_DATE ),
  "\n",
  "Server Time ",            TimeToString( TimeCurrent(), TIME_SECONDS ),
  "\n", 
  "Profit ",                 Profit(),
  "\n",
  "AvTP ",                   CalcTP (),
  "\n", 
  "Количество ордеров ",     CountTrades(),
  "\n",
  "\n ",                     GetVolumeLotLastOrder(),
  "\n",
  "\n", "Процент просадки ", NormalizeDouble(  (AccountInfoDouble(ACCOUNT_BALANCE)-AccountInfoDouble(ACCOUNT_MARGIN_FREE))/AccountInfoDouble(ACCOUNT_BALANCE)*100,2)
  ); 
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//
   double body = Close[1] - Open[1];
   if (CountTrades() == 0 && body > 0) BuyOpen();     // Если нет открытых и сигнал бай
   if (CountTrades() == 0 && body < 0) SellOpen();    // Если нет открытых и сигнал селл
   if (CountTrades(0) > 0 && body > 0) BuyOpen();     // Если есть открытые бай и сигнал бай
   if (CountTrades(1) > 0 && body < 0) SellOpen();    // Если есть открытые селл и сигнал селл
   Trail();
  }

I've seen that they specify it that way, but it somehow does not work for me.

It is a general problem to specify the ex for the function to work, how should I do it?

 
Alexander Avksentyev #:

Good afternoon. Here's a question. I have a trawl.

How do I specify to my Expert Advisor to make it work?

I've seen that they specify it that way, but it somehow does not work for me.

In general, the problem is to specify the ex, for the function to work, how to do this?

What is it!!!

if(NormalizeDouble(((tp - OrderTakeProfit())) < 0.0,Digits))
if(NormalizeDouble(Bid - OrderOpenPrice() <= iTrailStart * Point(),Digits))
if(NormalizeDouble((Bid - sl_lev) <  MarketInfo(Symbol(),MODE_STOPLEVEL) * Point,Digits))

NormalizeDouble read and tell me how you put the comparison there.


P.S. You don't have any errors in your log at all?

 
Tretyakov Rostyslav #:

What is this!!!

NormalizeDouble read it and tell me how you got the comparison in there.


P.S. Do you have no errors at all in your logbook?

No errors, not one.

NormalizeDouble- makes it readable.

Can't you do it that way?

 
Alexander Avksentyev #:

no errors, not one.

NormalizeDouble- makes itreadable.

You can't do it this way?

Boolean variable.

 

Hello all!

Please help!

The common_sr indicator shows yesterday's maximum/minimum only today, on the current period. I.e. these levels, boundaries are not shown on yesterday's day - only today. And this is correct!

And the same indicator, showing the maximum/maximum levels of the previous week, draws them in the previous week as well. Although, logically, it should draw only the current week.

I have tried to represent these ideas in the screenshot. If I have any questions, I will give the answers.

Will you be able to correct it in any way?

Thanks a lot for the help!