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

 
Vladimir Pastushak:
我如何以编程方式了解账户类型?对冲还是净值化?
   if(m_account.MarginMode()!=ACCOUNT_MARGIN_MODE_RETAIL_HEDGING)
     {
      Alert("Only Hedging!");
      return(INIT_FAILED);
     }
 

或者像这样

帐户信息样本

   m_label_info[3].Description(m_account.MarginModeDescription());

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

//+------------------------------------------------------------------+
//|                                        MarginModeDescription.mq5 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#include <Trade\AccountInfo.mqh>
CAccountInfo      m_account;     // account info wrapper
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   string Pr= m_account.MarginModeDescription();
   Alert(Pr);
  }
//+------------------------------------------------------------------+
 
请帮助我找到一个EA(脚本),它可以将虚拟挂单的网格与指定的参数放在一起,或者在指定的方向上以指定的方式开出订单(一个接一个)。
 

请告诉我错误在哪里。

      for(int s=OrdersTotal()-1; s>=0; s--)          
         {
           if(o_orderInfo.SelectByIndex(s)) 
           if(o_orderInfo.OrderType()==ORDER_TYPE_SELL_STOP)
             {                 
               count_sell_stop++;
             }
         }  

      for(int s1=PositionsTotal()-1; s1>=0; s1--)          
         {
           if(o_orderInfo.SelectByIndex(s1)) 
           if(o_orderInfo.OrderType()==ORDER_TYPE_SELL)
             {                 
               count_sell++;
             }
         }  
         
      if(count_sell == 0 && count_sell_stop == 0)
         {
            sellstop_req3.action       = TRADE_ACTION_PENDING;
            sellstop_req3.symbol       = _Symbol;
            sellstop_req3.volume       = NormalizeDouble(lot_v, 2);
            sellstop_req3.price        = SymbolInfoDouble(sellstop_req3.symbol, SYMBOL_ASK) - 100*_Point;
            sellstop_req3.sl           = sellstop_req3.price + 110*_Point;
            sellstop_req3.type         = ORDER_TYPE_SELL_STOP;
            sellstop_req3.type_filling = ORDER_FILLING_RETURN;
            sellstop_req3.expiration   = ORDER_TIME_GTC;
            
            OrderSend(sellstop_req3, sellstop_res3);
         }
SELL_STOP - 订单被计算,但SELL不希望这样。根据该算法,如果没有,就下SELL_STOP订单,如果至少有一个,就不下订单。
 
Fergert Фергерт:

请告诉我错误在哪里。

SELL_STOP - 订单被计算在内,但SELL不想要。根据该算法,如果没有,就下SELL_STOP订单,如果至少有一个,就不下订单

不要把LOCAL ORDERPOSITION 混为一谈。

//+------------------------------------------------------------------+
//|                                                     Script 1.mq5 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//---
#include <Trade\PositionInfo.mqh>
#include <Trade\OrderInfo.mqh>
//---
CPositionInfo  m_position;                   // object of CPositionInfo class
COrderInfo     m_order;                      // object of COrderInfo class
//---
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   int count_buys          = 0.0;
   int count_sells         = 0.0;
   int count_buy_limits    = 0.0;
   int count_sell_limits   = 0.0;
   int count_buy_stops     = 0.0;
   int count_sell_stops    = 0.0;
//---
   for(int i=PositionsTotal()-1; i>=0; i--)
      if(m_position.SelectByIndex(i)) // selects the position by index for further access to its properties
        {
         if(m_position.PositionType()==POSITION_TYPE_BUY)
            count_buys++;
         else
            if(m_position.PositionType()==POSITION_TYPE_SELL)
               count_sells++;
        }
//---
   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.OrderType()==ORDER_TYPE_BUY_LIMIT)
            count_buy_limits++;
         else
            if(m_order.OrderType()==ORDER_TYPE_SELL_LIMIT)
               count_sell_limits++;
            else
               if(m_order.OrderType()==ORDER_TYPE_BUY_STOP)
                  count_buy_stops++;
               else
                  if(m_order.OrderType()==ORDER_TYPE_SELL_STOP)
                     count_sell_stops++;
        }
//--- you code
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
附加的文件:
Script_1.mq5  5 kb
 
Vladimir Karputov:

不要把REMOTE ORDERPOSITION 混淆。

谢谢你))。明白了...
 
我不明白onCalculate函数的 第二个变体中的参数begin有什么作用。
每次调用onCalculate函数时,它都等于0。
,我通过print函数输出begin的值。
参考书上说,开始是 "有意义的数据开始的地方"。这并没有告诉我什么。
 
MisterRight:
我不明白onCalculate函数的 第二个变体中的参数begin负责什么。每次调用onCalculate函数时,它都等于0。 ,我通过print函数使开始值输出。参考书上说,开始是 "有意义的数据开始的地方"。这并没有告诉我什么。


请看实例中的开放指标代码。

 
Mikhail Mishanin:

看一下例子中的开放指标代码。

我看了看。总是开始=0。

在这里,我从AMA指标中提取了一段代码

如果(begin!=0)

PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtPeriodAMA+begin)。


如果条件begin!=0永远不为真,这段代码应该告诉我什么

 
你能告诉我用什么来计算历史上的关闭订单吗?我是这样试的:

HistorySelect(0,TimeCurrent());

Alert("Количество ордеров в истории:  ",HistoryOrdersTotal());
它最后给出了一些废话,比封闭的订单多得多。
原因: