MQL4、MQL5に関する初心者からの質問、アルゴリズムやコードに関するヘルプ、ディスカッションなど。 - ページ 1293

 
Aleksei Stepanenko:

ある直線上の2点から、その直線上の任意の3点目の将来の価格も求めることができる(逆もまたしかり)。

ありがとうございました。試してみます。

P.S. 唯一のもの。ぱっと見ではわからない。MT4のExpert Advisorで、動作するのでしょうか?

 
専門家の皆さん、こんにちは。インジケーターの修正に協力してほしい。指標の本質は以下の通りです。直前のバーに対する値上がりの値を計算する。ゼロにはスターバーが必要です。つまり、始値は終値と同じです。コンパイル時はエラーなし、テスト時は80 20文字の行でエラーになります。また、信号線の 引き方も間違っています。しかし、これがメインバッファの計算を誤らせる原因になっていると思うのです。修正できるよう、よろしくお願いします。
//+------------------------------------------------------------------+
//|                                                         MSBB.mq4 |
//|                        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"
#property strict

#include <MovingAverages.mqh>

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1  clrGreen
#property indicator_color2  clrRed
#property  indicator_width1  1
input int            InpMSBBPeriod=3;        // Period
input ENUM_MA_METHOD InpMSBBMethod=MODE_SMA;  // Method
//--- indicator buffers
double         ExtMSBBBuffer[];
double         ExtTempBuffer[];
double         ExtPriceBuffer[];
double         ExtSignalBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
  {
//--- indicator buffers mapping
   IndicatorDigits(Digits-2);
//--- drawing settings
   IndicatorBuffers(4);
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0,ExtMSBBBuffer);
   SetIndexBuffer(1,ExtSignalBuffer);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(2,ExtTempBuffer);
   SetIndexBuffer(2,ExtPriceBuffer);
   SetIndexDrawBegin(1,InpMSBBPeriod);
//--- name for DataWindow and indicator subwindow label
   IndicatorShortName("MSBB("+IntegerToString(InpMSBBPeriod)+")");
   SetIndexLabel(0,"MSBB");
   SetIndexLabel(1,"Signal");
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   int    i;//limit;
//------
   if(rates_total<=InpMSBBPeriod || InpMSBBPeriod<=2)
      return(0);
   /*//--- counting from 0 to rates_total
      ArraySetAsSeries(ExtMSBBBuffer,false);
      ArraySetAsSeries(ExtSignalBuffer,false);
      ArraySetAsSeries(open,false);
      ArraySetAsSeries(high,false);
      ArraySetAsSeries(low,false);
      ArraySetAsSeries(close,false);*/
//---
  // limit=rates_total-prev_calculated;
   //if(prev_calculated>0)
     // limit++;
//--- typical price and its moving average
   for(i=0; i<rates_total; i++)
     {
      ExtTempBuffer[i] = NormalizeDouble((close[i]-open[i])/Point(),2);
      ExtPriceBuffer[i] = NormalizeDouble((close[i+1]-open[i+1])/Point(),2);
      //ExtMSBBBuffer[i]=price_open+ExtTempBuffer[i];
      //Print("ExtPriceBuffer[i] = ", ExtPriceBuffer[i]);
      if(ExtTempBuffer[i]==0)
         ExtMSBBBuffer[i]=0.0;
      if(ExtPriceBuffer[i]>0 && ExtTempBuffer[i]>0)
        {
         double price_open = NormalizeDouble((open[i]-open[i+1])/Point(),2);
         double price_close = NormalizeDouble((close[i]-close[i+1])/Point(),2);
         if((price_open<0 && price_close>0)||(price_open>0 && price_close<0))
            ExtMSBBBuffer[i] = 0.0;
         if((price_open<0 && price_close<0)||(price_open>0 && price_close>0))
            ExtMSBBBuffer[i]=ExtTempBuffer[i]+price_open;
        }
      if(ExtPriceBuffer[i]>0 && ExtTempBuffer[i]<0)
        {
         double price_open = NormalizeDouble((open[i]-close[i+1])/Point(),2);
         double price_close = NormalizeDouble((close[i]-open[i+1])/Point(),2);
         if((price_open<0 && price_close>0)||(price_open>0 && price_close<0))
            ExtMSBBBuffer[i] = 0.0;
         if((price_open>0 && price_close>0)||(price_open<0 && price_close<0))
            ExtMSBBBuffer[i]=ExtTempBuffer[i]+price_open;
        }
      if(ExtPriceBuffer[i]<0 && ExtTempBuffer[i]<0)
        {
         double price_open = NormalizeDouble((open[i]-open[i+1])/Point(),2);
         double price_close = NormalizeDouble((close[i]-close[i+1])/Point(),2);
         if((price_open<0 && price_close>0)||(price_open>0 && price_close<0))
            ExtMSBBBuffer[i]=0.0;
         if((price_open<0 && price_close<0)||(price_open>0 && price_close>0))
            ExtMSBBBuffer[i]=ExtTempBuffer[i]+price_open;
        }
      if(ExtPriceBuffer[i]<0 && ExtTempBuffer[i]>0)
        {
         double price_open = NormalizeDouble((open[i]-close[i+1])/Point(),2);
         double price_close = NormalizeDouble((close[i]-open[i+1])/Point(),2);
         if((price_open>0 && price_close<0)||(price_open<0 && price_close>0))
            ExtMSBBBuffer[i]=0.0;
         if((price_open>0 && price_close>0)||(price_open<0 && price_close<0))
            ExtMSBBBuffer[i]=ExtTempBuffer[i]+price_open;
        }
      //--- signal line counted in the 2-nd buffer
      //ExtSignalBuffer[i]=iMAOnArray(ExtMSBBBuffer,0,InpMSBBPeriod,0,InpMSBBMethod,0);
      SimpleMAOnBuffer(rates_total,prev_calculated,1,InpMSBBPeriod+2,ExtMSBBBuffer,ExtSignalBuffer);
      Print ("ExtSignalBuffer = ", ExtSignalBuffer[i]);
      //--- done
     }
   /* if(ExtPriceBuffer[i]>0||ExtPriceBuffer[i]<0)
     {
      ExtMSBBBuffer[i] = ExtPriceBuffer[i]+ExtTempBuffer[i];
      Print("ExtMSBBBuffer[i] = ", ExtMSBBBuffer[i]);
     }
   if(ExtPriceBuffer[i]==0)
     {
      ExtMSBBBuffer[i] = 0.0;
      Print("ExtMSBBBuffer[i] = ", ExtMSBBBuffer[i]);
     }
   }*/
//---
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
 
単体テストが行われる現地代理店の番号を調べるにはどうしたらいいですか?
 

こんにちは。

EAでお願いできますか?

30レベルと70レベルからのRSIシグナルで適切な方向にトレードを行い、グリッドを作成します。

ストップロス%のようなものが入っているのですが、時々注文がぶら下がっていて、手動で閉じるか、預けたものを売るまで閉じません。

すなわち、このような注文は、価格がすでに5000ピップス以上動いているにもかかわらず、まだ赤字でぶら下がっているときに開かれます。

エラーを見つける必要があります。これが不可能な場合、EAにピップ単位でストップロスを挿入する必要があります。

2つのEAを1つにまとめてみたが、私のスキルではうまくいかなかった。

ファイル:
 

こんにちは。ヒントを教えてください。最後のティックで通過した点数を取得する必要があります。でも、手に入らないんです。

#property indicator_chart_window
#property indicator_buffers 1
double ExtMapBuffer[];
double dOldPriceEURUSD, dNewPriceEURUSD;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   IndicatorDigits(5);
   SetIndexBuffer(0, ExtMapBuffer);
   SetIndexEmptyValue(0,0.0);        
   dOldPriceEURUSD=iClose("EURUSD",0,0);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   dNewPriceEURUSD=iClose("EURUSD",0,0);
   double delta=NormalizeDouble(dOldPriceEURUSD-dNewPriceEURUSD,5);
   ExtMapBuffer[0] = delta;
   Alert(delta);     
   dOldPriceEURUSD=dNewPriceEURUSD;
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
Forallf:

こんにちは。ヒントを教えてください。最後のティックで通過した点数を取得する必要があります。でも、うまくいかないんです。

これを試してみてください。

//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2018, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 1
double ExtMapBuffer[];
double dOldPriceEURUSD, dNewPriceEURUSD;
double delta;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   IndicatorDigits(5);
   SetIndexBuffer(0, ExtMapBuffer);
   SetIndexEmptyValue(0, 0.0);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   dNewPriceEURUSD = NormalizeDouble(Close[0],Digits);
   delta = dOldPriceEURUSD - dNewPriceEURUSD;
   Comment(" delta = ", DoubleToStr(delta ,5));
   dOldPriceEURUSD = dNewPriceEURUSD;
   ExtMapBuffer[0] = delta;
 Alert(" delta = ", DoubleToStr(delta ,5));
   return(rates_total);
  }
//+------------------------------------------------------------------+
Domain Registration Services
  • www.registryrocket.com
Get a unique domain name plus our FREE value-added services to help you get the most from it. Call it a "dot-com name," a URL, or a domain. Whatever you call it, it's the cornerstone of your online presence, and we make getting one easy. Simply enter the name you want in the search field above, and we'll tell you instantly whether the name is...
 
Александр:

この方法で試してみてください。

ありがとうございました。
 

また、こんにちは。
初心者の質問にご注意ください。
テスターではExpert Advisorが注文を開けないので、コードのエラーを指摘する必要があります...。
コンパイラはエラーも警告も表示しないし、同じジャーナルでもエラーは 出ないし...。

extern double Lot=0.1;            
extern int Slippage = 3;
extern int TakeProfit = 30;
extern int StopLoss   = 30;
extern int MA_Smoth_S = 60;
extern int MA_Smoth_B = 12;
extern int MA_Simpl_S = 3;
extern int MA_Simpl_B = 1;
int start()
         {
          //___________________

          double SL, TP;
          int MA_Simpl_S_Cl,      //
              MA_Simpl_S_Op,      //
              MA_Simpl_B_Cl,      //
              MA_Simpl_B_Op;      //
         
          //________________

          //------------

          SL=NormalizeDouble(Bid-StopLoss*Point,Digits);      // 
          TP=NormalizeDouble(Bid+TakeProfit*Point,Digits);    //
          SL = StopLoss;                        
          TP = TakeProfit;
          if(_Digits==5 || _Digits==3)
            {
             SL = SL*10;
             TP = TP*10;
             return(0);
            }
            
          //_______________

          MA_Smoth_S = iMA(NULL,0,60,0,MODE_SMMA,PRICE_CLOSE,1);
          MA_Smoth_B = iMA(NULL,0,12,0,MODE_SMMA,PRICE_CLOSE,1);
          MA_Simpl_S = iMA(NULL,0,3,0,MODE_SMA,PRICE_CLOSE,1);
          MA_Simpl_B = iMA(NULL,0,1,0,MODE_SMA,PRICE_CLOSE,1);
          MA_Simpl_S_Cl = iMA(NULL,0,3,0,MODE_SMA,PRICE_CLOSE,1);
          MA_Simpl_S_Op = iMA(NULL,0,3,0,MODE_SMA,PRICE_CLOSE,2);
          MA_Simpl_B_Cl = iMA(NULL,0,1,0,MODE_SMA,PRICE_CLOSE,1);
          MA_Simpl_B_Op = iMA(NULL,0,1,0,MODE_SMA,PRICE_CLOSE,2);
          
          //______________________

          while(MA_Smoth_B > MA_Smoth_S)
               {
                if(MA_Simpl_B_Op < MA_Simpl_S_Op && MA_Simpl_B_Cl > MA_Simpl_S_Cl)
                  {
                   bool check = OrderSend(Symbol(),OP_BUY,Lot,NormalizeDouble(Ask, Digits),Slippage,SL,TP,"Buy",0,0,clrGreen);
                   return(0);
                  }
               }
               
          //_____________________

          while(MA_Smoth_S > MA_Smoth_B)
               {
                if(MA_Simpl_B_Op > MA_Simpl_S_Op && MA_Simpl_B_Cl < MA_Simpl_S_Cl)
                  {
                   check = OrderSend(Symbol(),OP_SELL,Lot,NormalizeDouble(Ask, Digits),Slippage,SL,TP,"Sell",0,0,clrRed);
                   return(0);
                  }   
               }     
          return(0);
         } 
 

皆さん、ごきげんよう。

mql4からmql5への移行を試みています。

Question: なぜmql5 は、現在の価格と Hay 変数の値の差ではなく、2.99999999 - (minus) 05 のような、私にはわからない式を計算し表示 するのですか(mql4 のように)?

mql5でこれらの値の差を正しく計算 させるにはどうしたらよいでしょうか?NormalizeDouble()を使って全ての値を正規化 しましたが、上記の値では

の値は変更されずに表示されます。どちらの値もドブルタイプであるため、これは不思議なことです

皆さん、ありがとうございました。

#include <Trade\Trade.mqh>                                        
int tm, s1 ;                                    
double P=SymbolInfoDouble(Symbol(),SYMBOL_BID),S=P+0.0030,T=P-0.0010,Lou,Hay,DL=0.0030; 
CTrade            m_Trade;                 //структура для выполнения торговых операций
//=============================================================================================================
void OnTick()
  {
Print("===============",SymbolInfoDouble(Symbol(),SYMBOL_BID) - Hay,"===Hay====",Hay,"===SymbolInfoDouble()====",SymbolInfoDouble(Symbol(),SYMBOL_BID)); 

m_Trade.Sell(0.1,Symbol(),P,S,T);
Hay=SymbolInfoDouble(Symbol(),SYMBOL_BID);

   }


 
MrBrooklin:

Ivanさん、こんにちは。ここでは誰も初心者を叱ったりしませんし、逆に助けようとします。私自身は初心者です。さて、ご質問の件ですが。ポジションをオープンするためのチェックを行ったが、チェックを 止め忘れたために、複数のポジションがオープンしてしまう。演算子returnは、呼び出したプログラムに制御を戻します(MQL5 Referenceより引用)。

Expert Advisorのコードにreturnを 追加する必要があります(黄色でハイライトされています)。

また、コンパイラが警告を出さないように、買いポジションと売りポジションの開始条件に、OrderSend(mrequest,mresult) をチェックする条件をもう一つ追加する必要があります。この条件はif 演算子で定義され、次のようになります。

もうひとつ、考慮すべきことがあります。23:59:59に取引日をまたぐと、開いたポジションが閉じられ、00:00:00に新しいポジションが開かれることがあります。これはいわゆるロールオーバー・クローズとロールオーバー・オープンと呼ばれるもので、特定のFX業者とその取引条件によって異なります。フォーラムを検索してください、どこかに情報がありますよ。

敬具 ウラジミール


こんにちは。

ご返信ありがとうございました。しかし、私はなぜ私はオペレータのリターンが 必要なのか理解できません。このコードには2つの条件があり、そのうちの1つが満たされたときにチェックを停止する必要があります。

//--- есть ли открытые позиции?
   bool Buy_opened=false;  // переменные, в которых будет храниться информация 
   bool Sell_opened=false; // о наличии соответствующих открытых позиций

   if(PositionSelect(_Symbol)==true) // есть открытая позиция
     {
      if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)  // если истина, выполняем условие 1
        {
         Buy_opened=true;  //это длинная позиция
        }
      else if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)  // иначе выполняем условие 2
        {
         Sell_opened=true; // это короткая позиция
        }
     }
それとも違うのでしょうか?