2026-03-02 18:48:20 +03:00
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//| Charter.mq5 |
|
|
|
|
|
//| Copyright 2026, MasterOfPuppets |
|
|
|
|
|
//| https://forge.mql5.io/masterofpuppets/mql5 |
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//| Includes |
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
#include <Trade\SymbolInfo.mqh>
|
2026-03-03 01:24:56 +03:00
|
|
|
#include <MasterOfPuppetsLib\ActionKey.mqh>
|
|
|
|
|
#include <MasterOfPuppetsLib\Actions.mqh>
|
2026-03-03 01:47:23 +03:00
|
|
|
#include <MasterOfPuppetsLib\Utils.mqh>
|
2026-03-02 18:48:20 +03:00
|
|
|
#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"
|
2026-03-02 20:46:43 +03:00
|
|
|
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
|
2026-03-02 18:48:20 +03:00
|
|
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//| Variables |
|
|
|
|
|
//+------------------------------------------------------------------+
|
2026-03-03 01:24:56 +03:00
|
|
|
Actions<Action> actions;
|
2026-03-02 18:48:20 +03:00
|
|
|
string actionsUsage;
|
2026-03-02 20:46:43 +03:00
|
|
|
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
|
|
|
|
|
};
|
2026-03-02 18:48:20 +03:00
|
|
|
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;
|
|
|
|
|
}
|
2026-03-02 20:46:43 +03:00
|
|
|
Action action = (Action) actions.GetAction(lparam);
|
|
|
|
|
switch(action)
|
2026-03-02 18:48:20 +03:00
|
|
|
{
|
2026-03-02 20:46:43 +03:00
|
|
|
case Action::DECREASE_PERIOD:
|
|
|
|
|
case Action::INCREASE_PERIOD:
|
|
|
|
|
ChangePeriod(action);
|
|
|
|
|
break;
|
2026-03-02 20:02:15 +03:00
|
|
|
case Action::SET_PERIOD_M1:
|
2026-03-02 20:53:16 +03:00
|
|
|
SetPeriod(PERIOD_M1);
|
2026-03-02 20:02:15 +03:00
|
|
|
break;
|
|
|
|
|
case Action::SET_PERIOD_M5:
|
2026-03-02 20:53:16 +03:00
|
|
|
SetPeriod(PERIOD_M5);
|
2026-03-02 20:02:15 +03:00
|
|
|
break;
|
|
|
|
|
case Action::SET_PERIOD_M15:
|
2026-03-02 20:53:16 +03:00
|
|
|
SetPeriod(PERIOD_M15);
|
2026-03-02 20:02:15 +03:00
|
|
|
break;
|
|
|
|
|
case Action::SET_PERIOD_M30:
|
2026-03-02 20:53:16 +03:00
|
|
|
SetPeriod(PERIOD_M30);
|
2026-03-02 20:02:15 +03:00
|
|
|
break;
|
|
|
|
|
case Action::SET_PERIOD_H1:
|
2026-03-02 20:53:16 +03:00
|
|
|
SetPeriod(PERIOD_H1);
|
2026-03-02 20:02:15 +03:00
|
|
|
break;
|
|
|
|
|
case Action::SET_PERIOD_H4:
|
2026-03-02 20:53:16 +03:00
|
|
|
SetPeriod(PERIOD_H4);
|
2026-03-02 20:02:15 +03:00
|
|
|
break;
|
|
|
|
|
case Action::SET_PERIOD_H8:
|
2026-03-02 20:53:16 +03:00
|
|
|
SetPeriod(PERIOD_H8);
|
2026-03-02 20:02:15 +03:00
|
|
|
break;
|
|
|
|
|
case Action::SET_PERIOD_H12:
|
2026-03-02 20:53:16 +03:00
|
|
|
SetPeriod(PERIOD_H12);
|
2026-03-02 20:02:15 +03:00
|
|
|
break;
|
|
|
|
|
case Action::SET_PERIOD_D1:
|
2026-03-02 20:53:16 +03:00
|
|
|
SetPeriod(PERIOD_D1);
|
2026-03-02 20:02:15 +03:00
|
|
|
break;
|
|
|
|
|
case Action::SET_PERIOD_W1:
|
2026-03-02 20:53:16 +03:00
|
|
|
SetPeriod(PERIOD_W1);
|
2026-03-02 20:02:15 +03:00
|
|
|
break;
|
|
|
|
|
case Action::SET_PERIOD_MN1:
|
2026-03-02 20:53:16 +03:00
|
|
|
SetPeriod(PERIOD_MN1);
|
2026-03-02 20:02:15 +03:00
|
|
|
break;
|
|
|
|
|
case Action::SET_PERIOD_H1_DEFAULT:
|
2026-03-02 20:53:16 +03:00
|
|
|
SetPeriod(PERIOD_H1);
|
2026-03-02 20:02:15 +03:00
|
|
|
break;
|
|
|
|
|
case Action::SET_PERIOD_H1_1:
|
2026-03-02 20:53:16 +03:00
|
|
|
SetPeriod(PERIOD_H1);
|
2026-03-02 20:02:15 +03:00
|
|
|
break;
|
|
|
|
|
case Action::SET_PERIOD_D1_1:
|
2026-03-02 20:53:16 +03:00
|
|
|
SetPeriod(PERIOD_D1);
|
2026-03-02 20:02:15 +03:00
|
|
|
break;
|
|
|
|
|
case Action::SET_PERIOD_W1_1:
|
2026-03-02 20:53:16 +03:00
|
|
|
SetPeriod(PERIOD_W1);
|
2026-03-02 20:02:15 +03:00
|
|
|
break;
|
|
|
|
|
case Action::SET_PERIOD_MN1_1:
|
2026-03-02 20:53:16 +03:00
|
|
|
SetPeriod(PERIOD_MN1);
|
2026-03-02 20:02:15 +03:00
|
|
|
break;
|
2026-03-02 18:48:20 +03:00
|
|
|
case Action::SHOW_TRADE_HISTORY:
|
|
|
|
|
tradeHistoryEnabled = !tradeHistoryEnabled;
|
|
|
|
|
ChartSetInteger(0, CHART_SHOW_TRADE_HISTORY, tradeHistoryEnabled);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-02 20:46:43 +03:00
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//| 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]);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-02 20:53:16 +03:00
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//| Set period function |
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
void SetPeriod(const ENUM_TIMEFRAMES enumTimeframes)
|
|
|
|
|
{
|
|
|
|
|
ChartSetSymbolPeriod(0, _Symbol, enumTimeframes);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-02 18:48:20 +03:00
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//| 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()
|
|
|
|
|
{
|
2026-03-02 20:46:43 +03:00
|
|
|
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);
|
2026-03-02 18:48:20 +03:00
|
|
|
actions.AddAction(showTradeHistoryActionKey, Action::SHOW_TRADE_HISTORY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//| Timer function |
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
void OnTimer()
|
|
|
|
|
{
|
2026-03-02 20:46:43 +03:00
|
|
|
Comment(actionsUsage);
|
2026-03-02 18:48:20 +03:00
|
|
|
}
|
|
|
|
|
//+------------------------------------------------------------------+
|