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

 
Alexey Viktorov:

mql5でも同じです。わずかに伸びているくらいです。私たちに必要なものではありませんか?

シンボリックトレードティック値

SYMBOL_TRADE_TICK_VALUE_PROFIT です。

二重

シンボル・トレード・チック・バリュー・プロフィット

利益の出るポジションの計算ティック値

二重

シンボル・トレード・チック・バリュー・ロス

負けポジションの1ティックの計算値

二重

シンボル・トレード・チック・サイズ

最低価格変更

二重

くっそー、俺馬鹿だからTICK_VALUEじゃなくてTICK_SIZEって入れ ちゃったよ・・・もう寝よっと。
 
みんな、どうしたんだ、助けてくれ!?
 
Alexey Viktorov:

まず目を引いたのは、バッファの配列です。

ビルドバッファは必ず順番に実行されなければならない。例えば、データバッファが2番と3番の場合、カラーバッファは 4番でなければならない(MUST)。

このエラーだけでない場合は、さらに調べます。

OK、説明書の中にそのような機能がありました、こちら。

MQL5リファレンスガイド / カスタムインジケータ / SetIndexBuffer
".....

boolSetIndexBuffer()
イントindex,// バッファのインデックス
doublebuffer[],// 配列
ENUM_INDEXBUFFER_TYPEdata_type//何が格納さ れるのか
);

パラメータ

インデックス

[in] インジケータ・バッファの番号。ナンバリングは0から始まります。この数値は、#property indicator_buffersで 宣言された値よりも小さくなければならない。

バッファ[]の

[in] カスタムインジケータープログラムで宣言された配列。

データ型

[in] インジケータ配列に格納されているデータの種類。デフォルトはINDICATOR_DATA(算出されたインジケータの値)です。INDICATOR_COLOR_INDEX 値を取ることもでき、その場合、このバッファは前のインジケータバッファの色のインデックスを格納する ために使用されます。プロパティ indicator_colorN の行で最大64色まで 指定可能です。INDICATOR_CALCULATIONSの 値は、このバッファがインジケータの中間計算に参加することを意味し、描画を目的としたものではありません。

 

やり直そうとしたら、さらにデタラメになった。ヒストグラムは完全に消え、ライン 表示ははっきり言っておかしくなった。シグナルの方は50以上でカットされ、メインの方はそれ以下でした。コードにそのような切り口はありません。

 
Artyom Trishkin:

ヒストグラムではなく、カラーバッファの扱い方を勉強するためのリンクをあげました。ヒストグラムから離れ、色彩をどう扱うかに集中する。

私はそれを勉強したが、何も新しい、どうやらそれは(私にとって新しい)もちろん、すべてのイニシエーションに明白である、自明である。上記のインデックス作成時のバッファの相互配置の機能以外、目新しいものは見つかりませんでした。このシークエンスに敬意を表して、さらにチープな写真を撮りました。

下記写真、添付ファイル

//+------------------------------------------------------------------+
//|                                       Stoch_HISTOGRAM_MQL5_4.mq5 |
//|                   Copyright 2009-2017, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"

//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 8
#property indicator_plots   3

#property indicator_type1   DRAW_COLOR_HISTOGRAM2
#property indicator_color1  clrGreen,clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1 

#property indicator_type1   DRAW_LINE       // основная
#property indicator_color1  clrLightSeaGreen
#property indicator_style1  STYLE_SOLID
#property indicator_width2  3 

#property indicator_type2   DRAW_LINE       // сигнальная
#property indicator_color2  clrYellow
#property indicator_style2  STYLE_SOLID
#property indicator_width3  2 

//--- input parameters
input int InpKPeriod=5;  // K period
input int InpDPeriod=3;  // D period
input int InpSlowing=3;  // Slowing

//--- indicator buffers
double    ColorHistogram_2Buffer1[]; 
double    ColorHistogram_2Buffer2[]; 
double    ColorHistogram_2Colors[];
double    ExtMainBuffer[];
double    ExtSignalBuffer[];
double    ExtHighesBuffer[];
double    ExtLowesBuffer[];
color     colors[]={clrRed,clrGreen};
int       cl;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
//--- indicator buffers mapping

   SetIndexBuffer(0,ColorHistogram_2Buffer1,INDICATOR_DATA);
   SetIndexBuffer(1,ColorHistogram_2Buffer2,INDICATOR_DATA);
   SetIndexBuffer(2,ColorHistogram_2Colors,INDICATOR_COLOR_INDEX);
   SetIndexBuffer(3,ExtMainBuffer,INDICATOR_DATA);
   SetIndexBuffer(4,ExtSignalBuffer,INDICATOR_DATA);
   SetIndexBuffer(5,ExtHighesBuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(6,ExtLowesBuffer,INDICATOR_CALCULATIONS);  
   
   //ArraySetAsSeries(ExtMainBuffer,true);
   //ArraySetAsSeries(ExtSignalBuffer,true);
   //ArraySetAsSeries(ExtHighesBuffer,true);
   //ArraySetAsSeries(ExtLowesBuffer,true);
   //ArraySetAsSeries(ColorHistogram_2Buffer1,true);
   //ArraySetAsSeries(ColorHistogram_2Buffer2,true);
   //ArraySetAsSeries(ColorHistogram_2Colors,true);
   
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0);
//--- set accuracy
   IndicatorSetInteger(INDICATOR_DIGITS,2);
//--- set levels
   IndicatorSetInteger(INDICATOR_LEVELS,3);
   IndicatorSetDouble(INDICATOR_LEVELVALUE,0,20);
   IndicatorSetDouble(INDICATOR_LEVELVALUE,1,50);
   IndicatorSetDouble(INDICATOR_LEVELVALUE,2,80);
//--- set maximum and minimum for subwindow 
   IndicatorSetDouble(INDICATOR_MINIMUM,0);
   IndicatorSetDouble(INDICATOR_MAXIMUM,100);
//--- name for DataWindow and indicator subwindow label
   IndicatorSetString(INDICATOR_SHORTNAME,"Stoch_HISTOGRAM("+(string)InpKPeriod+","+(string)InpDPeriod+","+(string)InpSlowing+")");
   PlotIndexSetString(3,PLOT_LABEL,"Main");
   PlotIndexSetString(4,PLOT_LABEL,"Signal");
   //PlotIndexSetString(2,PLOT_LABEL,"UP");
   //PlotIndexSetString(3,PLOT_LABEL,"LOW");
//--- sets first bar from what index will be drawn
   PlotIndexSetInteger(3,PLOT_DRAW_BEGIN,InpKPeriod+InpSlowing-2);
   PlotIndexSetInteger(4,PLOT_DRAW_BEGIN,InpKPeriod+InpDPeriod);
   PlotIndexSetInteger(5,PLOT_DRAW_BEGIN,InpKPeriod+InpSlowing-2);
   PlotIndexSetInteger(6,PLOT_DRAW_BEGIN,InpKPeriod+InpSlowing-2);
//--- initialization done
  }
//+------------------------------------------------------------------+
//| Stochastic Oscillator                                            |
//+------------------------------------------------------------------+
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,k,start;
//--- check for bars count
   if(rates_total<=InpKPeriod+InpDPeriod+InpSlowing)
      return(0);
//---
   start=InpKPeriod-1;
   if(start+1<prev_calculated) start=prev_calculated-2;
   else
     {
      for(i=0;i<start;i++)
        {
         ExtLowesBuffer[i]=0.0;
         ExtHighesBuffer[i]=0.0;
        }
     }
//--- calculate HighesBuffer[] and ExtHighesBuffer[]
   for(i=start;i<rates_total && !IsStopped();i++)
     {
      double dmin=1000000.0;
      double dmax=-1000000.0;
      for(k=i-InpKPeriod+1;k<=i;k++)
        {
         if(dmin>low[k])  dmin=low[k];
         if(dmax<high[k]) dmax=high[k];
        }
      ExtLowesBuffer[i]=dmin;
      ExtHighesBuffer[i]=dmax;
     }
