EMA_Rainbow/EMA Rainbow.mq5
2026-04-17 15:28:22 -05:00

222 lines
No EOL
8.3 KiB
MQL5

//+------------------------------------------------------------------+
//| DigitalRogue |
//| Algorithmic Trading Systems for MetaTrader 5 |
//| |
//| EMA Rainbow (MultiEMA_10_to_100) |
//| |
//| Copyright 2026, DigitalRogue Trading |
//| All rights reserved. |
//| https://www.mql5.com/en/users/digitalrogue |
//+------------------------------------------------------------------+
#property copyright "Copyright 2026, DigitalRogue Trading"
#property link "https://www.mql5.com/en/users/digitalrogue"
#property version "1.01"
#property indicator_chart_window
#property indicator_buffers 10
#property indicator_plots 10
//--- Plot 1
#property indicator_label1 "EMA 10"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrRed
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//--- Plot 2
#property indicator_label2 "EMA 20"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrLime
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//--- Plot 3
#property indicator_label3 "EMA 30"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrDodgerBlue
#property indicator_style3 STYLE_SOLID
#property indicator_width3 1
//--- Plot 4
#property indicator_label4 "EMA 40"
#property indicator_type4 DRAW_LINE
#property indicator_color4 clrOrange
#property indicator_style4 STYLE_SOLID
#property indicator_width4 1
//--- Plot 5
#property indicator_label5 "EMA 50"
#property indicator_type5 DRAW_LINE
#property indicator_color5 clrMediumOrchid
#property indicator_style5 STYLE_SOLID
#property indicator_width5 1
//--- Plot 6
#property indicator_label6 "EMA 60"
#property indicator_type6 DRAW_LINE
#property indicator_color6 clrMaroon
#property indicator_style6 STYLE_SOLID
#property indicator_width6 1
//--- Plot 7
#property indicator_label7 "EMA 70"
#property indicator_type7 DRAW_LINE
#property indicator_color7 clrTeal
#property indicator_style7 STYLE_SOLID
#property indicator_width7 1
//--- Plot 8
#property indicator_label8 "EMA 80"
#property indicator_type8 DRAW_LINE
#property indicator_color8 clrNavy
#property indicator_style8 STYLE_SOLID
#property indicator_width8 1
//--- Plot 9
#property indicator_label9 "EMA 90"
#property indicator_type9 DRAW_LINE
#property indicator_color9 clrOlive
#property indicator_style9 STYLE_SOLID
#property indicator_width9 1
//--- Plot 10
#property indicator_label10 "EMA 100"
#property indicator_type10 DRAW_LINE
#property indicator_color10 clrBrown
#property indicator_style10 STYLE_SOLID
#property indicator_width10 1
//--- Inputs
input ENUM_APPLIED_PRICE InpAppliedPrice = PRICE_CLOSE;
//--- Buffers
double ema10[];
double ema20[];
double ema30[];
double ema40[];
double ema50[];
double ema60[];
double ema70[];
double ema80[];
double ema90[];
double ema100[];
//--- Indicator handles
int handle10 = INVALID_HANDLE;
int handle20 = INVALID_HANDLE;
int handle30 = INVALID_HANDLE;
int handle40 = INVALID_HANDLE;
int handle50 = INVALID_HANDLE;
int handle60 = INVALID_HANDLE;
int handle70 = INVALID_HANDLE;
int handle80 = INVALID_HANDLE;
int handle90 = INVALID_HANDLE;
int handle100 = INVALID_HANDLE;
//+------------------------------------------------------------------+
//| Initialization |
//+------------------------------------------------------------------+
int OnInit()
{
//--- Bind buffers
SetIndexBuffer(0, ema10, INDICATOR_DATA);
SetIndexBuffer(1, ema20, INDICATOR_DATA);
SetIndexBuffer(2, ema30, INDICATOR_DATA);
SetIndexBuffer(3, ema40, INDICATOR_DATA);
SetIndexBuffer(4, ema50, INDICATOR_DATA);
SetIndexBuffer(5, ema60, INDICATOR_DATA);
SetIndexBuffer(6, ema70, INDICATOR_DATA);
SetIndexBuffer(7, ema80, INDICATOR_DATA);
SetIndexBuffer(8, ema90, INDICATOR_DATA);
SetIndexBuffer(9, ema100, INDICATOR_DATA);
//--- Use time-series order
ArraySetAsSeries(ema10, true);
ArraySetAsSeries(ema20, true);
ArraySetAsSeries(ema30, true);
ArraySetAsSeries(ema40, true);
ArraySetAsSeries(ema50, true);
ArraySetAsSeries(ema60, true);
ArraySetAsSeries(ema70, true);
ArraySetAsSeries(ema80, true);
ArraySetAsSeries(ema90, true);
ArraySetAsSeries(ema100, true);
//--- Create EMA handles
handle10 = iMA(_Symbol, PERIOD_CURRENT, 10, 0, MODE_EMA, InpAppliedPrice);
handle20 = iMA(_Symbol, PERIOD_CURRENT, 20, 0, MODE_EMA, InpAppliedPrice);
handle30 = iMA(_Symbol, PERIOD_CURRENT, 30, 0, MODE_EMA, InpAppliedPrice);
handle40 = iMA(_Symbol, PERIOD_CURRENT, 40, 0, MODE_EMA, InpAppliedPrice);
handle50 = iMA(_Symbol, PERIOD_CURRENT, 50, 0, MODE_EMA, InpAppliedPrice);
handle60 = iMA(_Symbol, PERIOD_CURRENT, 60, 0, MODE_EMA, InpAppliedPrice);
handle70 = iMA(_Symbol, PERIOD_CURRENT, 70, 0, MODE_EMA, InpAppliedPrice);
handle80 = iMA(_Symbol, PERIOD_CURRENT, 80, 0, MODE_EMA, InpAppliedPrice);
handle90 = iMA(_Symbol, PERIOD_CURRENT, 90, 0, MODE_EMA, InpAppliedPrice);
handle100 = iMA(_Symbol, PERIOD_CURRENT, 100, 0, MODE_EMA, InpAppliedPrice);
if(handle10 == INVALID_HANDLE ||
handle20 == INVALID_HANDLE ||
handle30 == INVALID_HANDLE ||
handle40 == INVALID_HANDLE ||
handle50 == INVALID_HANDLE ||
handle60 == INVALID_HANDLE ||
handle70 == INVALID_HANDLE ||
handle80 == INVALID_HANDLE ||
handle90 == INVALID_HANDLE ||
handle100 == INVALID_HANDLE)
{
Print("Failed to create one or more EMA handles.");
return(INIT_FAILED);
}
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Deinitialization |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
if(handle10 != INVALID_HANDLE) IndicatorRelease(handle10);
if(handle20 != INVALID_HANDLE) IndicatorRelease(handle20);
if(handle30 != INVALID_HANDLE) IndicatorRelease(handle30);
if(handle40 != INVALID_HANDLE) IndicatorRelease(handle40);
if(handle50 != INVALID_HANDLE) IndicatorRelease(handle50);
if(handle60 != INVALID_HANDLE) IndicatorRelease(handle60);
if(handle70 != INVALID_HANDLE) IndicatorRelease(handle70);
if(handle80 != INVALID_HANDLE) IndicatorRelease(handle80);
if(handle90 != INVALID_HANDLE) IndicatorRelease(handle90);
if(handle100 != INVALID_HANDLE) IndicatorRelease(handle100);
}
//+------------------------------------------------------------------+
//| Calculation |
//+------------------------------------------------------------------+
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(rates_total <= 0)
return 0;
//--- Copy EMA data from indicator handles into our buffers
if(CopyBuffer(handle10, 0, 0, rates_total, ema10) <= 0) return prev_calculated;
if(CopyBuffer(handle20, 0, 0, rates_total, ema20) <= 0) return prev_calculated;
if(CopyBuffer(handle30, 0, 0, rates_total, ema30) <= 0) return prev_calculated;
if(CopyBuffer(handle40, 0, 0, rates_total, ema40) <= 0) return prev_calculated;
if(CopyBuffer(handle50, 0, 0, rates_total, ema50) <= 0) return prev_calculated;
if(CopyBuffer(handle60, 0, 0, rates_total, ema60) <= 0) return prev_calculated;
if(CopyBuffer(handle70, 0, 0, rates_total, ema70) <= 0) return prev_calculated;
if(CopyBuffer(handle80, 0, 0, rates_total, ema80) <= 0) return prev_calculated;
if(CopyBuffer(handle90, 0, 0, rates_total, ema90) <= 0) return prev_calculated;
if(CopyBuffer(handle100, 0, 0, rates_total, ema100) <= 0) return prev_calculated;
return rates_total;
}
//+------------------------------------------------------------------+