Posted at

[MQL5]全チャートの時間足を変更するショートカットを追加するスクリプト

More than 1 year has passed since last update.

//+------------------------------------------------------------------+

//| AdditinalShortCuts.mq5 |
//| Copyright 2018, Shintaro Tanikawa |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, Shintaro Tanikawa"

void OnChartEvent(const int id,
const long &lparam,
const double &dparam,
const string &sparam)
{
if (id == CHARTEVENT_KEYDOWN)
{
ENUM_TIMEFRAMES timeframes = GetTimeFramesByKey(lparam);
if (timeframes != -1)
{
long chartId = ChartFirst();
for (int i = 0; i < CHARTS_MAX; ++i)
{
if (ChartPeriod(chartId) != timeframes)
{
ChartSetSymbolPeriod(chartId, ChartSymbol(chartId), timeframes);
}
chartId = ChartNext(chartId);
}
}

}
}

ENUM_TIMEFRAMES GetTimeFramesByKey(const long &key)
{
switch (key)
{
case 49: // Pressed Key 1
return PERIOD_M1;
case 50: // Pressed Key 2
return PERIOD_M5;
case 51: // Pressed Key 3
return PERIOD_M15;
case 52: // Pressed Key 4
return PERIOD_M30;
case 53: // Pressed Key 5
return PERIOD_H1;
case 54: // Pressed Key 6
return PERIOD_H4;
case 55: // Pressed Key 7
return PERIOD_D1;
case 56: // Pressed Key 8
return PERIOD_W1;
case 57:
return PERIOD_MN1;
default:
return -1;
}
}
//+------------------------------------------------------------------+