//--- %K
   start=InpKPeriod-1+InpSlowing-1;
   if(start+1<prev_calculated) start=prev_calculated-2;
   else
     {
      for(i=0;i<start;i++) ExtMainBuffer[i]=0.0;
     }
//--- main cycle
   for(i=start;i<rates_total && !IsStopped();i++)
     {
      double sumlow=0.0;
      double sumhigh=0.0;
      for(k=(i-InpSlowing+1);k<=i;k++)
        {
         sumlow +=(close[k]-ExtLowesBuffer[k]);
         sumhigh+=(ExtHighesBuffer[k]-ExtLowesBuffer[k]);
        }
      if(sumhigh==0.0) ExtMainBuffer[i]=100.0;
         else ExtMainBuffer[i]=sumlow/sumhigh*100;
      if(ExtMainBuffer[i]>50){
         cl=1;
         ColorHistogram_2Buffer1[i]=50; 
         ColorHistogram_2Buffer2[i]=ExtMainBuffer[i]; 
         ColorHistogram_2Colors[i]=colors[cl];
     Print("ExtMainBuffer[i]=",ExtMainBuffer[i],
           " cl=",cl,
           " ColorHistogram_2Buffer1[i]=",ColorHistogram_2Buffer1[i],
           " ColorHistogram_2Buffer2[i]=",ColorHistogram_2Buffer2[i],
           " ColorHistogram_2Colors[i]=",ColorHistogram_2Colors[i]);
         } 
      if(ExtMainBuffer[i]<50){
         cl=0;
         ColorHistogram_2Buffer1[i]=ExtMainBuffer[i]; 
         ColorHistogram_2Buffer2[i]=50; 
         ColorHistogram_2Colors[i]=colors[cl];
     Print("ExtMainBuffer[i]=",ExtMainBuffer[i],
           " cl=",cl,
           " ColorHistogram_2Buffer1[i]=",ColorHistogram_2Buffer1[i],
           " ColorHistogram_2Buffer2[i]=",ColorHistogram_2Buffer2[i],
           " ColorHistogram_2Colors[i]=",ColorHistogram_2Colors[i]);
         } 
     }
//--- signal
   start=InpDPeriod-1;
   if(start+1<prev_calculated) start=prev_calculated-2;
   else
     {
      for(i=0;i<start;i++) ExtSignalBuffer[i]=0.0;
     }
   for(i=start;i<rates_total && !IsStopped();i++)
     {
      double sum=0.0;
      for(k=0;k<InpDPeriod;k++) sum+=ExtMainBuffer[i-k];
      ExtSignalBuffer[i]=sum/InpDPeriod;
     }
//--- OnCalculate done. Return new prev_calculated.
   return(rates_total);
  }
//+------------------------------------------------------------------+ 
ファイル:
 

こんにちは。

信頼できる」注文の開始(今のところ成行注文にしか興味がありません)のアルゴリズムはどこにあるのか、困っているので教えてください。

問題は、私の口座(Alpari)ではStopLevelとFreezeLevelのレベルがゼロで、これらのhttps://book.mql4.com/ru/appendix/limits の 制限だけを使用すると、買いのStopLossはBidレベルで設定でき、売りはAskレベルで設定できることになりますが、これは真実ではありません。この場合、OrderSend は "No price" エラー (ERR_OFF_QUOTES, コード 136) を返します。

同時に、ストップなしの取引や50ポイント以上のストップがかかっている取引も問題なく開く。

SlopLossの最小値が19pipsであることを経験的に知りました。このマージンをプログラムで決定する方法がわかりません。

 
これらのレベルは、始値からではなく、注文の終値から設定する必要があります。また、これらのレベルを設定する際の終値は、設定した値と同じであってはならない。
 
