質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
MQL5

MQL5(MetaQuotes Language 5)は、トレードロボットやカスタムインディケータを作成できる高レベル言語。MetaQuotes社の独自の取引プラットフォームのために開発されました。さまざまなサービスをリンクできるコミュニティも存在します。

Q&A

解決済

1回答

482閲覧

カスタムインジケーターが時間足を切り替えた瞬間にクラッシュする。

xxgranvillexx

総合スコア13

MQL5

MQL5(MetaQuotes Language 5)は、トレードロボットやカスタムインディケータを作成できる高レベル言語。MetaQuotes社の独自の取引プラットフォームのために開発されました。さまざまなサービスをリンクできるコミュニティも存在します。

0グッド

0クリップ

投稿2023/02/02 04:52

MQL5にてカスタムインジケーターを試作で作っているのですが、どうも、移動平均線自体は表示することに成功したのですが、どうも、時間足を切り替えた瞬間にチャートがクラッシュします。原因が不明です。どうコーディングしていいか分かりませんので、改善策を提示して頂ければと存じます。

mql5

1#property indicator_chart_window 2#property indicator_buffers 1 3#property indicator_plots 1 4 5#property indicator_label1 "AngleMA" 6#property indicator_type1 DRAW_LINE 7#property indicator_color1 clrRed 8#property indicator_style1 STYLE_SOLID 9#property indicator_width1 1 10 11enum Creation 12 { 13 Call_iMA, 14 Call_IndicatorCreate 15 }; 16 17input Creation type=Call_iMA; 18input int ma_period=10; 19input int ma_shift=0; 20input ENUM_MA_METHOD ma_method=MODE_SMA; 21input ENUM_APPLIED_PRICE applied_price=PRICE_CLOSE; 22 23 24 25//+------------------------------------------------------------------+ 26//| Custom indicator initialization function | 27//+------------------------------------------------------------------+ 28 29double AngleMA[]; 30int Handle; 31int bars; 32 33int OnInit() 34 { 35//--- indicator buffers mapping 36 SetIndexBuffer(0,AngleMA,INDICATOR_DATA); 37 PlotIndexSetInteger(0,PLOT_SHIFT,ma_shift); 38 Handle = iMA(_Symbol,0,ma_period,ma_shift,ma_method,applied_price); 39 40//--- 41 return(INIT_SUCCEEDED); 42 } 43//+------------------------------------------------------------------+ 44//| Custom indicator iteration function | 45//+------------------------------------------------------------------+ 46int OnCalculate(const int rates_total, 47 const int prev_calculated, 48 const datetime &time[], 49 const double &open[], 50 const double &high[], 51 const double &low[], 52 const double &close[], 53 const long &tick_volume[], 54 const long &volume[], 55 const int &spread[]) 56 { 57//--- 58 int copy; 59 int cal=BarsCalculated(Handle); 60 if(cal<=0) 61 { 62 return(0); 63 } 64 if(prev_calculated==0 || cal!=bars || rates_total>prev_calculated+1) 65 { 66 if(cal > rates_total) 67 { 68 copy=rates_total; 69 } else 70 71 { 72 copy=cal; 73 } 74 } else 75 76 { 77 copy=(rates_total-prev_calculated)+1; 78 } 79 80 if(!FillArrayFromBuffer(AngleMA,ma_shift,Handle,copy)) 81 82 { 83 return(0); 84 } 85 86 bars=cal; 87 88//--- return value of prev_calculated for next call 89 return(rates_total); 90 } 91//+------------------------------------------------------------------+ 92 93void OnDeinit(const int reason) 94{ 95 if(Handle!=INVALID_HANDLE) 96 { 97 IndicatorRelease(Handle); 98 } 99} 100 101bool FillArrayFromBuffer(double &values[], int shift, int ind_handle, int amount) 102 103{ 104ResetLastError(); 105if(CopyBuffer(ind_handle,0,-shift,amount,values)<0) 106{ 107 return(false); 108} 109 110return(true); 111 112 113}

よろしくお願い致します。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

自己解決しました。普通にMT5のバグだったようで、コンパイラしたものをチャートに表示させたら、クラッシュしませんででした。

投稿2023/02/02 23:09

xxgranvillexx

総合スコア13

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問