1
0
포크 0
원본 프로젝트 masterofpuppets/mql5
mql5/Experts/Charter/Charter.mq5
2026-03-03 01:47:23 +03:00

228 lines
9 KiB
MQL5

//+------------------------------------------------------------------+
//| Charter.mq5 |
//| Copyright 2026, MasterOfPuppets |
//| https://forge.mql5.io/masterofpuppets/mql5 |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Includes |
//+------------------------------------------------------------------+
#include <Trade\SymbolInfo.mqh>
#include <MasterOfPuppetsLib\ActionKey.mqh>
#include <MasterOfPuppetsLib\Actions.mqh>
#include <MasterOfPuppetsLib\Utils.mqh>
#include "Action.mqh"
//+------------------------------------------------------------------+
//| Properties |
//+------------------------------------------------------------------+
#property copyright "Copyright 2026, MasterOfPuppets"
#property description "Charter"
#property link "https://forge.mql5.io/masterofpuppets/mql5"
#property version "1.00"
//+------------------------------------------------------------------+
//| Inputs |
//+------------------------------------------------------------------+
input group "Action keys"
input ActionKey decreasePeriodActionKey = Z; // DECREASE_PERIOD
input ActionKey increasePeriodActionKey = X; // INCREASE_PERIOD
input ActionKey setPeriodM1ActionKey = _1; // SET_PERIOD_PERIOD_M1
input ActionKey setPeriodM5ActionKey = _2; // SET_PERIOD_PERIOD_M5
input ActionKey setPeriodM15ActionKey = _3; // SET_PERIOD_PERIOD_M15
input ActionKey setPeriodM30ActionKey = _4; // SET_PERIOD_PERIOD_M30
input ActionKey setPeriodH1ActionKey = _5; // SET_PERIOD_PERIOD_H1
input ActionKey setPeriodH4ActionKey = _6; // SET_PERIOD_PERIOD_H4
input ActionKey setPeriodH8ActionKey = O; // SET_PERIOD_PERIOD_H8
input ActionKey setPeriodH12ActionKey = P; // SET_PERIOD_PERIOD_H12
input ActionKey setPeriodD1ActionKey = _7; // SET_PERIOD_PERIOD_D1
input ActionKey setPeriodW1ActionKey = _8; // SET_PERIOD_PERIOD_W1
input ActionKey setPeriodMN1ActionKey = _9; // SET_PERIOD_PERIOD_MN1
input ActionKey setPeriodH1DefaultActionKey = _0; // SET_PERIOD_PERIOD_H1_DEFAULT
input ActionKey setPeriodH11ActionKey = H; // SET_PERIOD_PERIOD_H1_1
input ActionKey setPeriodD11ActionKey = D; // SET_PERIOD_PERIOD_D1_1
input ActionKey setPeriodW11ActionKey = W; // SET_PERIOD_PERIOD_W1_1
input ActionKey setPeriodMN11ActionKey = M; // SET_PERIOD_PERIOD_MN1_1
input ActionKey showTradeHistoryActionKey = T; // SHOW_TRADE_HISTORY
//+------------------------------------------------------------------+
//| Variables |
//+------------------------------------------------------------------+
Actions<Action> actions;
string actionsUsage;
int periodIndex = 4;
int periods[11] =
{
PERIOD_M1, PERIOD_M5, PERIOD_M15, PERIOD_M30,
PERIOD_H1, PERIOD_H4, PERIOD_H8, PERIOD_H12,
PERIOD_D1, PERIOD_W1, PERIOD_MN1
};
CSymbolInfo symbolInfo;
bool tradeHistoryEnabled;
//+------------------------------------------------------------------+
//| ChartEvent function |
//+------------------------------------------------------------------+
void OnChartEvent(const int32_t id, const long &lparam, const double &dparam, const string &sparam)
{
if(id != CHARTEVENT_KEYDOWN)
{
return;
}
Action action = (Action) actions.GetAction(lparam);
switch(action)
{
case Action::DECREASE_PERIOD:
case Action::INCREASE_PERIOD:
ChangePeriod(action);
break;
case Action::SET_PERIOD_M1:
SetPeriod(PERIOD_M1);
break;
case Action::SET_PERIOD_M5:
SetPeriod(PERIOD_M5);
break;
case Action::SET_PERIOD_M15:
SetPeriod(PERIOD_M15);
break;
case Action::SET_PERIOD_M30:
SetPeriod(PERIOD_M30);
break;
case Action::SET_PERIOD_H1:
SetPeriod(PERIOD_H1);
break;
case Action::SET_PERIOD_H4:
SetPeriod(PERIOD_H4);
break;
case Action::SET_PERIOD_H8:
SetPeriod(PERIOD_H8);
break;
case Action::SET_PERIOD_H12:
SetPeriod(PERIOD_H12);
break;
case Action::SET_PERIOD_D1:
SetPeriod(PERIOD_D1);
break;
case Action::SET_PERIOD_W1:
SetPeriod(PERIOD_W1);
break;
case Action::SET_PERIOD_MN1:
SetPeriod(PERIOD_MN1);
break;
case Action::SET_PERIOD_H1_DEFAULT:
SetPeriod(PERIOD_H1);
break;
case Action::SET_PERIOD_H1_1:
SetPeriod(PERIOD_H1);
break;
case Action::SET_PERIOD_D1_1:
SetPeriod(PERIOD_D1);
break;
case Action::SET_PERIOD_W1_1:
SetPeriod(PERIOD_W1);
break;
case Action::SET_PERIOD_MN1_1:
SetPeriod(PERIOD_MN1);
break;
case Action::SHOW_TRADE_HISTORY:
tradeHistoryEnabled = !tradeHistoryEnabled;
ChartSetInteger(0, CHART_SHOW_TRADE_HISTORY, tradeHistoryEnabled);
break;
}
}
//+------------------------------------------------------------------+
//| Change period function |
//+------------------------------------------------------------------+
void ChangePeriod(const Action action)
{
switch(action)
{
case Action::DECREASE_PERIOD:
periodIndex--;
if(periodIndex < 0)
{
periodIndex = (int) periods.Size() - 1;
}
break;
case Action::INCREASE_PERIOD:
periodIndex++;
if(periodIndex >= (int) periods.Size())
{
periodIndex = 0;
}
break;
}
ChartSetSymbolPeriod(0, _Symbol, (ENUM_TIMEFRAMES) periods[periodIndex]);
}
//+------------------------------------------------------------------+
//| Set period function |
//+------------------------------------------------------------------+
void SetPeriod(const ENUM_TIMEFRAMES enumTimeframes)
{
ChartSetSymbolPeriod(0, _Symbol, enumTimeframes);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
actions.Clear();
EventKillTimer();
}
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
if(!symbolInfo.Name(_Symbol))
{
return(INIT_FAILED);
}
InitActions();
if(!IsKeyMappingCorrect())
{
return(INIT_PARAMETERS_INCORRECT);
}
EventSetTimer(1);
actionsUsage = actions.Usage();
Print(actionsUsage);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Actions initialization function |
//+------------------------------------------------------------------+
void InitActions()
{
actions.AddAction(decreasePeriodActionKey, Action::DECREASE_PERIOD);
actions.AddAction(increasePeriodActionKey, Action::INCREASE_PERIOD);
actions.AddAction(setPeriodM1ActionKey, Action::SET_PERIOD_M1);
actions.AddAction(setPeriodM5ActionKey, Action::SET_PERIOD_M5);
actions.AddAction(setPeriodM15ActionKey, Action::SET_PERIOD_M15);
actions.AddAction(setPeriodM30ActionKey, Action::SET_PERIOD_M30);
actions.AddAction(setPeriodH1ActionKey, Action::SET_PERIOD_H1);
actions.AddAction(setPeriodH4ActionKey, Action::SET_PERIOD_H4);
actions.AddAction(setPeriodH8ActionKey, Action::SET_PERIOD_H8);
actions.AddAction(setPeriodH12ActionKey, Action::SET_PERIOD_H12);
actions.AddAction(setPeriodD1ActionKey, Action::SET_PERIOD_D1);
actions.AddAction(setPeriodW1ActionKey, Action::SET_PERIOD_W1);
actions.AddAction(setPeriodMN1ActionKey, Action::SET_PERIOD_MN1);
actions.AddAction(setPeriodH1DefaultActionKey, Action::SET_PERIOD_H1_DEFAULT);
actions.AddAction(setPeriodH11ActionKey, Action::SET_PERIOD_H1_1);
actions.AddAction(setPeriodD11ActionKey, Action::SET_PERIOD_D1_1);
actions.AddAction(setPeriodW11ActionKey, Action::SET_PERIOD_W1_1);
actions.AddAction(setPeriodMN11ActionKey, Action::SET_PERIOD_MN1_1);
actions.AddAction(showTradeHistoryActionKey, Action::SHOW_TRADE_HISTORY);
}
//+------------------------------------------------------------------+
//| Timer function |
//+------------------------------------------------------------------+
void OnTimer()
{
Comment(actionsUsage);
}
//+------------------------------------------------------------------+