新人对MQL4和MQL5的任何问题,对算法和代码的帮助和讨论 - 页 541

 
Rustam Bikbulatov:

见过并试过。已经帮助了很多,但我的理解有一个限度

所以你不想要订单的数量,而是以手为单位的数量?

//+------------------------------------------------------------------+
int fMarketOrdersOpenVolume(const ENUM_ORDER_TYPE order_type)
  {
   int total=OrdersTotal();
   double lots=0;
   for(int i=total-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS))
        {
         if(OrderType()!=order_type) continue;
         if(OrderMagicNumber()==123 && OrderSymbol()==Symbol())
            lots+=OrderLots();
        }
     }
   return lots;
  }
//+------------------------------------------------------------------+
 
Artyom Trishkin:

所以你不想要订单的数量,而是以手为单位的数量?

double fMarketOrdersOpenVolume(const ENUM_ORDER_TYPE order_type)
 
Konstantin Nikitin:

Ahrinet!!!!!!我需要的是!!!!!!我从未想过!!!!!非常感谢您!!!!!

 
Konstantin Nikitin:

是的,我在担心中错过了它。

 
谢谢你们对我们的帮助!!。你们都做得很好!!。
 

然而,你好!

你能就这种情况提供建议吗:基于TMA_Fair,我在边界上开盘,并在相反的边界上收盘,但它并没有在另一个边界上收盘!你知道吗?代码中的错误在哪里?

void OnTick()
{
  PriceHigh = iCustom(NULL, 0, "ExtremeTMALine st2050 v1", TimeFrame, TMAPeriod, Price, ATRMultiplier, ATRPeriod, TrendThreshold, ShowCenterLine, alertsOn, alertsMessage, alertsSound, alertsEmail, MaxBars, ShowInfo, ShowInfo_WindowNo, ShowInfo_X, ShowInfo_Y, ShowInfo_ColorLabel, ShowInfo_ColorSwing, ShowInfo_ColorUp, ShowInfo_ColorDown, 1, 0);
  PriceLow  = iCustom(NULL, 0, "ExtremeTMALine st2050 v1", TimeFrame, TMAPeriod, Price, ATRMultiplier, ATRPeriod, TrendThreshold, ShowCenterLine, alertsOn, alertsMessage, alertsSound, alertsEmail, MaxBars, ShowInfo, ShowInfo_WindowNo, ShowInfo_X, ShowInfo_Y, ShowInfo_ColorLabel, ShowInfo_ColorSwing, ShowInfo_ColorUp, ShowInfo_ColorDown, 2, 0);
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+  
  if (CountSell() == 0 && Bid >= PriceHigh)
  {
      ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0, "ExtremeTMALine_Robot", Magic, 0, Red);
      if (ticket>0)
      {
       SL = NormalizeDouble(Bid + StopLoss*Point, Digits);
       
       if(OrderSelect(ticket, SELECT_BY_TICKET))
          if(!OrderModify (ticket, OrderOpenPrice(), SL, 0, 0))
          Print ("Ошибка модификации ордера на продажу!!!"); 
      } else Print ("Ошибка открытия ордера на продажу!!!");
        
  }
//+------------------------------------------------------------------+  
  if(Ask <= PriceLow && CountSell() > 0)
  {
    for(int i = OrdersTotal()-1; i >= 0; i--)
    {
      if (OrderSelect (i, SELECT_BY_POS, MODE_TRADES))
      {
        if (OrderMagicNumber() == Magic && OrderType() == OP_SELL)
            if (!OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, Black))
            Print ("Ошибка закрытия ордера на продажу!!!");  
      } else Print ("Ошибка открытия ордера на продажу!!!");
    }
  }  
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+  
  
  if (CountBuy() == 0 && Ask <= PriceLow)
  {
      ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0, "ExtremeTMALine_Robot", Magic, 0, Blue);
      if (ticket>0)
      {
       SL = NormalizeDouble(Ask - StopLoss*Point, Digits);
       
       if(OrderSelect(ticket, SELECT_BY_TICKET))
          if (!OrderModify (ticket, OrderOpenPrice(), SL, 0, 0))
          Print ("Ошибка модификации ордера на покупку!!!");  
      } else Print ("Ошибка открытия ордера на покупку!!!");
        
  }
//+------------------------------------------------------------------+  
   if(Bid >= PriceHigh && CountBuy() > 0)
  {
    for(int i = OrdersTotal()-1; i >= 0; i--)
    {
      if (OrderSelect (i, SELECT_BY_POS, MODE_TRADES))
      {
        if (OrderMagicNumber() == Magic && OrderType() == OP_BUY)
           if(!OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, Green))
           Print ("Ошибка закрытия ордера на покупку!!!"); 
      } else Print ("Ошибка открытия ордера на покупку!!!");
    }
  }
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
int CountSell()
{
 int count = 0;
     for (int trade = OrdersTotal()-1; trade>=0; trade--)
     {
          if(OrderSelect(trade, SELECT_BY_POS, MODE_TRADES))
          {
             if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_SELL)
             count++;
          }
     }
     return (count);
}
//+------------------------------------------------------------------+
int CountBuy()
{
 int count = 0;
     for (int trade = OrdersTotal()-1; trade>=0; trade--)
     {
          if(OrderSelect(trade, SELECT_BY_POS, MODE_TRADES))
          {
             if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_BUY)
             count++;
          }
     }
     return (count);
}
//+------------------------------------------------------------------+
 
Domovoi44:

然而,你好!

你能就这种情况提供建议吗:基于TMA_Fair,我在边界上开盘,并在相反的边界上收盘,但它并没有在另一个边界上收盘!你知道吗?代码中的错误在哪里?

如果你密切关注这个指标,你可以看到它向后重绘了10个或更多的条形图。这就是全部原因。

 
Alexey Viktorov:

如果你密切关注该指标,你会注意到它会向后重绘10条或更多。这就是全部原因。

Ehhhhhhh man!!!我将继续挖掘)谢谢你的帮助!!。
 
你能告诉我,MT-4是否有坑口量背离指标?
 

下午好,请您帮忙我正试图写出大量的计数控制。如果我的账户成为+10%的利润,那么手数就会翻倍。如果+20%,则地段*4。如果在我的账户中减少,那么分别减少手数。我不明白如何使Lots_New在每次新的交易中取得新的价值。

double Bal= AccountBalance();
double GetLots()
{
double Lots_New;
double Lots = 0.1;
   
   if(Bal <=AccountBalance()+0.1*AccountBalance()){
   Lots_New=Lots*2;
   }
   if(Bal >=AccountBalance()+0.1*AccountBalance()){
   Lots_New=Lots/2;
   }
   if(Bal ==AccountBalance()){
   Lots_New=Lots;
   }

Alert("Lot new= ",Lots_New);
return (Lots_New);
}
原因: