Ripster EMA Clouds in MQL5 — converted from Pine Script

The Ripster EMA Clouds indicator by ripster47, published on TradingView under the Mozilla Public License 2.0, converted to MetaTrader 5 by the Stratlate engine. The conversion was executed against the original on 500 synthetic bars and compared value by value: equivalent (fidelity 1.000).

Direction
Pine Script → MQL5
Kind
indicator, drawn on the price chart
Verdict
EQUIVALENT on 500 bars
Engine
pinec 0.6.46
Conversion notes
20 informational
Source
215 lines of Pine v4

Inputs

InputDefault
MA Type"EMA"
Short EMA1 Length8
Long EMA1 Length9
Short EMA2 Length5
Long EMA2 Length12
Short EMA3 Length34
Long EMA3 Length50
Short EMA4 Length72
Long EMA4 Length89
Short EMA5 Length180
Long EMA5 Length200
Sourcehl2

Converted MQL5

Save as ripster-ema-clouds.mq5 next to PineRuntime.mqh (included with every conversion), compile in MetaEditor, then review and backtest before trading. Output of the engine alone; the AI review available after sign-in may improve it further.

//+------------------------------------------------------------------+
//| pine-transpiler 0.6.46 (pinec) - generated code
//| source sha256: b693b8060e12   status: CLEAN
//| notes: 0 unsupported, 0 warn, 20 info
//| Review, compile and backtest before trading.
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Ripster EMA Clouds
//| Converted from Pine Script by pine-transpiler.
//| Review before trading: see the accompanying report for every
//| construct that was approximated or could not be converted.
//+------------------------------------------------------------------+
#property copyright "Converted by pine-transpiler"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 30
#property indicator_plots   15
#property indicator_label1  "MA Cloud1"
#property indicator_type1   DRAW_FILLING
#property indicator_color1  clrDodgerBlue
#property indicator_width1  1
#property indicator_label2  "MA Cloud2"
#property indicator_type2   DRAW_FILLING
#property indicator_color2  clrDodgerBlue
#property indicator_width2  1
#property indicator_label3  "MA Cloud3"
#property indicator_type3   DRAW_FILLING
#property indicator_color3  clrDodgerBlue
#property indicator_width3  1
#property indicator_label4  "MA Cloud4"
#property indicator_type4   DRAW_FILLING
#property indicator_color4  clrDodgerBlue
#property indicator_width4  1
#property indicator_label5  "MA Cloud5"
#property indicator_type5   DRAW_FILLING
#property indicator_color5  clrDodgerBlue
#property indicator_width5  1
#property indicator_label6  "Short Leading EMA1"
#property indicator_type6   DRAW_COLOR_LINE
#property indicator_color6  clrDodgerBlue
#property indicator_width6  1
#property indicator_label7  "Short Leading EMA2"
#property indicator_type7   DRAW_COLOR_LINE
#property indicator_color7  clrDodgerBlue
#property indicator_width7  1
#property indicator_label8  "Short Leading EMA3"
#property indicator_type8   DRAW_COLOR_LINE
#property indicator_color8  clrDodgerBlue
#property indicator_width8  1
#property indicator_label9  "Short Leading EMA4"
#property indicator_type9   DRAW_COLOR_LINE
#property indicator_color9  clrDodgerBlue
#property indicator_width9  1
#property indicator_label10  "Short Leading EMA5"
#property indicator_type10   DRAW_COLOR_LINE
#property indicator_color10  clrDodgerBlue
#property indicator_width10  1
#property indicator_label11  "Long Leading EMA1"
#property indicator_type11   DRAW_COLOR_LINE
#property indicator_color11  clrDodgerBlue
#property indicator_width11  3
#property indicator_label12  "Long Leading EMA2"
#property indicator_type12   DRAW_COLOR_LINE
#property indicator_color12  clrDodgerBlue
#property indicator_width12  3
#property indicator_label13  "Long Leading EMA3"
#property indicator_type13   DRAW_COLOR_LINE
#property indicator_color13  clrDodgerBlue
#property indicator_width13  3
#property indicator_label14  "Long Leading EMA4"
#property indicator_type14   DRAW_COLOR_LINE
#property indicator_color14  clrDodgerBlue
#property indicator_width14  3
#property indicator_label15  "Long Leading EMA5"
#property indicator_type15   DRAW_COLOR_LINE
#property indicator_color15  clrDodgerBlue
#property indicator_width15  3

#include "PineRuntime.mqh"

//--- plot buffers
double PineFill0[];
double PineFill1[];
double PineFill2[];
double PineFill3[];
double PineFill4[];
double PineFill5[];
double PineFill6[];
double PineFill7[];
double PineFill8[];
double PineFill9[];
double Buf10[];
double Buf11[];
double Buf12[];
double Buf13[];
double Buf14[];
double Buf15[];
double Buf16[];
double Buf17[];
double Buf18[];
double Buf19[];
double Buf20[];
double Buf21[];
double Buf22[];
double Buf23[];
double Buf24[];
double Buf25[];
double Buf26[];
double Buf27[];
double Buf28[];
double Buf29[];
color  __pal5[64];   // the colours plot 5 has drawn so far; see pine_color_slot
int    __paln5 = 0;
color  __pal6[64];   // the colours plot 6 has drawn so far; see pine_color_slot
int    __paln6 = 0;
color  __pal7[64];   // the colours plot 7 has drawn so far; see pine_color_slot
int    __paln7 = 0;
color  __pal8[64];   // the colours plot 8 has drawn so far; see pine_color_slot
int    __paln8 = 0;
color  __pal9[64];   // the colours plot 9 has drawn so far; see pine_color_slot
int    __paln9 = 0;
color  __pal10[64];   // the colours plot 10 has drawn so far; see pine_color_slot
int    __paln10 = 0;
color  __pal11[64];   // the colours plot 11 has drawn so far; see pine_color_slot
int    __paln11 = 0;
color  __pal12[64];   // the colours plot 12 has drawn so far; see pine_color_slot
int    __paln12 = 0;
color  __pal13[64];   // the colours plot 13 has drawn so far; see pine_color_slot
int    __paln13 = 0;
color  __pal14[64];   // the colours plot 14 has drawn so far; see pine_color_slot
int    __paln14 = 0;

//--- script-level state
// The newest bar's index: `last_bar_index` and `barstate.islast`.
int    __pineLastBar = 0;
// Series-valued names are arrays because their history is read;
// the rest stay scalars.
double htf_ma1 = PINE_NA;
double htf_ma2 = PINE_NA;
double htf_ma3 = PINE_NA;
double htf_ma4 = PINE_NA;
double htf_ma5 = PINE_NA;
double htf_ma6 = PINE_NA;
double htf_ma7 = PINE_NA;
double htf_ma8 = PINE_NA;
double htf_ma9 = PINE_NA;
double htf_ma10 = PINE_NA;
double mashort1[];
double malong1[];
double mashort2[];
double malong2[];
double mashort3[];
double malong3[];
double mashort4[];
double malong4[];
double mashort5[];
double malong5[];
color cloudcolour1 = clrNONE;
color cloudcolour2 = clrNONE;
color cloudcolour3 = clrNONE;
color cloudcolour4 = clrNONE;
color cloudcolour5 = clrNONE;
double mashortcolor1 = PINE_NA;
double mashortcolor2 = PINE_NA;
double mashortcolor3 = PINE_NA;
double mashortcolor4 = PINE_NA;
double mashortcolor5 = PINE_NA;
double malongcolor1 = PINE_NA;
double malongcolor2 = PINE_NA;
double malongcolor3 = PINE_NA;
double malongcolor4 = PINE_NA;
double malongcolor5 = PINE_NA;

//--- live-tick rollback: the state each bar started from
double __sv_htf_ma1;
double __si_htf_ma1;
double __sv_htf_ma2;
double __si_htf_ma2;
double __sv_htf_ma3;
double __si_htf_ma3;
double __sv_htf_ma4;
double __si_htf_ma4;
double __sv_htf_ma5;
double __si_htf_ma5;
double __sv_htf_ma6;
double __si_htf_ma6;
double __sv_htf_ma7;
double __si_htf_ma7;
double __sv_htf_ma8;
double __si_htf_ma8;
double __sv_htf_ma9;
double __si_htf_ma9;
double __sv_htf_ma10;
double __si_htf_ma10;
color __sv_cloudcolour1;
color __si_cloudcolour1;
color __sv_cloudcolour2;
color __si_cloudcolour2;
color __sv_cloudcolour3;
color __si_cloudcolour3;
color __sv_cloudcolour4;
color __si_cloudcolour4;
color __sv_cloudcolour5;
color __si_cloudcolour5;
double __sv_mashortcolor1;
double __si_mashortcolor1;
double __sv_mashortcolor2;
double __si_mashortcolor2;
double __sv_mashortcolor3;
double __si_mashortcolor3;
double __sv_mashortcolor4;
double __si_mashortcolor4;
double __sv_mashortcolor5;
double __si_mashortcolor5;
double __sv_malongcolor1;
double __si_malongcolor1;
double __sv_malongcolor2;
double __si_malongcolor2;
double __sv_malongcolor3;
double __si_malongcolor3;
double __sv_malongcolor4;
double __si_malongcolor4;
double __sv_malongcolor5;
double __si_malongcolor5;
int __pineSnapBar = -1;
void __pineSaveState()
{
   __sv_htf_ma1 = htf_ma1;
   __sv_htf_ma2 = htf_ma2;
   __sv_htf_ma3 = htf_ma3;
   __sv_htf_ma4 = htf_ma4;
   __sv_htf_ma5 = htf_ma5;
   __sv_htf_ma6 = htf_ma6;
   __sv_htf_ma7 = htf_ma7;
   __sv_htf_ma8 = htf_ma8;
   __sv_htf_ma9 = htf_ma9;
   __sv_htf_ma10 = htf_ma10;
   __sv_cloudcolour1 = cloudcolour1;
   __sv_cloudcolour2 = cloudcolour2;
   __sv_cloudcolour3 = cloudcolour3;
   __sv_cloudcolour4 = cloudcolour4;
   __sv_cloudcolour5 = cloudcolour5;
   __sv_mashortcolor1 = mashortcolor1;
   __sv_mashortcolor2 = mashortcolor2;
   __sv_mashortcolor3 = mashortcolor3;
   __sv_mashortcolor4 = mashortcolor4;
   __sv_mashortcolor5 = mashortcolor5;
   __sv_malongcolor1 = malongcolor1;
   __sv_malongcolor2 = malongcolor2;
   __sv_malongcolor3 = malongcolor3;
   __sv_malongcolor4 = malongcolor4;
   __sv_malongcolor5 = malongcolor5;
   pine_draw_mark();
   __pineSaveGen++;   // helpers' static arrays snapshot lazily
}
void __pineRestoreState()
{
   htf_ma1 = __sv_htf_ma1;
   htf_ma2 = __sv_htf_ma2;
   htf_ma3 = __sv_htf_ma3;
   htf_ma4 = __sv_htf_ma4;
   htf_ma5 = __sv_htf_ma5;
   htf_ma6 = __sv_htf_ma6;
   htf_ma7 = __sv_htf_ma7;
   htf_ma8 = __sv_htf_ma8;
   htf_ma9 = __sv_htf_ma9;
   htf_ma10 = __sv_htf_ma10;
   cloudcolour1 = __sv_cloudcolour1;
   cloudcolour2 = __sv_cloudcolour2;
   cloudcolour3 = __sv_cloudcolour3;
   cloudcolour4 = __sv_cloudcolour4;
   cloudcolour5 = __sv_cloudcolour5;
   mashortcolor1 = __sv_mashortcolor1;
   mashortcolor2 = __sv_mashortcolor2;
   mashortcolor3 = __sv_mashortcolor3;
   mashortcolor4 = __sv_mashortcolor4;
   mashortcolor5 = __sv_mashortcolor5;
   malongcolor1 = __sv_malongcolor1;
   malongcolor2 = __sv_malongcolor2;
   malongcolor3 = __sv_malongcolor3;
   malongcolor4 = __sv_malongcolor4;
   malongcolor5 = __sv_malongcolor5;
   pine_draw_rollback();
   __pineRestoreGen++;
   __pineRestoreSaveGen = __pineSaveGen;
}
void __pineSaveInitial()
{
   __si_htf_ma1 = htf_ma1;
   __si_htf_ma2 = htf_ma2;
   __si_htf_ma3 = htf_ma3;
   __si_htf_ma4 = htf_ma4;
   __si_htf_ma5 = htf_ma5;
   __si_htf_ma6 = htf_ma6;
   __si_htf_ma7 = htf_ma7;
   __si_htf_ma8 = htf_ma8;
   __si_htf_ma9 = htf_ma9;
   __si_htf_ma10 = htf_ma10;
   __si_cloudcolour1 = cloudcolour1;
   __si_cloudcolour2 = cloudcolour2;
   __si_cloudcolour3 = cloudcolour3;
   __si_cloudcolour4 = cloudcolour4;
   __si_cloudcolour5 = cloudcolour5;
   __si_mashortcolor1 = mashortcolor1;
   __si_mashortcolor2 = mashortcolor2;
   __si_mashortcolor3 = mashortcolor3;
   __si_mashortcolor4 = mashortcolor4;
   __si_mashortcolor5 = mashortcolor5;
   __si_malongcolor1 = malongcolor1;
   __si_malongcolor2 = malongcolor2;
   __si_malongcolor3 = malongcolor3;
   __si_malongcolor4 = malongcolor4;
   __si_malongcolor5 = malongcolor5;
   pine_draw_save_initial();
}
void __pineRestoreInitial()
{
   htf_ma1 = __si_htf_ma1;
   htf_ma2 = __si_htf_ma2;
   htf_ma3 = __si_htf_ma3;
   htf_ma4 = __si_htf_ma4;
   htf_ma5 = __si_htf_ma5;
   htf_ma6 = __si_htf_ma6;
   htf_ma7 = __si_htf_ma7;
   htf_ma8 = __si_htf_ma8;
   htf_ma9 = __si_htf_ma9;
   htf_ma10 = __si_htf_ma10;
   cloudcolour1 = __si_cloudcolour1;
   cloudcolour2 = __si_cloudcolour2;
   cloudcolour3 = __si_cloudcolour3;
   cloudcolour4 = __si_cloudcolour4;
   cloudcolour5 = __si_cloudcolour5;
   mashortcolor1 = __si_mashortcolor1;
   mashortcolor2 = __si_mashortcolor2;
   mashortcolor3 = __si_mashortcolor3;
   mashortcolor4 = __si_mashortcolor4;
   mashortcolor5 = __si_mashortcolor5;
   malongcolor1 = __si_malongcolor1;
   malongcolor2 = __si_malongcolor2;
   malongcolor3 = __si_malongcolor3;
   malongcolor4 = __si_malongcolor4;
   malongcolor5 = __si_malongcolor5;
   pine_draw_reset();
   __pineInitGen++;
}

string matype = "";   // input the script modifies; reset each bar
double __st0[];    // accumulator for one stateful call site
double __stb0[];   // secondary buffer (e.g. true range for ATR)
double __st1[];    // accumulator for one stateful call site
double __stb1[];   // secondary buffer (e.g. true range for ATR)
double __st2[];    // accumulator for one stateful call site
double __stb2[];   // secondary buffer (e.g. true range for ATR)
double __st3[];    // accumulator for one stateful call site
double __stb3[];   // secondary buffer (e.g. true range for ATR)
double __st4[];    // accumulator for one stateful call site
double __stb4[];   // secondary buffer (e.g. true range for ATR)
double __st5[];    // accumulator for one stateful call site
double __stb5[];   // secondary buffer (e.g. true range for ATR)
double __st6[];    // accumulator for one stateful call site
double __stb6[];   // secondary buffer (e.g. true range for ATR)
double __st7[];    // accumulator for one stateful call site
double __stb7[];   // secondary buffer (e.g. true range for ATR)
double __st8[];    // accumulator for one stateful call site
double __stb8[];   // secondary buffer (e.g. true range for ATR)
double __st9[];    // accumulator for one stateful call site
double __stb9[];   // secondary buffer (e.g. true range for ATR)
double __src[];   // Pine's `src` as a real series, filled per bar

//--- inputs
enum ENUM_MATYPE_OPTS
{
   matype_opt0,   // EMA
   matype_opt1   // SMA
};
string matype_Labels[] = {"EMA", "SMA"};
input ENUM_MATYPE_OPTS matype_Input = matype_opt0;   // MA Type
input int ma_len1 = 8;   // Short EMA1 Length
input int ma_len2 = 9;   // Long EMA1 Length
input int ma_len3 = 5;   // Short EMA2 Length
input int ma_len4 = 12;   // Long EMA2 Length
input int ma_len5 = 34;   // Short EMA3 Length
input int ma_len6 = 50;   // Long EMA3 Length
input int ma_len7 = 72;   // Short EMA4 Length
input int ma_len8 = 89;   // Long EMA4 Length
input int ma_len9 = 180;   // Short EMA5 Length
input int ma_len10 = 200;   // Long EMA5 Length
input ENUM_APPLIED_PRICE src = PRICE_MEDIAN;   // Source
input int ma_offset = 0;   // Offset
input bool showlong = false;   // Show Long Alerts
input bool showshort = false;   // Show Short Alerts
input bool showLine = false;   // Display EMA Line
input bool ema1 = true;   // Show EMA Cloud-1
input bool ema2 = true;   // Show EMA Cloud-2
input bool ema3 = true;   // Show EMA Cloud-3
input bool ema4 = false;   // Show EMA Cloud-4
input bool ema5 = false;   // Show EMA Cloud-5
input int emacloudleading = 0;   // Leading Period For EMA Cloud

//--- user functions
double f_ma(const int malen, const int __pineBar)
{
   double result = 0;
   if((matype == "EMA"))
   {
      result = pine_ema(__src, __st0, __pineBar, (int)(malen));
   }
   if((matype == "SMA"))
   {
      result = pine_sma(__src, __pineBar, (int)(malen));
   }
   return result;
   return PINE_NA;
}

double f_ma__site1(const int malen, const int __pineBar)
{
   double result = 0;
   if((matype == "EMA"))
   {
      result = pine_ema(__src, __st1, __pineBar, (int)(malen));
   }
   if((matype == "SMA"))
   {
      result = pine_sma(__src, __pineBar, (int)(malen));
   }
   return result;
   return PINE_NA;
}

double f_ma__site2(const int malen, const int __pineBar)
{
   double result = 0;
   if((matype == "EMA"))
   {
      result = pine_ema(__src, __st2, __pineBar, (int)(malen));
   }
   if((matype == "SMA"))
   {
      result = pine_sma(__src, __pineBar, (int)(malen));
   }
   return result;
   return PINE_NA;
}

double f_ma__site3(const int malen, const int __pineBar)
{
   double result = 0;
   if((matype == "EMA"))
   {
      result = pine_ema(__src, __st3, __pineBar, (int)(malen));
   }
   if((matype == "SMA"))
   {
      result = pine_sma(__src, __pineBar, (int)(malen));
   }
   return result;
   return PINE_NA;
}

double f_ma__site4(const int malen, const int __pineBar)
{
   double result = 0;
   if((matype == "EMA"))
   {
      result = pine_ema(__src, __st4, __pineBar, (int)(malen));
   }
   if((matype == "SMA"))
   {
      result = pine_sma(__src, __pineBar, (int)(malen));
   }
   return result;
   return PINE_NA;
}

double f_ma__site5(const int malen, const int __pineBar)
{
   double result = 0;
   if((matype == "EMA"))
   {
      result = pine_ema(__src, __st5, __pineBar, (int)(malen));
   }
   if((matype == "SMA"))
   {
      result = pine_sma(__src, __pineBar, (int)(malen));
   }
   return result;
   return PINE_NA;
}

double f_ma__site6(const int malen, const int __pineBar)
{
   double result = 0;
   if((matype == "EMA"))
   {
      result = pine_ema(__src, __st6, __pineBar, (int)(malen));
   }
   if((matype == "SMA"))
   {
      result = pine_sma(__src, __pineBar, (int)(malen));
   }
   return result;
   return PINE_NA;
}

double f_ma__site7(const int malen, const int __pineBar)
{
   double result = 0;
   if((matype == "EMA"))
   {
      result = pine_ema(__src, __st7, __pineBar, (int)(malen));
   }
   if((matype == "SMA"))
   {
      result = pine_sma(__src, __pineBar, (int)(malen));
   }
   return result;
   return PINE_NA;
}

double f_ma__site8(const int malen, const int __pineBar)
{
   double result = 0;
   if((matype == "EMA"))
   {
      result = pine_ema(__src, __st8, __pineBar, (int)(malen));
   }
   if((matype == "SMA"))
   {
      result = pine_sma(__src, __pineBar, (int)(malen));
   }
   return result;
   return PINE_NA;
}

double f_ma__site9(const int malen, const int __pineBar)
{
   double result = 0;
   if((matype == "EMA"))
   {
      result = pine_ema(__src, __st9, __pineBar, (int)(malen));
   }
   if((matype == "SMA"))
   {
      result = pine_sma(__src, __pineBar, (int)(malen));
   }
   return result;
   return PINE_NA;
}

int OnInit()
{
   matype = matype_Labels[(int)matype_Input];
   if(emacloudleading < 0) { Print("Leading Period For EMA Cloud", " must be at least 0"); return INIT_PARAMETERS_INCORRECT; }
   SetIndexBuffer(0, PineFill0, INDICATOR_DATA);
   SetIndexBuffer(1, PineFill1, INDICATOR_DATA);
   SetIndexBuffer(2, PineFill2, INDICATOR_DATA);
   SetIndexBuffer(3, PineFill3, INDICATOR_DATA);
   SetIndexBuffer(4, PineFill4, INDICATOR_DATA);
   SetIndexBuffer(5, PineFill5, INDICATOR_DATA);
   SetIndexBuffer(6, PineFill6, INDICATOR_DATA);
   SetIndexBuffer(7, PineFill7, INDICATOR_DATA);
   SetIndexBuffer(8, PineFill8, INDICATOR_DATA);
   SetIndexBuffer(9, PineFill9, INDICATOR_DATA);
   SetIndexBuffer(10, Buf10, INDICATOR_DATA);
   SetIndexBuffer(11, Buf11, INDICATOR_COLOR_INDEX);
   SetIndexBuffer(12, Buf12, INDICATOR_DATA);
   SetIndexBuffer(13, Buf13, INDICATOR_COLOR_INDEX);
   SetIndexBuffer(14, Buf14, INDICATOR_DATA);
   SetIndexBuffer(15, Buf15, INDICATOR_COLOR_INDEX);
   SetIndexBuffer(16, Buf16, INDICATOR_DATA);
   SetIndexBuffer(17, Buf17, INDICATOR_COLOR_INDEX);
   SetIndexBuffer(18, Buf18, INDICATOR_DATA);
   SetIndexBuffer(19, Buf19, INDICATOR_COLOR_INDEX);
   SetIndexBuffer(20, Buf20, INDICATOR_DATA);
   SetIndexBuffer(21, Buf21, INDICATOR_COLOR_INDEX);
   SetIndexBuffer(22, Buf22, INDICATOR_DATA);
   SetIndexBuffer(23, Buf23, INDICATOR_COLOR_INDEX);
   SetIndexBuffer(24, Buf24, INDICATOR_DATA);
   SetIndexBuffer(25, Buf25, INDICATOR_COLOR_INDEX);
   SetIndexBuffer(26, Buf26, INDICATOR_DATA);
   SetIndexBuffer(27, Buf27, INDICATOR_COLOR_INDEX);
   SetIndexBuffer(28, Buf28, INDICATOR_DATA);
   SetIndexBuffer(29, Buf29, INDICATOR_COLOR_INDEX);
   PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, EMPTY_VALUE);
   PlotIndexSetDouble(1, PLOT_EMPTY_VALUE, EMPTY_VALUE);
   PlotIndexSetDouble(2, PLOT_EMPTY_VALUE, EMPTY_VALUE);
   PlotIndexSetDouble(3, PLOT_EMPTY_VALUE, EMPTY_VALUE);
   PlotIndexSetDouble(4, PLOT_EMPTY_VALUE, EMPTY_VALUE);
   PlotIndexSetDouble(5, PLOT_EMPTY_VALUE, EMPTY_VALUE);
   PlotIndexSetDouble(6, PLOT_EMPTY_VALUE, EMPTY_VALUE);
   PlotIndexSetDouble(7, PLOT_EMPTY_VALUE, EMPTY_VALUE);
   PlotIndexSetDouble(8, PLOT_EMPTY_VALUE, EMPTY_VALUE);
   PlotIndexSetDouble(9, PLOT_EMPTY_VALUE, EMPTY_VALUE);
   PlotIndexSetDouble(10, PLOT_EMPTY_VALUE, EMPTY_VALUE);
   PlotIndexSetDouble(11, PLOT_EMPTY_VALUE, EMPTY_VALUE);
   PlotIndexSetDouble(12, PLOT_EMPTY_VALUE, EMPTY_VALUE);
   PlotIndexSetDouble(13, PLOT_EMPTY_VALUE, EMPTY_VALUE);
   PlotIndexSetDouble(14, PLOT_EMPTY_VALUE, EMPTY_VALUE);
   PlotIndexSetInteger(0, PLOT_SHOW_DATA, false);
   PlotIndexSetInteger(1, PLOT_SHOW_DATA, false);
   PlotIndexSetInteger(2, PLOT_SHOW_DATA, false);
   PlotIndexSetInteger(3, PLOT_SHOW_DATA, false);
   PlotIndexSetInteger(4, PLOT_SHOW_DATA, false);
   PlotIndexSetInteger(5, PLOT_SHIFT, (int)(emacloudleading));
   PlotIndexSetInteger(6, PLOT_SHIFT, (int)(emacloudleading));
   PlotIndexSetInteger(7, PLOT_SHIFT, (int)(emacloudleading));
   PlotIndexSetInteger(8, PLOT_SHIFT, (int)(emacloudleading));
   PlotIndexSetInteger(9, PLOT_SHIFT, (int)(emacloudleading));
   PlotIndexSetInteger(10, PLOT_SHIFT, (int)(emacloudleading));
   PlotIndexSetInteger(11, PLOT_SHIFT, (int)(emacloudleading));
   PlotIndexSetInteger(12, PLOT_SHIFT, (int)(emacloudleading));
   PlotIndexSetInteger(13, PLOT_SHIFT, (int)(emacloudleading));
   PlotIndexSetInteger(14, PLOT_SHIFT, (int)(emacloudleading));
   IndicatorSetString(INDICATOR_SHORTNAME, "Ripster EMA Clouds");
   __pineSaveInitial();
   return INIT_SUCCEEDED;
}

//--- one bar == one evaluation of the original Pine script
void PineBar(const int __pineBar,
             const double   &open[],  const double &high[],
             const double   &low[],   const double &close[],
             const long     &volume[],
             const datetime &time[])
{
   __src[__pineBar] = pine_source(src, open, high, low, close, __pineBar);
   if(__pineBar > 0)
   {
      mashort1[__pineBar] = mashort1[__pineBar - 1];
      malong1[__pineBar] = malong1[__pineBar - 1];
      mashort2[__pineBar] = mashort2[__pineBar - 1];
      malong2[__pineBar] = malong2[__pineBar - 1];
      mashort3[__pineBar] = mashort3[__pineBar - 1];
      malong3[__pineBar] = malong3[__pineBar - 1];
      mashort4[__pineBar] = mashort4[__pineBar - 1];
      malong4[__pineBar] = malong4[__pineBar - 1];
      mashort5[__pineBar] = mashort5[__pineBar - 1];
      malong5[__pineBar] = malong5[__pineBar - 1];
   }
   matype = matype_Labels[(int)matype_Input];
   htf_ma1 = f_ma(ma_len1, __pineBar);
   htf_ma2 = f_ma__site1(ma_len2, __pineBar);
   htf_ma3 = f_ma__site2(ma_len3, __pineBar);
   htf_ma4 = f_ma__site3(ma_len4, __pineBar);
   htf_ma5 = f_ma__site4(ma_len5, __pineBar);
   htf_ma6 = f_ma__site5(ma_len6, __pineBar);
   htf_ma7 = f_ma__site6(ma_len7, __pineBar);
   htf_ma8 = f_ma__site7(ma_len8, __pineBar);
   htf_ma9 = f_ma__site8(ma_len9, __pineBar);
   htf_ma10 = f_ma__site9(ma_len10, __pineBar);
   mashort1[__pineBar] = htf_ma1;
   malong1[__pineBar] = htf_ma2;
   mashort2[__pineBar] = htf_ma3;
   malong2[__pineBar] = htf_ma4;
   mashort3[__pineBar] = htf_ma5;
   malong3[__pineBar] = htf_ma6;
   mashort4[__pineBar] = htf_ma7;
   malong4[__pineBar] = htf_ma8;
   mashort5[__pineBar] = htf_ma9;
   malong5[__pineBar] = htf_ma10;
   cloudcolour1 = ((mashort1[__pineBar] >= malong1[__pineBar]) ? C'3,97,3' : C'136,14,79');
   cloudcolour2 = ((mashort2[__pineBar] >= malong2[__pineBar]) ? C'76,175,80' : C'244,67,54');
   cloudcolour3 = ((mashort3[__pineBar] >= malong3[__pineBar]) ? C'33,150,243' : C'255,183,77');
   cloudcolour4 = ((mashort4[__pineBar] >= malong4[__pineBar]) ? C'0,150,136' : C'240,98,146');
   cloudcolour5 = ((mashort5[__pineBar] >= malong5[__pineBar]) ? C'5,190,213' : C'230,81,0');
   mashortcolor1 = ((mashort1[__pineBar] >= pine_hist(mashort1, __pineBar, (int)(1))) ? C'128,128,0' : C'136,14,79');
   mashortcolor2 = ((mashort2[__pineBar] >= pine_hist(mashort2, __pineBar, (int)(1))) ? C'128,128,0' : C'136,14,79');
   mashortcolor3 = ((mashort3[__pineBar] >= pine_hist(mashort3, __pineBar, (int)(1))) ? C'128,128,0' : C'136,14,79');
   mashortcolor4 = ((mashort4[__pineBar] >= pine_hist(mashort4, __pineBar, (int)(1))) ? C'128,128,0' : C'136,14,79');
   mashortcolor5 = ((mashort5[__pineBar] >= pine_hist(mashort5, __pineBar, (int)(1))) ? pine_color_rgb((int)(179), (int)(179), (int)(43)) : C'136,14,79');
   malongcolor1 = ((malong1[__pineBar] >= pine_hist(malong1, __pineBar, (int)(1))) ? C'76,175,80' : C'242,54,69');
   malongcolor2 = ((malong2[__pineBar] >= pine_hist(malong2, __pineBar, (int)(1))) ? C'76,175,80' : C'242,54,69');
   malongcolor3 = ((malong3[__pineBar] >= pine_hist(malong3, __pineBar, (int)(1))) ? C'76,175,80' : C'242,54,69');
   malongcolor4 = ((malong4[__pineBar] >= pine_hist(malong4, __pineBar, (int)(1))) ? C'76,175,80' : C'242,54,69');
   malongcolor5 = ((malong5[__pineBar] >= pine_hist(malong5, __pineBar, (int)(1))) ? C'76,175,80' : C'242,54,69');
   double __pinePlotValue5 = (ema1 ? mashort1[__pineBar] : PINE_NA);
   double __pinePlotColour5 = (double)((showLine ? mashortcolor1 : PINE_NA));
   Buf10[__pineBar] = __pinePlotValue5;
   Buf11[__pineBar] = pine_color_slot(5, pine_na(__pinePlotColour5) ? clrNONE : (color)__pinePlotColour5, __pal5, __paln5);
   double __pinePlotValue6 = (ema2 ? mashort2[__pineBar] : PINE_NA);
   double __pinePlotColour6 = (double)((showLine ? mashortcolor2 : PINE_NA));
   Buf12[__pineBar] = __pinePlotValue6;
   Buf13[__pineBar] = pine_color_slot(6, pine_na(__pinePlotColour6) ? clrNONE : (color)__pinePlotColour6, __pal6, __paln6);
   double __pinePlotValue7 = (ema3 ? mashort3[__pineBar] : PINE_NA);
   double __pinePlotColour7 = (double)((showLine ? mashortcolor3 : PINE_NA));
   Buf14[__pineBar] = __pinePlotValue7;
   Buf15[__pineBar] = pine_color_slot(7, pine_na(__pinePlotColour7) ? clrNONE : (color)__pinePlotColour7, __pal7, __paln7);
   double __pinePlotValue8 = (ema4 ? mashort4[__pineBar] : PINE_NA);
   double __pinePlotColour8 = (double)((showLine ? mashortcolor4 : PINE_NA));
   Buf16[__pineBar] = __pinePlotValue8;
   Buf17[__pineBar] = pine_color_slot(8, pine_na(__pinePlotColour8) ? clrNONE : (color)__pinePlotColour8, __pal8, __paln8);
   double __pinePlotValue9 = (ema5 ? mashort5[__pineBar] : PINE_NA);
   double __pinePlotColour9 = (double)((showLine ? mashortcolor5 : PINE_NA));
   Buf18[__pineBar] = __pinePlotValue9;
   Buf19[__pineBar] = pine_color_slot(9, pine_na(__pinePlotColour9) ? clrNONE : (color)__pinePlotColour9, __pal9, __paln9);
   double __pinePlotValue10 = (ema1 ? malong1[__pineBar] : PINE_NA);
   double __pinePlotColour10 = (double)((showLine ? malongcolor1 : PINE_NA));
   Buf20[__pineBar] = __pinePlotValue10;
   Buf21[__pineBar] = pine_color_slot(10, pine_na(__pinePlotColour10) ? clrNONE : (color)__pinePlotColour10, __pal10, __paln10);
   double __pinePlotValue11 = (ema2 ? malong2[__pineBar] : PINE_NA);
   double __pinePlotColour11 = (double)((showLine ? malongcolor2 : PINE_NA));
   Buf22[__pineBar] = __pinePlotValue11;
   Buf23[__pineBar] = pine_color_slot(11, pine_na(__pinePlotColour11) ? clrNONE : (color)__pinePlotColour11, __pal11, __paln11);
   double __pinePlotValue12 = (ema3 ? malong3[__pineBar] : PINE_NA);
   double __pinePlotColour12 = (double)((showLine ? malongcolor3 : PINE_NA));
   Buf24[__pineBar] = __pinePlotValue12;
   Buf25[__pineBar] = pine_color_slot(12, pine_na(__pinePlotColour12) ? clrNONE : (color)__pinePlotColour12, __pal12, __paln12);
   double __pinePlotValue13 = (ema4 ? malong4[__pineBar] : PINE_NA);
   double __pinePlotColour13 = (double)((showLine ? malongcolor4 : PINE_NA));
   Buf26[__pineBar] = __pinePlotValue13;
   Buf27[__pineBar] = pine_color_slot(13, pine_na(__pinePlotColour13) ? clrNONE : (color)__pinePlotColour13, __pal13, __paln13);
   double __pinePlotValue14 = (ema5 ? malong5[__pineBar] : PINE_NA);
   double __pinePlotColour14 = (double)((showLine ? malongcolor5 : PINE_NA));
   Buf28[__pineBar] = __pinePlotValue14;
   Buf29[__pineBar] = pine_color_slot(14, pine_na(__pinePlotColour14) ? clrNONE : (color)__pinePlotColour14, __pal14, __paln14);
   PineFill0[__pineBar] = Buf10[__pineBar];
   PineFill1[__pineBar] = Buf20[__pineBar];
   PineFill2[__pineBar] = Buf12[__pineBar];
   PineFill3[__pineBar] = Buf22[__pineBar];
   PineFill4[__pineBar] = Buf14[__pineBar];
   PineFill5[__pineBar] = Buf24[__pineBar];
   PineFill6[__pineBar] = Buf16[__pineBar];
   PineFill7[__pineBar] = Buf26[__pineBar];
   PineFill8[__pineBar] = Buf18[__pineBar];
   PineFill9[__pineBar] = Buf28[__pineBar];
}

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[])
{
   // Pine evaluates oldest-to-newest. MQL4 hands OnCalculate
   // SERIES-indexed arrays (0 == newest) while MQL5 hands over
   // oldest-first, so the direction is forced explicitly rather
   // than relying on either default. `x[n]` is then index i - n
   // in both dialects, and the generated logic is identical.
   ArraySetAsSeries(open,  false);
   ArraySetAsSeries(high,  false);
   ArraySetAsSeries(low,   false);
   ArraySetAsSeries(close, false);
   ArraySetAsSeries(tick_volume, false);
   ArraySetAsSeries(volume, false);
   ArraySetAsSeries(time,  false);
   ArrayResize(mashort1, rates_total);
   ArrayResize(malong1, rates_total);
   ArrayResize(mashort2, rates_total);
   ArrayResize(malong2, rates_total);
   ArrayResize(mashort3, rates_total);
   ArrayResize(malong3, rates_total);
   ArrayResize(mashort4, rates_total);
   ArrayResize(malong4, rates_total);
   ArrayResize(mashort5, rates_total);
   ArrayResize(malong5, rates_total);
   ArrayResize(__st0, rates_total);
   ArrayResize(__stb0, rates_total);
   ArrayResize(__st1, rates_total);
   ArrayResize(__stb1, rates_total);
   ArrayResize(__st2, rates_total);
   ArrayResize(__stb2, rates_total);
   ArrayResize(__st3, rates_total);
   ArrayResize(__stb3, rates_total);
   ArrayResize(__st4, rates_total);
   ArrayResize(__stb4, rates_total);
   ArrayResize(__st5, rates_total);
   ArrayResize(__stb5, rates_total);
   ArrayResize(__st6, rates_total);
   ArrayResize(__stb6, rates_total);
   ArrayResize(__st7, rates_total);
   ArrayResize(__stb7, rates_total);
   ArrayResize(__st8, rates_total);
   ArrayResize(__stb8, rates_total);
   ArrayResize(__st9, rates_total);
   ArrayResize(__stb9, rates_total);
   ArrayResize(__src, rates_total);
   if(prev_calculated == 0)
   {
      ArrayInitialize(mashort1, PINE_NA);
      ArrayInitialize(malong1, PINE_NA);
      ArrayInitialize(mashort2, PINE_NA);
      ArrayInitialize(malong2, PINE_NA);
      ArrayInitialize(mashort3, PINE_NA);
      ArrayInitialize(malong3, PINE_NA);
      ArrayInitialize(mashort4, PINE_NA);
      ArrayInitialize(malong4, PINE_NA);
      ArrayInitialize(mashort5, PINE_NA);
      ArrayInitialize(malong5, PINE_NA);
      ArrayInitialize(__st0, PINE_NA);
      ArrayInitialize(__stb0, PINE_NA);
      ArrayInitialize(__st1, PINE_NA);
      ArrayInitialize(__stb1, PINE_NA);
      ArrayInitialize(__st2, PINE_NA);
      ArrayInitialize(__stb2, PINE_NA);
      ArrayInitialize(__st3, PINE_NA);
      ArrayInitialize(__stb3, PINE_NA);
      ArrayInitialize(__st4, PINE_NA);
      ArrayInitialize(__stb4, PINE_NA);
      ArrayInitialize(__st5, PINE_NA);
      ArrayInitialize(__stb5, PINE_NA);
      ArrayInitialize(__st6, PINE_NA);
      ArrayInitialize(__stb6, PINE_NA);
      ArrayInitialize(__st7, PINE_NA);
      ArrayInitialize(__stb7, PINE_NA);
      ArrayInitialize(__st8, PINE_NA);
      ArrayInitialize(__stb8, PINE_NA);
      ArrayInitialize(__st9, PINE_NA);
      ArrayInitialize(__stb9, PINE_NA);
      ArrayInitialize(__src, PINE_NA);
   }

   __pineLastBar = rates_total - 1;
   const int start = (prev_calculated > 1) ? prev_calculated - 1 : 0;
   static bool __pineRealVolume = false;
   if(start == 0)
   {
      __pineRestoreInitial();
      __pineSnapBar = -1;
      __pineRealVolume = rates_total > 0 && volume[rates_total - 1] > 0;
   }
   __pineRealtime = prev_calculated > 0;
   for(int __pineBar = start; __pineBar < rates_total; __pineBar++)
   {
      if(__pineBar == __pineSnapBar)
         __pineRestoreState();   // a re-run of this bar: back to its start
      else if(__pineBar == __pineLastBar)
      {
         __pineSaveState();      // the forming bar: remember the state it starts from
         __pineSnapBar = __pineBar;
      }
      if(__pineRealVolume) PineBar(__pineBar, open, high, low, close, volume, time);
      else PineBar(__pineBar, open, high, low, close, tick_volume, time);
   }

   return rates_total;
}

Original Pine Script

© ripster47 — Mozilla Public License 2.0. Reproduced for attribution and comparison; the converted code above is a derivative work offered under the same licence.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/

// © ripster47



//@version=4

study("Ripster EMA Clouds","Ripster EMA Clouds", overlay=true)

matype = input(title="MA Type", type=input.string, defval="EMA", options=["EMA", "SMA"])



ma_len1 = input(title="Short EMA1 Length", type=input.integer, defval=8)

ma_len2 = input(title="Long EMA1 Length", type=input.integer, defval=9)

ma_len3 = input(title="Short EMA2 Length", type=input.integer, defval=5)

ma_len4 = input(title="Long EMA2 Length", type=input.integer, defval=12)

ma_len5 = input(title="Short EMA3 Length", type=input.integer, defval=34)

ma_len6 = input(title="Long EMA3 Length", type=input.integer, defval=50)

ma_len7 = input(title="Short EMA4 Length", type=input.integer, defval=72)

ma_len8 = input(title="Long EMA4 Length", type=input.integer, defval=89)

ma_len9 = input(title="Short EMA5 Length", type=input.integer, defval=180)

ma_len10 = input(title="Long EMA5 Length", type=input.integer, defval=200)



src = input(title="Source", type=input.source, defval=hl2)

ma_offset = input(title="Offset", type=input.integer, defval=0)

//res = input(title="Resolution", type=resolution, defval="240")



f_ma(malen) =>

    float result = 0

    if (matype == "EMA")

        result := ema(src, malen)

    if (matype == "SMA")

        result := sma(src, malen)

    result

    

htf_ma1 = f_ma(ma_len1)

htf_ma2 = f_ma(ma_len2)

htf_ma3 = f_ma(ma_len3)

htf_ma4 = f_ma(ma_len4)

htf_ma5 = f_ma(ma_len5)

htf_ma6 = f_ma(ma_len6)

htf_ma7 = f_ma(ma_len7)

htf_ma8 = f_ma(ma_len8)

htf_ma9 = f_ma(ma_len9)

htf_ma10 = f_ma(ma_len10)



//plot(out1, color=green, offset=ma_offset)

//plot(out2, color=red, offset=ma_offset)



//lengthshort = input(8, minval = 1, title = "Short EMA Length")

//lengthlong = input(200, minval = 2, title = "Long EMA Length")

//emacloudleading = input(50, minval = 0, title = "Leading Period For EMA Cloud")

//src = input(hl2, title = "Source")

showlong = input(false, title="Show Long Alerts")

showshort = input(false, title="Show Short Alerts")

showLine = input(false, title="Display EMA Line")

ema1 = input(true, title="Show EMA Cloud-1")

ema2 = input(true, title="Show EMA Cloud-2")

ema3 = input(true, title="Show EMA Cloud-3")

ema4 = input(false, title="Show EMA Cloud-4")

ema5 = input(false, title="Show EMA Cloud-5")



emacloudleading = input(0, minval=0, title="Leading Period For EMA Cloud")

mashort1 = htf_ma1

malong1 = htf_ma2

mashort2 = htf_ma3

malong2 = htf_ma4

mashort3 = htf_ma5

malong3 = htf_ma6

mashort4 = htf_ma7

malong4 = htf_ma8

mashort5 = htf_ma9

malong5 = htf_ma10



cloudcolour1 = mashort1 >= malong1 ? #036103 : #880e4f

cloudcolour2 = mashort2 >= malong2 ? #4caf50 : #f44336

cloudcolour3 = mashort3 >= malong3 ? #2196f3 : #ffb74d

cloudcolour4 = mashort4 >= malong4 ? #009688 : #f06292

cloudcolour5 = mashort5 >= malong5 ? #05bed5 : #e65100

//03abc1



mashortcolor1 = mashort1 >= mashort1[1] ? color.olive : color.maroon

mashortcolor2 = mashort2 >= mashort2[1] ? color.olive : color.maroon

mashortcolor3 = mashort3 >= mashort3[1] ? color.olive : color.maroon

mashortcolor4 = mashort4 >= mashort4[1] ? color.olive : color.maroon

mashortcolor5 = mashort5 >= mashort5[1] ? color.rgb(179, 179, 43) : color.maroon





mashortline1 = plot(ema1 ? mashort1 : na, color=showLine ? mashortcolor1 : na, linewidth=1, offset=emacloudleading, title="Short Leading EMA1")

mashortline2 = plot(ema2 ? mashort2 : na, color=showLine ? mashortcolor2 : na, linewidth=1, offset=emacloudleading, title="Short Leading EMA2")

mashortline3 = plot(ema3 ?mashort3 : na, color=showLine ? mashortcolor3 : na, linewidth=1, offset=emacloudleading, title="Short Leading EMA3")

mashortline4 = plot(ema4 ? mashort4 :na , color=showLine ? mashortcolor4 : na, linewidth=1, offset=emacloudleading, title="Short Leading EMA4")

mashortline5 = plot(ema5 ? mashort5 : na, color=showLine ? mashortcolor5 : na, linewidth=1, offset=emacloudleading, title="Short Leading EMA5")



malongcolor1 = malong1 >= malong1[1] ? color.green : color.red

malongcolor2 = malong2 >= malong2[1] ? color.green : color.red

malongcolor3 = malong3 >= malong3[1] ? color.green : color.red

malongcolor4 = malong4 >= malong4[1] ? color.green : color.red

malongcolor5 = malong5 >= malong5[1] ? color.green : color.red



malongline1 = plot(ema1 ? malong1 : na, color=showLine ? malongcolor1 : na, linewidth=3, offset=emacloudleading, title="Long Leading EMA1")

malongline2 = plot(ema2 ? malong2 : na, color=showLine ? malongcolor2 : na, linewidth=3, offset=emacloudleading, title="Long Leading EMA2")

malongline3 = plot(ema3 ? malong3 : na, color=showLine ? malongcolor3 : na, linewidth=3, offset=emacloudleading, title="Long Leading EMA3")

malongline4 = plot(ema4 ? malong4 : na, color=showLine ? malongcolor4 : na, linewidth=3, offset=emacloudleading, title="Long Leading EMA4")

malongline5 = plot(ema5 ? malong5 : na, color=showLine ? malongcolor5 : na, linewidth=3, offset=emacloudleading, title="Long Leading EMA5")





// Updated fill function calls using color.new() for transparency

fill(mashortline1, malongline1, color=color.new(cloudcolour1, 45), title="MA Cloud1")

fill(mashortline2, malongline2, color=color.new(cloudcolour2, 65), title="MA Cloud2")

fill(mashortline3, malongline3, color=color.new(cloudcolour3, 70), title="MA Cloud3")

fill(mashortline4, malongline4, color=color.new(cloudcolour4, 65), title="MA Cloud4")

fill(mashortline5, malongline5, color=color.new(cloudcolour5, 65), title="MA Cloud5")

Convert your own Pine Script to MQL5

Your first conversion is free, in either direction. Paste a TradingView indicator or strategy and get MQL5 or MQL4 source, with every construct the engine could not map flagged by line.

Open the converter

More: all example conversions · how Pine Script maps to MQL5 · how the engine measures