初心者の方からの質問 MQL5 MT5 MetaTrader 5 - ページ 1294

 
Vladimir Pastushak:
プログラム上でアカウントタイプを把握するには?ヘッジかネッティングか?
   if(m_account.MarginMode()!=ACCOUNT_MARGIN_MODE_RETAIL_HEDGING)
     {
      Alert("Only Hedging!");
      return(INIT_FAILED);
     }
削除済み  

あるいは、このように

AccountInfoSample

   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);
  }
//+------------------------------------------------------------------+
 
指定したパラメータで仮想保留注文のグリッドを置くか、指定した方向に指定したテイクで注文を(1つずつ)オープンする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はそれを望んでいない。アルゴリズムによれば、1つもなければSELL_STOP注文が出され、少なくとも1つあれば注文は出されない。
 
Fergert Фергерт:

どこにエラーがあるのか教えてください。

SELL_STOP - 注文はカウントされますが、SELLは望んでいません。アルゴリズムによれば、1つもなければSELL_STOP注文が出され、少なくとも1つあれば注文は 出されない。

LOCAL ORDERと POSITIONを 混同しないようにしましょう。

//+------------------------------------------------------------------+
//|                                                     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 ORDERと POSITIONを 混同しないでください。

ありがとうございました))了解...
 
onCalculate関数の 2番目のバリアントのパラメータbeginが何を担っているのかがわかりません。
onCalculate関数が呼ばれるたびに0になります。
print関数でbeginの値を出力していました。
参考書には、ビギニングは「意味のあるデータはここから始まる」と書かれている。これでは何もわからない。
 
MisterRight:
onCalculate関数の 2番目のバリアントのパラメータbeginが何を担っているのかがわかりません。onCalculate関数が呼ばれるたびに0になります。 print関数でbeginの値を出力するようにしました。参考書には、beginは「意味のあるデータはここから始まる」と書かれています。これでは何もわからない。


例題のオープンインジケーターコードを確認する。

 
Mikhail Mishanin:

例題のオープン・インジケータ・コードを見てください。

見たんです。常にbegin=0とする。

ここでは、AMAのインジケータからコードの一部を抜き出してみました。

if(begin!=0)

PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtPeriodAMA+begin);


また、begin!=0という条件が決して真で ない場合、このコードは何を伝えるべきでしょうか?

 
クローズした注文を履歴にカウントするには何を使うか教えてください。こんな感じで試してみました。

HistorySelect(0,TimeCurrent());

Alert("Количество ордеров в истории:  ",HistoryOrdersTotal());
クローズド・オーダーよりもずっと、最終的にはナンセンスなものを出してくるんです。