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

 
Vitaly Muzichenko #:

OnTradeTransaction

Thank you. Just hell) I feel sorry for the algotraders on MT5.
 
secret #:
Thank you. Just hell) I pity the algotraders on mt5.

It's worth it, in mt5 orders are processed many times faster. And testing is more plausible, there are almost no tester grails.

 
Vitaly Muzichenko #:

Read three or four posts.

Yeah, I did. Got it now.

Thanks, I thought it was a mistake, but it's the norm.
 
Tretyakov Rostyslav #:

1,12500*Point=0.0000112500

Fixed everything, the result did not change.

Maybe it is in the logic?

Well somehow it opens the TSL but as a stop

 
Alexander Avksentyev #:

I fixed it, but the result didn't change.

Could it be a matter of logic?

Well, somehow it opens the TSL, but as a stop.

Your function looks like this:

NormalizeDouble((Bid - OrderOpenPrice()*Point),Digits)

NormalizeDouble((1,12700 - 1,12500/100000),5)

You need to understand what"Point" does.

Make a print.

Print(DoubleToString(NormalizeDouble(Point,Digits),Digits));
 
Tretyakov Rostyslav #:

Your function looks like this:

NormalizeDouble((1,12700 - 1,12500/100000),5)

You need to understand what"Point" does.

Make a print

before

void TrailSL()
{
 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 (NormalizeDouble(Bid - OrderOpenPrice(),Digits) <= iTrailStart * MarketInfo(Symbol(),MODE_POINT) );//true
                   {
                    if(OrderStopLoss() < OrderOpenPrice() || OrderStopLoss() == 0 && NormalizeDouble(Bid - OrderStopLoss(),Digits) <= iTrailDist * MarketInfo(Symbol(),MODE_POINT));//true
                      {
                      if(iTrailStep > 0.0 && OrderStopLoss() != 0.0 && NormalizeDouble((Bid - OrderStopLoss()) - iTrailDist * MarketInfo(Symbol(),MODE_POINT),Digits) < iTrailStep * MarketInfo(Symbol(),MODE_POINT));//true
                        {
                         sl_lev = Bid - iTrailDist * MarketInfo(Symbol(),MODE_POINT);
                         if(NormalizeDouble(Bid - sl_lev,Digits) < MarketInfo(Symbol(),MODE_STOPLEVEL));//false
                           {
                            if(!OrderModify(Forder,OrderOpenPrice(),sl_lev,tp,0,Red))return;
                            Print("Не удалось модифицировать стоплосс ордера №",OrderTicket(),". Ошибка: ",GetLastError());
                           }
                        }
                      }
                   }
                }
             }

after

void TrailSL()
{
   if (iTrailStart <= 0.0 || iTrailStep <= 0.0)
      return; 
      
   double sl_lev;
         
   for (int i = OrdersTotal() - 1; i >= 0; i--)
   {
      if(!OrderSelect(i, SELECT_BY_POS,MODE_TRADES))
         continue;
      
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != Magic)
         continue;  
         
      if(OrderType() == OP_BUY) 
      {
         if (NormalizeDouble(Bid - OrderOpenPrice(),Digits) < iTrailStart * MarketInfo(Symbol(),MODE_POINT) )
            continue;

         if (OrderStopLoss() >= OrderOpenPrice() || NormalizeDouble(Bid - OrderStopLoss(), Digits()) < iTrailDist * MarketInfo(Symbol(),MODE_POINT))
            continue;

         if (OrderStopLoss() == 0.0 || NormalizeDouble((Bid - OrderStopLoss()) - iTrailDist * MarketInfo(Symbol(),MODE_POINT),Digits) < iTrailStep * MarketInfo(Symbol(),MODE_POINT))
            continue;

         sl_lev = Bid - iTrailDist * MarketInfo(Symbol(),MODE_POINT);
         if (NormalizeDouble(Bid - sl_lev,Digits) < MarketInfo(Symbol(),MODE_STOPLEVEL))
            continue;
            
         if (!OrderModify(OrderTicket(), OrderOpenPrice(), sl_lev, OrderTakeProfit(), 0, clrRed))
            Print("Не удалось модифицировать стоплосс ордера №",OrderTicket(),". Ошибка: ",GetLastError());
      }}}

But now it doesn't want to turn on at all.

No errors in compiler or terminal, just won't turn on.

What's the magic problem?

What is it?

Sorry for the intrusion.

 
Alexander Avksentyev #:

I'm sorry for being intrusive.

It's not being intrusive. Never be afraid to say you don't know something - always ask.

I'll give you an example.
 
Alexander Avksentyev #:

What are "iTrailStart" and "iTrailDist"?

 
Tretyakov Rostyslav #:

What are "iTrailStart" and "iTrailDist"?

Number of points to switch on and distance from market to trawl

iTrailStart = 10; //Number of points to enable trawl;

iTrailDist = 10; //Distance from the stop to the market;

If the order is in the plus by 11 pips, then 11-10=1 pips without a loss.

 
Alexander Avksentyev #:

Number of points to include and distance from market to tsl

More or less

//--- input parameters
int iTrailStart   = 10;  //Кол-во пунктов для включения тралa
int iTrailDist    = 10;  //Расстояние от стопа до рынка
//--- global parameters
int iDistTrail = iTrailDist;
//+------------------------------------------------------------------+
void OnTick()
  {
//---
if(iDistTrail<MarketInfo(Symbol(),MODE_STOPLEVEL))
   iDistTrail = MarketInfo(Symbol(),MODE_STOPLEVEL);
   
   // дальше твой код

  }
//+------------------------------------------------------------------+
void TrailSL()
  {
   if(iTrailStart <= 0) return; 
      
   double 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 ((OrderStopLoss() == 0 && Bid > OrderOpenPrice() + iTrailStart * _Point)||(OrderStopLoss() != 0 && Bid > OrderStopLoss() + (iDistTrail+iTrailStep) * _Point))
                 {
                  sl_lev = NormalizeDouble(Bid - iDistTrail * _Point,Digits);
                  if (OrderModify(OrderTicket(), OrderOpenPrice(), sl_lev, OrderTakeProfit(), 0, clrRed))
                     Print("Удачная модифиция стоплосс ордера №",OrderTicket());
                  else
                     Print("Не удалось модифицировать стоплосс ордера №",OrderTicket(),". Ошибка: ",GetLastError());
                 }
              }
            if(OrderType() == OP_SELL) 
              {
               if ((OrderStopLoss() == 0 && Ask < OrderOpenPrice() - iTrailStart * _Point)||(OrderStopLoss() != 0 && Ask < OrderStopLoss() - (iDistTrail+iTrailStep) * _Point))
                 {
                  sl_lev = NormalizeDouble(Ask + iDistTrail * _Point,Digits);
                  if (OrderModify(OrderTicket(), OrderOpenPrice(), sl_lev, OrderTakeProfit(), 0, clrRed))
                     Print("Удачная модифиция стоплосс ордера №",OrderTicket());
                  else
                     Print("Не удалось модифицировать стоплосс ордера №",OrderTicket(),". Ошибка: ",GetLastError());
                 }
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+
Reason: