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

 
TheXpert:
端末に「クローズオーダー」イベントはありません。スクリプトまたはExpert Advisorを使用する必要があります。上記のとおりです。

クロス」を押して未決済の注文を決済するときのイベント名は何ですか?

それが、サウンドを「アサイン」するために必要なものです

 
paladin800:

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

また、自分のミスも発見しました。ポイントは、"Buy_close "という条件で、プログラムに取引を実行するタスクを与え、ポジションのチェックは "Buy_opened "とすることです。

取引成立と "Buy_close "の条件が重なったため、エラーが発生しました。

条件を以下のようにした。

if(Buy_close && Buy_opened==true)
 
trora:

にサウンドを "アサイン "するアクションです。

グッドラック :)
 

オフセットが-+0.30%のMA線が出ないのですが。

オフセットが 発生する 移動平均を 呼び出すことは問題ない。しかし、オフセットラインを取得する 方法がない。

基本コードです。

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2
#property  indicator_type1   DRAW_LINE
#property  indicator_color1  clrMediumVioletRed
#property  indicator_style1  STYLE_SOLID
#property  indicator_label1  ""
#property  indicator_type2   DRAW_LINE
#property  indicator_color2  clrRed
#property  indicator_style2  STYLE_SOLID
#property  indicator_label2  "Sell TP
input int Period_ = 34;         //Период
int ma1Handle;
double ma1Val[]; 
double ExtMapBuffer1[];
double ExtMapBuffer2[]
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {   
SetIndexBuffer(0,ExtMapBuffer1,INDICATOR_DATA);
SetIndexBuffer(1,ExtMapBuffer2,INDICATOR_DATA)
ma1Handle=iMA(_Symbol,_Period,Period_,0,MODE_EMA,PRICE_CLOSE); 
   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[])
  {
CopyBuffer(ma1Handle,0,0,2,ma1Val);
ArraySetAsSeries(ma1Val,true);
int bars=Bars(_Symbol,_Period);
for(int i=0;i<bars;i++)
{
ExtMapBuffer2[i]=ma1Val[0] - ((ma1Val[0]/100)*0.3);//ЗДЕСЬ НЕ ПОЛУЧАЕТСЯ ПОЛУЧИТЬ ЛИНИЮ
}
//---   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
 
#property indicator_label2  "Sell TP
2つ目の倒置コンマはどこですか?
 
CopyBuffer(ma1Handle,0,0,2,ma1Val);
この文字列は、ループ内でかつインデックスが必要です。
 
sandex:
この文字列は、ループの中で、インデックスを付ける必要があります。

文字列のインデックスを作成するにはどうしたらよいでしょうか。 試してみると、次のようなエラーが出ます。

ArraySetAsSeries(ma1Val,true);
int bars=Bars(_Symbol,_Period);
for(int i=0;i<bars;i++)
    {
    CopyBuffer(ma1Handle,0,0,2,ma1Val[i]);
    ExtMapBuffer2[i]=ma1Val[i] - ((ma1Val[i]/100)*0.3);//ЗДЕСЬ НЕ ПОЛУЧАЕТСЯ ПОЛУЧИТЬ ЛИНИЮ
    }
 

インデックス作成はこのように行います。

CopyBuffer(ma1Handle,0,i,1,ma1Val);
 

この行は、次のようになります。

ExtMapBuffer2[i]=ma1Val[0] - ((ma1Val[0]/100)*0.3);
 

サイズ1の静的な配列を宣言します。

double ma1Val[1];
理由: