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

 
Vladimir Karputov:

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

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

我放弃了,你是否有一个现成的专家顾问,可以打印出我在截图中用箭头显示的那些挂单的价格?

我不明白为什么这个函数不通过任何价格就能工作。

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);

???

 
ilyav:

我放弃了,难道你没有一个现成的专家顾问,可以输出打印我在截图中用箭头显示的那些订单的价格?

我给了你一个现成的功能。你需要在其中通过。

  • 当前价格
  • 一个变量,其中将写入下一个买入止损的价格。
  • 一个变量,下一个卖出止损点的价格将被写入其中。

你有什么不明白的?

 
我明白了。显然,这不是我的事。
 
ilyav:

我放弃了,难道你没有一个现成的专家顾问,可以输出我在截图中用箭头显示的那些挂单的价格打印吗?

我不明白为什么这个功能可以工作而不发送任何价格。

???

你展示的代码是不可行的--至少它不能编译--因为它有一个不匹配的开括号和闭括号。其次是=破碎的逻辑。

 
Vladimir Karputov:

你所展示的是不可行的代码--至少它不能被编译--因为它有一个不匹配的开括号和闭括号。其次是=破碎的逻辑。

我重写了你的代码。

但它产生的挂单离价格很远

void TradeMode3()
  {
   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()-price1>0.0 && m_order.PriceOpen()-price1<diff_buy_stop)
                 {
                  diff_buy_stop           = m_order.PriceOpen()-price1;
                  price_nearest_buy_stop  = m_order.PriceOpen();
                 
                 }
               Print("buy : ",price_nearest_buy_stop);
                return;  
              }
              
               
            else if(m_order.OrderType()==ORDER_TYPE_SELL_STOP)
              {
               if(price1-m_order.PriceOpen()>0.0 && price1-m_order.PriceOpen()<diff_sell_stop)
                 {
                  diff_sell_stop          = price1-m_order.PriceOpen();
                  price_nearest_sell_stop = m_order.PriceOpen();
                 }
                 Print("sell : ",price_nearest_sell_stop);
                 return;
              }
           }
  }
  
 
 
ilyav:

我重写了你的代码。

但它发出的吊坠离价格较远

打印应该在OrdersTotal 循环之后进行。

那么什么是price1呢?你如何得到它?
 

而在这个版本中,它打印出了所有可用的

//+------------------------------------------------------------------+
//| Calculate all pending orders                                     |
//+------------------------------------------------------------------+
void TradeMode3()
  {
   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()-price1>0.0 && m_order.PriceOpen()-price1<diff_buy_stop)
                 {
                  diff_buy_stop           = m_order.PriceOpen()-price1;
                  price_nearest_buy_stop  = m_order.PriceOpen();
                 }
                 Print("buy : ",price_nearest_buy_stop);
                 
              }
            else if(m_order.OrderType()==ORDER_TYPE_SELL_STOP)
              {
               if(price1-m_order.PriceOpen()>0.0 && price1-m_order.PriceOpen()<diff_sell_stop)
                 {
                  diff_sell_stop          = price1-m_order.PriceOpen();
                  price_nearest_sell_stop = m_order.PriceOpen();
                 }
                 Print("sell : ",price_nearest_sell_stop);
                 
              }
           }
  }
 
Vladimir Karputov:

打印必须在OrdersTotal 循环之后进行。

那么什么是price1呢?你如何得到它?
//|  Выбран режим торговли 3 ? Тогда торгуем его    

      if(РежимТорговли==3)

        {

        price1=m_symbol.Bid();

        TradeMode3();

在EA的标题中,我写道

double price1;
double price_nearest_buy_stop;
double price_nearest_sell_stop;

如果一切正确,这里是最终的变体

//+------------------------------------------------------------------+
//| Calculate all pending orders                                     |
//+------------------------------------------------------------------+
void TradeMode3()
  {
   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()-price1>0.0 && m_order.PriceOpen()-price1<diff_buy_stop)
                 {
                  diff_buy_stop           = m_order.PriceOpen()-price1;
                  price_nearest_buy_stop  = m_order.PriceOpen();
                 }

              }
            else if(m_order.OrderType()==ORDER_TYPE_SELL_STOP)
              {
               if(price1-m_order.PriceOpen()>0.0 && price1-m_order.PriceOpen()<diff_sell_stop)
                 {
                  diff_sell_stop          = price1-m_order.PriceOpen();
                  price_nearest_sell_stop = m_order.PriceOpen();
                 }

              }

           }
   Print("Цена ближнего SELL_STOP : ",price_nearest_sell_stop);
   Print("Цена ближнего BUY_STOP : ",price_nearest_buy_stop);
  }
//+------------------------------------------------------------------+

一切似乎都在运作。如果有任何错误,请告诉我。非常感谢你。

 

请帮助我解决这个问题。

假设我有一个当前的时间框架M1,我需要知道任何上层TF的给定条N的时间,这个小时可能不是60分钟,而是45或其他时间,此外还有周末,我需要知道当前TF的最后一个条的日期,从任何TF。

如何实施?

 
ilyav:

而在顾问的标题中写道

如果一切正确,这里是最终的变体

一切似乎都在运作。如果有任何错误,请告诉我。非常感谢你。

行前

price1=m_symbol.Bid();

你需要更新报价。

if(!RefreshRates())
   return;