klok79:

こんにちは。

信頼できる」注文の開始(今のところ成行注文にしか興味がありません)のアルゴリズムはどこにあるのか、困っているので教えてください。

問題は、私の口座(Alpari)ではStopLevelとFreezeLevelのレベルがゼロで、これらのhttps://book.mql4.com/ru/appendix/limits の 制限だけを使用すると、買いのStopLossはBidレベルで設定でき、売りはAskレベルで設定できることになりますが、これは真実ではありません。この場合、OrderSend は "No price" エラー (ERR_OFF_QUOTES, コード 136) を返します。

同時に、ストップなしの取引や50ポイント以上のストップがかかっている取引も問題なく開く。

SlopLossの最小値が19pipsであることを経験的に知りました。このマージンをプログラムで決定する方法がわかりません。

minStopLoss = 現在値 +/- (MaxValue(2*Spread, StopLoss)) を試してみてください。

 
デバッグの停止時にオブジェクトが破棄されないのはなぜですか?OnDeinit()は全く呼ばれないと理解しています。デバッグ停止後、毎回端末を強制終了しなければならない。
 

良い午後は、以下のコードは、しばしば配列adx_sig[9]を更新している問題です。データ更新の依存性を定時に把握したかった。しかし、何かが間違っていた。

//+------------------------------------------------------------------+
//|                                                          123.mq5 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
input int                  ADX_adx_period          = 14;                                                 // adx period ADX 
input int                  ADX_lower_level         = 20;                                                 // Lower level ADX 
int h_adx[9];
double adx1_buffer[3];
double adx2_buffer[3];
double adx3_buffer[3];
ENUM_TIMEFRAMES handle_period[9]={PERIOD_CURRENT,PERIOD_M1,PERIOD_M5,PERIOD_M15,PERIOD_M30,PERIOD_H1,PERIOD_H4,PERIOD_D1,PERIOD_W1};
int adx_sig[9];
int OnInit()
  {
//---
   for(int i=0; i<ArraySize(handle_period); i++)
     {
      //--- Установим хэндлы для индикаторов
      h_adx[i]=iADX(_Symbol,handle_period[i],ADX_adx_period);
        if(h_adx[i]<0) 
        {
         Alert("Ошибка при создании индикаторов - : ",GetLastError(),"!!");
        }
     }   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
    for(int i=0; i<ArraySize(handle_period); i++)
     {
      //--- Удаляем хэндлы для индикаторов
      IndicatorRelease(h_adx[i]);
     }
     //---
       
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   for(int i_sig=0; i_sig<ArraySize(handle_period); i_sig++)
     {
      if(CopyBuffer(h_adx[i_sig],0,0,3,adx1_buffer)<3)Print("CopyBuffer adx1_buffer ",GetLastError());
      if(CopyBuffer(h_adx[i_sig],1,0,3,adx2_buffer)<3)Print("CopyBuffer adx2_buffer ",GetLastError());
      if(CopyBuffer(h_adx[i_sig],2,0,3,adx3_buffer)<3)Print("CopyBuffer adx3_buffer ",GetLastError());
      if(adx3_buffer[1]<adx2_buffer[1] && adx3_buffer[1]>=ADX_lower_level && adx3_buffer[1]>adx3_buffer[2])adx_sig[i_sig]=1;
      else if(adx3_buffer[1]>adx2_buffer[1] && adx3_buffer[1]>=ADX_lower_level && adx3_buffer[1]<adx3_buffer[2])adx_sig[i_sig]=-1;
      else adx_sig[i_sig]=0;
      }
      PrintFormat("ADX sig0=%i sig1=%i sig2=%i sig3=%i sig4=%i sig5=%i sig6=%i sig7=%i sig8=%i",adx_sig[0],adx_sig[1],adx_sig[2],adx_sig[3],adx_sig[4],adx_sig[5],adx_sig[6],adx_sig[7],adx_sig[8]); 
  }