简单问题 - 页 2

 
Ais:

请检查 "Dist "值

检查?如何检查?我从MQL4的书中复制了代码(有距离变量的部分)。

int start()                                     // Special function 'start'
  {
   string Symb=Symbol();                        // Symbol
   double Dist=1000000.0;                       // Presetting
   int Real_Order=-1;                           // No market orders yet
   double Win_Price=WindowPriceOnDropped();     // The script is dropped here
//-------------------------------------------------------------------------------- 2 --
   for(int i=1; i<=OrdersTotal(); i++)          // Order searching cycle
     {
      if (OrderSelect( i-1, SELECT_BY_POS)==true) // If the next is available
        {                                       // Order analysis:
         //----------------------------------------------------------------------- 3 --
         if (OrderSymbol()!= Symb) continue;    // Symbol is not ours
         int Tip=OrderType();                   // Order type
         if ( Tip>1) continue;                   // Pending order  
         //----------------------------------------------------------------------- 4 --
         double Price=OrderOpenPrice();         // Order price
         if (NormalizeDouble(MathAbs( Price- Win_Price),Digits)< //Selection
            NormalizeDouble( Dist,Digits))       // of the closest order       
           {
            Dist=MathAbs( Price- Win_Price);      // New value
            Real_Order= Tip;                     // Market order available
            int Ticket=OrderTicket();           // Order ticket
            double Lot=OrderLots();             // Amount of lots
           }
         //----------------------------------------------------------------------- 5 --
        }                                       //End of order analysis
     }                                          //End of order searching
//-------------------------------------------------------------------------------- 6 --
   while(true)                                  // Order closing cycle
     {
      if ( Real_Order==-1)                       // If no market orders available
        {
         Alert("For ", Symb," no market orders available");
         break;                                 // Exit closing cycle        
        }
      //-------------------------------------------------------------------------- 7 --
      switch( Real_Order)                        // By order type
        {
         case 0: double Price_Cls=Bid;          // Order Buy
            string Text="Buy ";                 // Text for Buy
            break;                              // Из switch
         case 1: Price_Cls=Ask;                 // Order Sell
            Text="Sell ";                       // Text for Sell
        }
      Alert("Attempt to close ", Text," ", Ticket,". Awaiting response..");
      bool Ans=OrderClose( Ticket, Lot, Price_Cls,2);// Order closing
see also: https://book.mql4.com/trading/orderclose
 
Ais:

1.确保 "Dist "的初始值是正确的。

2.在周期开始时插入警报以检查 "Dist "的值:"警报(" Dist = ", Dist );"

有什么方法可以在不使用变量 "Dist "的情况下选择正确的顺序吗?

 
Ais:

回答1

样本中的符号">"和"<"在同一表达式中的方向不同

closeorder.mq4 的第22行和前一个样本的第6行

我认为在第二个例子中,这一定是一个错误......你怎么看?

 
Ais:

回答2

取决于 "正确的订单 "的含义

我需要选择(并关闭)开盘价较低的订单OP_BUY,而且这种选择必须在有2个订单OP_BUY时开始...OP_SELL也是如此...这有这么难实现吗?我很迷惑...

 
Ais:

普通工作

那么我做错了什么呢?您如何选择具有较低openprice的OP_BUY?我甚至试过不使用 "Dist"...


if ( CheckFirstOP(OP_BUY) > 1) {      
      for(int i = OrdersTotal() - 1; i >= 0; i--) {
          OrderSelect( i, SELECT_BY_POS, MODE_TRADES);
          if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber || OrderType() != OP_BUY) continue;     
          double Price = OrderOpenPrice();
          if ( Price < Price), Digits) {                                            
             int Ticket = OrderTicket();           
             double Lot = OrderLots();                          
             OrderClose( Ticket, Lot, OrderClosePrice(), 3); 
         }    
      }   
   }
without any results
[删除]  

这一行 "if (Price < Price), Digits) "的意图是什么?

对我来说,这看起来很疯狂。


CB

 
cloudbreaker:

这一行 "if (Price < Price), Digits) "的意图是什么?

对我来说,这看起来很疯狂。

不仅如此。

这句话在编译时怎么可能不出错,因为少了一个左括号。

 
Ais:

人类都会犯错

如果(a_human_made_a_mistake=true)

{human_learn_next_lesson();}。

否则

{reincarnate_as_plant=true;}。

 
meikel:

{human_learn_next_lesson();}。

如果我们有MT5就好了。那么我们就可以用human->learnNextLesson()来代替。

 
jjc:

如果我们有MT5就好了。那么我们就可以用human->learnNextLesson()来代替。

我从来没有熟悉过OOP。

我讨厌这样。

在这种情况下,我拒绝学习...;-)

this->repeat->this->repeat->this->repeat->this->repeat->this->repeat->this->repeat->this。