Skip to content

Instantly share code, notes, and snippets.

@Y-Koji
Created August 16, 2018 12:41
Show Gist options
  • Save Y-Koji/875b2a12f9ce671872cb76adf0427c4f to your computer and use it in GitHub Desktop.
Save Y-Koji/875b2a12f9ce671872cb76adf0427c4f to your computer and use it in GitHub Desktop.
MT5 SMMA 描画スクリプト
#property copyright "SMMA Sample Indicator."
#property link ""
#property version "1.00"
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_plots 3
// 移動平均短期スパン描画設定
#property indicator_label1 "SMMA Short"
#property indicator_type1 DRAW_LINE
#property indicator_color1 Yellow
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
// 移動平均中期スパン描画設定
#property indicator_label2 "SMMA Middle"
#property indicator_type2 DRAW_LINE
#property indicator_color2 Red
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
// 移動平均長期スパン描画設定
#property indicator_label3 "SMMA Long"
#property indicator_type3 DRAW_LINE
#property indicator_color3 DeepSkyBlue
#property indicator_style3 STYLE_SOLID
#property indicator_width3 1
// 短期スパン用バッファ
input int period1 = 10;
input int shift1 = 0;
double maLine1[];
// 中期スパン用バッファ
input int period2 = 20;
input int shift2 = 0;
double maLine2[];
// 長期スパン用バッファ
input int period3 = 30;
input int shift3 = 0;
double maLine3[];
// 各種移動平均のハンドル
int maLineHandle1;
int maLineHandle2;
int maLineHandle3;
int OnInit()
{
EventSetTimer(60);
// 描画用バッファの取得. maLineを描画用バッファとして設定.
SetIndexBuffer(0, maLine1, INDICATOR_DATA);
SetIndexBuffer(1, maLine2, INDICATOR_DATA);
SetIndexBuffer(2, maLine3, INDICATOR_DATA);
// 組み込まれている移動平均計算機能の各スパン用ハンドルを取得
maLineHandle1 = iMA(NULL, 0, period1, shift1, MODE_SMMA, PRICE_CLOSE);
maLineHandle2 = iMA(NULL, 0, period2, shift2, MODE_SMMA, PRICE_CLOSE);
maLineHandle3 = iMA(NULL, 0, period3, shift3, MODE_SMMA, PRICE_CLOSE);
return(INIT_SUCCEEDED);
}
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[])
{
// データが利用できるか確認.
if (BarsCalculated(maLineHandle1) < rates_total ||
BarsCalculated(maLineHandle2) < rates_total ||
BarsCalculated(maLineHandle3) < rates_total)
{
return 0;
}
// 未計算の足の数を取得
int to_copy;
if (rates_total < prev_calculated || prev_calculated <= 0)
{
to_copy = rates_total - prev_calculated;
}
else
{
to_copy = rates_total - prev_calculated;
to_copy++;
}
// 移動平均計算用ハンドルから結果を描画用バッファへコピー
if (CopyBuffer(maLineHandle1, 0, 0, to_copy, maLine1) <= 0 ||
CopyBuffer(maLineHandle2, 0, 0, to_copy, maLine2) <= 0 ||
CopyBuffer(maLineHandle3, 0, 0, to_copy, maLine3) <= 0)
{
return 0;
}
return(rates_total);
}
void OnDeinit(const int reason)
{
EventKillTimer();
}
void OnTick()
{
}
void OnTimer()
{
}
void OnTrade()
{
}
void OnTradeTransaction(
const MqlTradeTransaction& trans,
const MqlTradeRequest& request,
const MqlTradeResult& result)
{
}
double OnTester()
{
double ret=0.0;
return(ret);
}
void OnTesterInit()
{
}
void OnTesterPass()
{
}
void OnTesterDeinit()
{
}
void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam)
{
}
void OnBookEvent(const string &symbol)
{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment