初学者的问题 MQL5 MT5 MetaTrader 5 - 页 863

 
你能显示打印最近的买入止损点和最近的卖出止损点价格 的代码吗
 
ilyav:
你能显示打印最近的买入止损点和最近的卖出止损点的价格 的代码吗?

只是价格?它是用来做什么的?并破译 "最近的 "一词--对谁、什么......。

 
Vladimir Karputov:

只是价格?它是用来做什么的?并破译 "最近的 "一词--对谁、什么......。

只是价格。

看。

我们现在有10个离当前价格 100点的买入止损。

我们现在有10个卖出止损点,距离当前价格100点。

我需要在Print中显示相对于当前价格最近的买入止损和最近的卖出止损的价格。

我试图这样做,但没有成功。

最近的买入止损点的价格被正确输出,但最近的卖出止损点的价格却因某种原因被输出。

这个函数m_order.PriceOpen();总是显示买入停止价格尽管我要求它在买入止损请求后给我卖出止损的价格。

这样做是为了进一步的逻辑------。

我把最近的买入止损点的价格和最近的卖出止损点的价格除以2。

专家顾问将根据获得的数字继续工作。

完整的功能是

//+------------------------------------------------------------------+
void TradeMode3()
  {
   int TotalGridBuyOrders=0;
   Print(__FUNCTION__);
   for(int i=OrdersTotal()-1;i>=0;i--) // returns the number of current orders
      if(m_order.SelectByIndex(i)) // selects the pending order by index for further access to its properties
         if(m_order.Symbol()==m_symbol.Name() && m_order.Magic()==m_magic && m_order.OrderType()==ORDER_TYPE_BUY_STOP)
            TotalGridBuyOrders++;
   Print("Количество buy ордеров grid ",TotalGridBuyOrders);
   if(TotalGridBuyOrders>=1)
     {
      grid_buy_price_memory=m_order.PriceOpen();
      Print("Цена ближайшего buy grid ордера: ",grid_buy_price_memory);

      int TotalGridSellOrders=0;
      Print(__FUNCTION__);
      for(int i=OrdersTotal()-1;i>=0;i--) // returns the number of current orders
         if(m_order.SelectByIndex(i)) // selects the pending order by index for further access to its properties
            if(m_order.Symbol()==m_symbol.Name() && m_order.Magic()==m_magic && m_order.OrderType()==ORDER_TYPE_SELL_STOP)
               TotalGridSellOrders++;
      Print("Количество sell ордеров grid ",TotalGridSellOrders);
      if(TotalGridSellOrders>=1)
        {
         grid_sell_price_memory=m_order.PriceOpen();
         Print("Цена ближайшего sell grid ордера: ",grid_sell_price_memory);
        }
     }
  }
//+------------------------------------------------------------------+
 

现在我试着改变代码。

//+------------------------------------------------------------------+
void TradeMode3()
  {
     {
      int TotalGridBuyOrders=0;
      Print(__FUNCTION__);
      for(int i=OrdersTotal()-1;i>=0;i--) // returns the number of current orders
         if(m_order.SelectByIndex(i)) // selects the pending order by index for further access to its properties
            if(m_order.Symbol()==m_symbol.Name() && m_order.Magic()==m_magic && m_order.OrderType()==ORDER_TYPE_BUY_STOP)
               TotalGridBuyOrders++;
      Print("Количество buy ордеров grid ",TotalGridBuyOrders);
      if(TotalGridBuyOrders>=1)
        {
         double grid_buy_price_memory=m_order.PriceOpen();
         Print("Цена ближайшего buy grid ордера: ",grid_buy_price_memory);
        }
     }
     {
      int TotalGridSellOrders=0;
      Print(__FUNCTION__);
      for(int i=OrdersTotal()-1;i>=0;i--) // returns the number of current orders
         if(m_order.SelectByIndex(i)) // selects the pending order by index for further access to its properties
            if(m_order.Symbol()==m_symbol.Name() && m_order.Magic()==m_magic && m_order.OrderType()==ORDER_TYPE_SELL_STOP)
               TotalGridSellOrders++;
      Print("Количество sell ордеров grid ",TotalGridSellOrders);
      if(TotalGridSellOrders>=1)
        {
         double grid_sell_price_memory=m_order.PriceOpen();
         Print("Цена ближайшего sell grid ордера: ",grid_sell_price_memory);
        }
     }
  }
//+------------------------------------------------------------------+

没有变化。只输出买入停止价格

 
ilyav:

现在我试着改变代码。

没有变化。它只显示买入停止价格。

我们先来写代码。我首先要说的是,买入止损和卖出止损的搜索功能需要通过价格--否则你怎么搜索? ...

另外,我们需要澄清:"最近的"--高于或低于价格?还是只是设定的价格和挂单 之间的差异?

 
Vladimir Karputov:

让我们先把它写出来。我首先要说的是,买入止损和卖出止损的搜索功能需要通过价格--否则你怎么搜索? ...

我是这样做的。

for(int i=OrdersTotal()-1;i>=0;i--) // returns the number of current orders
         if(m_order.SelectByIndex(i)) // selects the pending order by index for further access to its properties
            if(m_order.Symbol()==m_symbol.Name() && m_order.Magic()==m_magic && m_order.OrderType()==ORDER_TYPE_SELL_STOP)
               TotalGridSellOrders++;

该函数完美地输出了当前卖出止损的数量。

接下来,我们选择了最接近的卖出止损。我们要求显示其价格并打印出来

double grid_sell_price_memory=m_order.PriceOpen();    
Print("Цена ближайшего sell grid ордера: ", grid_sell_price_memory);

它写在帮助中。

COrderInfo类

价格开放

获取订单价格。

doublePriceOpen()const

返回的值

订单开盘价。

注意事项

使用Select(按票数)SelectByIndex(按索引)方法 预先选择访问的顺序。


有什么问题吗?我们已经选择了订单。要求提供安装的价格。

还是我误解了什么?如果我做得不对,为什么会出现买入止损价?

 
Vladimir Karputov:

另外,我们需要澄清:"最近的 "是指价格的顶部还是底部?还是只是设定的价格和挂单 之间的差异?

这里是我需要的买入止损和卖出止损的价格

 
ilyav:

这里是我需要的买入止损和卖出止损的价格

该功能从价格 "price "中搜索最近的上方买入止损点,从价格 "price "中搜索最近的下方卖出止损点。

//+------------------------------------------------------------------+
//| Calculate all pending orders                                     |
//+------------------------------------------------------------------+
void CalculateAllPendingOrders(const double price,double &price_nearest_buy_stop,double &price_nearest_sell_stop)
  {
   price_nearest_buy_stop  = 0;
   price_nearest_sell_stop = 0;
   double diff_buy_stop    = DBL_MAX;
   double diff_sell_stop   = DBL_MAX;

   for(int i=OrdersTotal()-1;i>=0;i--) // returns the number of current orders
      if(m_order.SelectByIndex(i))     // selects the pending order by index for further access to its properties
         if(m_order.Symbol()==m_symbol.Name() && m_order.Magic()==m_magic)
           {
            if(m_order.OrderType()==ORDER_TYPE_BUY_STOP)
              {
               if(m_order.PriceOpen()-price>0.0 && m_order.PriceOpen()-price<diff_buy_stop)
                 {
                  diff_buy_stop           = m_order.PriceOpen()-price;
                  price_nearest_buy_stop  = m_order.PriceOpen();
                 }
              }
            else if(m_order.OrderType()==ORDER_TYPE_SELL_STOP)
              {
               if(price-m_order.PriceOpen()>0.0 && price-m_order.PriceOpen()<diff_sell_stop)
                 {
                  diff_sell_stop          = price-m_order.PriceOpen();
                  price_nearest_sell_stop = m_order.PriceOpen();
                 }
              }
           }
  }
 

现在是另一个问题)

我曾经这样调用我的函数--

//|  Выбран режим торговли 3 ? Тогда торгуем его    
      if(РежимТорговли==3)
        {
         TradeMode3();
        }

插入了你的代码,并将我的函数改为

 //|  Выбран режим торговли 3 ? Тогда торгуем его    
      if(РежимТорговли==3)
        {
        CalculateAllPendingOrders();
        }
     

现在编译时出现了一个错误(

'CalculateAllPendingOrders' - wrong parameters count
 
ilyav:

现在是另一个问题)

我曾经这样调用我的函数--

插入了你的代码,并将我的函数改为

现在编译时出现了一个错误(

你必须向函数传递一个PRICE,围绕这个PRICE 来搜索挂单

除了这个价格,你还必须通过两个变量

void CalculateAllPendingOrders(const double price,double &price_nearest_buy_stop,double &price_nearest_sell_stop)