Pivot Point SuperTrend in MQL5 — converted from Pine Script

The Pivot Point SuperTrend indicator by LonesomeTheBlue, 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
3 informational
Source
141 lines of Pine v4

Inputs

InputDefault
Pivot Point Period2
ATR Factor3
ATR Period10
Show Pivot Pointsfalse
Show Buy/Sell Labelstrue
Show PP Center Linefalse
Show Support/Resistancefalse

Plots

PP SuperTrend.

Converted MQL5

Save as pivot-point-supertrend.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: 932e8a338402   status: CLEAN
//| notes: 0 unsupported, 0 warn, 3 info
//| Review, compile and backtest before trading.
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Pivot Point SuperTrend
//| 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 12
#property indicator_plots   8
#property indicator_label1  "H"
#property indicator_type1   DRAW_ARROW
#property indicator_color1  clrDodgerBlue
#property indicator_width1  1
#property indicator_label2  "L"
#property indicator_type2   DRAW_ARROW
#property indicator_color2  clrDodgerBlue
#property indicator_width2  1
#property indicator_label3  "PP SuperTrend"
#property indicator_type3   DRAW_COLOR_LINE
#property indicator_color3  clrDodgerBlue
#property indicator_width3  2
#property indicator_label4  "Plot4"
#property indicator_type4   DRAW_COLOR_LINE
#property indicator_color4  clrDodgerBlue
#property indicator_width4  1
#property indicator_label5  "Buy"
#property indicator_type5   DRAW_ARROW
#property indicator_color5  clrDodgerBlue
#property indicator_width5  1
#property indicator_label6  "Sell"
#property indicator_type6   DRAW_ARROW
#property indicator_color6  clrDodgerBlue
#property indicator_width6  1
#property indicator_label7  "Plot7"
#property indicator_type7   DRAW_COLOR_ARROW
#property indicator_color7  clrDodgerBlue
#property indicator_width7  1
#property indicator_label8  "Plot8"
#property indicator_type8   DRAW_COLOR_ARROW
#property indicator_color8  clrDodgerBlue
#property indicator_width8  1

#include "PineRuntime.mqh"

//--- plot buffers
double Buf0[];
double Buf1[];
double Buf2[];
double Buf3[];
double Buf4[];
double Buf5[];
double Buf6[];
double Buf7[];
double Buf8[];
double Buf9[];
double Buf10[];
double Buf11[];
color  __pal2[64];   // the colours plot 2 has drawn so far; see pine_color_slot
int    __paln2 = 0;
color  __pal3[64];   // the colours plot 3 has drawn so far; see pine_color_slot
int    __paln3 = 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;

//--- 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 ph = PINE_NA;
double pl = PINE_NA;
double center = PINE_NA;
double lastpp = PINE_NA;
double Up = PINE_NA;
double Dn = PINE_NA;
double TUp[];
double TDown[];
double Trend[];
double Trailingsl = PINE_NA;
double linecolor = PINE_NA;
bool bsignal = false;
bool ssignal = false;
double resistance[];
double support[];

//--- live-tick rollback: the state each bar started from
double __sv_ph;
double __si_ph;
double __sv_pl;
double __si_pl;
double __sv_center;
double __si_center;
double __sv_lastpp;
double __si_lastpp;
double __sv_Up;
double __si_Up;
double __sv_Dn;
double __si_Dn;
double __sv_Trailingsl;
double __si_Trailingsl;
double __sv_linecolor;
double __si_linecolor;
bool __sv_bsignal;
bool __si_bsignal;
bool __sv_ssignal;
bool __si_ssignal;
int __pineSnapBar = -1;
void __pineSaveState()
{
   __sv_ph = ph;
   __sv_pl = pl;
   __sv_center = center;
   __sv_lastpp = lastpp;
   __sv_Up = Up;
   __sv_Dn = Dn;
   __sv_Trailingsl = Trailingsl;
   __sv_linecolor = linecolor;
   __sv_bsignal = bsignal;
   __sv_ssignal = ssignal;
   pine_draw_mark();
   __pineSaveGen++;   // helpers' static arrays snapshot lazily
}
void __pineRestoreState()
{
   ph = __sv_ph;
   pl = __sv_pl;
   center = __sv_center;
   lastpp = __sv_lastpp;
   Up = __sv_Up;
   Dn = __sv_Dn;
   Trailingsl = __sv_Trailingsl;
   linecolor = __sv_linecolor;
   bsignal = __sv_bsignal;
   ssignal = __sv_ssignal;
   pine_draw_rollback();
   __pineRestoreGen++;
   __pineRestoreSaveGen = __pineSaveGen;
}
void __pineSaveInitial()
{
   __si_ph = ph;
   __si_pl = pl;
   __si_center = center;
   __si_lastpp = lastpp;
   __si_Up = Up;
   __si_Dn = Dn;
   __si_Trailingsl = Trailingsl;
   __si_linecolor = linecolor;
   __si_bsignal = bsignal;
   __si_ssignal = ssignal;
   pine_draw_save_initial();
}
void __pineRestoreInitial()
{
   ph = __si_ph;
   pl = __si_pl;
   center = __si_center;
   lastpp = __si_lastpp;
   Up = __si_Up;
   Dn = __si_Dn;
   Trailingsl = __si_Trailingsl;
   linecolor = __si_linecolor;
   bsignal = __si_bsignal;
   ssignal = __si_ssignal;
   pine_draw_reset();
   __pineInitGen++;
}

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)

//--- inputs
input int prd = 2;   // Pivot Point Period
input int Factor = 3;   // ATR Factor
input int Pd = 10;   // ATR Period
input bool showpivot = false;   // Show Pivot Points
input bool showlabel = true;   // Show Buy/Sell Labels
input bool showcl = false;   // Show PP Center Line
input bool showsr = false;   // Show Support/Resistance

int OnInit()
{
   if(prd < 1) { Print("Pivot Point Period", " must be at least 1"); return INIT_PARAMETERS_INCORRECT; }
   if(prd > 50) { Print("Pivot Point Period", " must be at most 50"); return INIT_PARAMETERS_INCORRECT; }
   if(Factor < 1) { Print("ATR Factor", " must be at least 1"); return INIT_PARAMETERS_INCORRECT; }
   if(Pd < 1) { Print("ATR Period", " must be at least 1"); return INIT_PARAMETERS_INCORRECT; }
   SetIndexBuffer(0, Buf0, INDICATOR_DATA);
   SetIndexBuffer(1, Buf1, INDICATOR_DATA);
   SetIndexBuffer(2, Buf2, INDICATOR_DATA);
   SetIndexBuffer(3, Buf3, INDICATOR_COLOR_INDEX);
   SetIndexBuffer(4, Buf4, INDICATOR_DATA);
   SetIndexBuffer(5, Buf5, INDICATOR_COLOR_INDEX);
   SetIndexBuffer(6, Buf6, INDICATOR_DATA);
   SetIndexBuffer(7, Buf7, INDICATOR_DATA);
   SetIndexBuffer(8, Buf8, INDICATOR_DATA);
   SetIndexBuffer(9, Buf9, INDICATOR_COLOR_INDEX);
   SetIndexBuffer(10, Buf10, INDICATOR_DATA);
   SetIndexBuffer(11, Buf11, 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);
   PlotIndexSetInteger(4, PLOT_LINE_COLOR, C'0,230,118');
   PlotIndexSetInteger(5, PLOT_LINE_COLOR, C'242,54,69');
   PlotIndexSetInteger(6, PLOT_LINE_COLOR, C'0,230,118');
   PlotIndexSetInteger(7, PLOT_LINE_COLOR, C'242,54,69');
   PlotIndexSetInteger(0, PLOT_DRAW_TYPE, DRAW_ARROW);
   PlotIndexSetInteger(0, PLOT_ARROW, 242);
   PlotIndexSetInteger(0, PLOT_ARROW_SHIFT, -16);
   PlotIndexSetInteger(1, PLOT_DRAW_TYPE, DRAW_ARROW);
   PlotIndexSetInteger(1, PLOT_ARROW, 242);
   PlotIndexSetInteger(1, PLOT_ARROW_SHIFT, 16);
   PlotIndexSetInteger(4, PLOT_DRAW_TYPE, DRAW_ARROW);
   PlotIndexSetInteger(4, PLOT_ARROW, 241);
   PlotIndexSetInteger(4, PLOT_ARROW_SHIFT, -16);
   PlotIndexSetInteger(5, PLOT_DRAW_TYPE, DRAW_ARROW);
   PlotIndexSetInteger(5, PLOT_ARROW, 242);
   PlotIndexSetInteger(5, PLOT_ARROW_SHIFT, -16);
   PlotIndexSetInteger(6, PLOT_DRAW_TYPE, DRAW_COLOR_ARROW);
   PlotIndexSetInteger(6, PLOT_ARROW, 159);
   PlotIndexSetInteger(7, PLOT_DRAW_TYPE, DRAW_COLOR_ARROW);
   PlotIndexSetInteger(7, PLOT_ARROW, 159);
   PlotIndexSetInteger(0, PLOT_SHIFT, (int)((-prd)));
   PlotIndexSetInteger(1, PLOT_SHIFT, (int)((-prd)));
   PlotIndexSetInteger(6, PLOT_SHIFT, (int)((-prd)));
   PlotIndexSetInteger(7, PLOT_SHIFT, (int)((-prd)));
   IndicatorSetString(INDICATOR_SHORTNAME, "Pivot Point SuperTrend");
   __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[])
{
   if(__pineBar > 0)
   {
      TUp[__pineBar] = TUp[__pineBar - 1];
      TDown[__pineBar] = TDown[__pineBar - 1];
      Trend[__pineBar] = Trend[__pineBar - 1];
      resistance[__pineBar] = resistance[__pineBar - 1];
      support[__pineBar] = support[__pineBar - 1];
   }
   ph = pine_pivothigh(high, __pineBar, (int)(prd), (int)(prd));
   pl = pine_pivotlow(low, __pineBar, (int)(prd), (int)(prd));
   lastpp = (pine_truthy(ph) ? ph : (pine_truthy(pl) ? pl : PINE_NA));
   if(pine_truthy(lastpp))
   {
      if(pine_na(center))
      {
         center = lastpp;
      }
      else
      {
         center = pine_div(((center * 2) + lastpp), 3);
      }
   }
   Up = (center - (Factor * pine_atr_hlc(high, low, close, __st0, __stb0, __pineBar, (int)(Pd))));
   Dn = (center + (Factor * pine_atr_hlc(high, low, close, __st1, __stb1, __pineBar, (int)(Pd))));
   TUp[__pineBar] = PINE_NA;
   TDown[__pineBar] = PINE_NA;
   Trend[__pineBar] = 0;
   TUp[__pineBar] = ((pine_hist(close, __pineBar, (int)(1)) > pine_hist(TUp, __pineBar, (int)(1))) ? MathMax(Up, pine_hist(TUp, __pineBar, (int)(1))) : Up);
   TDown[__pineBar] = ((pine_hist(close, __pineBar, (int)(1)) < pine_hist(TDown, __pineBar, (int)(1))) ? MathMin(Dn, pine_hist(TDown, __pineBar, (int)(1))) : Dn);
   Trend[__pineBar] = ((close[__pineBar] > pine_hist(TDown, __pineBar, (int)(1))) ? 1 : ((close[__pineBar] < pine_hist(TUp, __pineBar, (int)(1))) ? (-1) : pine_nz(pine_hist(Trend, __pineBar, (int)(1)), 1)));
   Trailingsl = ((Trend[__pineBar] == 1) ? TUp[__pineBar] : TDown[__pineBar]);
   linecolor = (((((Trend[__pineBar] == 1) ? 1 : 0) & ((pine_nz(pine_hist(Trend, __pineBar, (int)(1))) == 1) ? 1 : 0)) != 0) ? C'0,230,118' : (((((Trend[__pineBar] == (-1)) ? 1 : 0) & ((pine_nz(pine_hist(Trend, __pineBar, (int)(1))) == (-1)) ? 1 : 0)) != 0) ? C'242,54,69' : PINE_NA));
   bsignal = ((((Trend[__pineBar] == 1) ? 1 : 0) & ((pine_hist(Trend, __pineBar, (int)(1)) == (-1)) ? 1 : 0)) != 0);
   ssignal = ((((Trend[__pineBar] == (-1)) ? 1 : 0) & ((pine_hist(Trend, __pineBar, (int)(1)) == 1) ? 1 : 0)) != 0);
   resistance[__pineBar] = PINE_NA;
   support[__pineBar] = PINE_NA;
   support[__pineBar] = (pine_truthy(pl) ? pl : pine_hist(support, __pineBar, (int)(1)));
   resistance[__pineBar] = (pine_truthy(ph) ? ph : pine_hist(resistance, __pineBar, (int)(1)));
   pine_alertcond(((((Trend[__pineBar] == 1) ? 1 : 0) & ((pine_hist(Trend, __pineBar, (int)(1)) == (-1)) ? 1 : 0)) != 0), "Buy Signal", 1020767982, __pineBar, __pineLastBar);
   pine_alertcond(((((Trend[__pineBar] == (-1)) ? 1 : 0) & ((pine_hist(Trend, __pineBar, (int)(1)) == 1) ? 1 : 0)) != 0), "Sell Signal", 70838928, __pineBar, __pineLastBar);
   pine_alertcond(pine_change(Trend, __pineBar, (int)(1)), "Trend Changed", 460887511, __pineBar, __pineLastBar);
   Buf0[__pineBar] = (((pine_truthy(ph) ? 1 : 0) & (showpivot ? 1 : 0)) != 0) ? pine_hist(high, __pineBar, (int)(MathMax(0, (-(-prd))))) : EMPTY_VALUE;
   pine_shape_text("0", __pineBar + (int)((-prd)), Buf0[__pineBar], "H", clrDodgerBlue, true);
   Buf1[__pineBar] = (((pine_truthy(pl) ? 1 : 0) & (showpivot ? 1 : 0)) != 0) ? pine_hist(low, __pineBar, (int)(MathMax(0, (-(-prd))))) : EMPTY_VALUE;
   pine_shape_text("1", __pineBar + (int)((-prd)), Buf1[__pineBar], "L", clrDodgerBlue, false);
   double __pinePlotValue2 = Trailingsl;
   double __pinePlotColour2 = (double)(linecolor);
   Buf2[__pineBar] = __pinePlotValue2;
   Buf3[__pineBar] = pine_color_slot(2, pine_na(__pinePlotColour2) ? clrNONE : (color)__pinePlotColour2, __pal2, __paln2);
   double __pinePlotValue3 = (showcl ? center : PINE_NA);
   double __pinePlotColour3 = (double)((showcl ? ((center < ((high[__pineBar] + low[__pineBar]) / 2.0)) ? C'41,98,255' : C'242,54,69') : PINE_NA));
   Buf4[__pineBar] = __pinePlotValue3;
   Buf5[__pineBar] = pine_color_slot(3, pine_na(__pinePlotColour3) ? clrNONE : (color)__pinePlotColour3, __pal3, __paln3);
   Buf6[__pineBar] = pine_truthy(((((bsignal ? 1 : 0) & (showlabel ? 1 : 0)) != 0) ? Trailingsl : PINE_NA)) ? ((((bsignal ? 1 : 0) & (showlabel ? 1 : 0)) != 0) ? Trailingsl : PINE_NA) : EMPTY_VALUE;
   pine_shape_text("6", __pineBar, Buf6[__pineBar], "Buy", C'0,230,118', true);
   Buf7[__pineBar] = pine_truthy(((((ssignal ? 1 : 0) & (showlabel ? 1 : 0)) != 0) ? Trailingsl : PINE_NA)) ? ((((ssignal ? 1 : 0) & (showlabel ? 1 : 0)) != 0) ? Trailingsl : PINE_NA) : EMPTY_VALUE;
   pine_shape_text("7", __pineBar, Buf7[__pineBar], "Sell", C'242,54,69', true);
   double __pinePlotValue6 = ((((showsr ? 1 : 0) & (pine_truthy(support[__pineBar]) ? 1 : 0)) != 0) ? support[__pineBar] : PINE_NA);
   double __pinePlotColour6 = (double)(((((showsr ? 1 : 0) & (pine_truthy(support[__pineBar]) ? 1 : 0)) != 0) ? C'0,230,118' : PINE_NA));
   Buf8[__pineBar] = __pinePlotValue6;
   Buf9[__pineBar] = pine_color_slot(6, pine_na(__pinePlotColour6) ? clrNONE : (color)__pinePlotColour6, __pal6, __paln6);
   double __pinePlotValue7 = ((((showsr ? 1 : 0) & (pine_truthy(resistance[__pineBar]) ? 1 : 0)) != 0) ? resistance[__pineBar] : PINE_NA);
   double __pinePlotColour7 = (double)(((((showsr ? 1 : 0) & (pine_truthy(resistance[__pineBar]) ? 1 : 0)) != 0) ? C'242,54,69' : PINE_NA));
   Buf10[__pineBar] = __pinePlotValue7;
   Buf11[__pineBar] = pine_color_slot(7, pine_na(__pinePlotColour7) ? clrNONE : (color)__pinePlotColour7, __pal7, __paln7);
}

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(TUp, rates_total);
   ArrayResize(TDown, rates_total);
   ArrayResize(Trend, rates_total);
   ArrayResize(resistance, rates_total);
   ArrayResize(support, rates_total);
   ArrayResize(__st0, rates_total);
   ArrayResize(__stb0, rates_total);
   ArrayResize(__st1, rates_total);
   ArrayResize(__stb1, rates_total);
   if(prev_calculated == 0)
   {
      ArrayInitialize(TUp, PINE_NA);
      ArrayInitialize(TDown, PINE_NA);
      ArrayInitialize(Trend, PINE_NA);
      ArrayInitialize(resistance, PINE_NA);
      ArrayInitialize(support, PINE_NA);
      ArrayInitialize(__st0, PINE_NA);
      ArrayInitialize(__stb0, PINE_NA);
      ArrayInitialize(__st1, PINE_NA);
      ArrayInitialize(__stb1, 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;
}

void OnDeinit(const int reason)
{
   ObjectsDeleteAll(0, "pine_");
}

Original Pine Script

© LonesomeTheBlue — 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/

// © LonesomeTheBlue



//@version=4

study("Pivot Point SuperTrend", overlay = true)

prd = input(defval = 2, title="Pivot Point Period", minval = 1, maxval = 50)

Factor=input(defval = 3, title = "ATR Factor", minval = 1, step = 0.1)

Pd=input(defval = 10, title = "ATR Period", minval=1)

showpivot = input(defval = false, title="Show Pivot Points")

showlabel = input(defval = true, title="Show Buy/Sell Labels")

showcl = input(defval = false, title="Show PP Center Line")

showsr = input(defval = false, title="Show Support/Resistance")



// get Pivot High/Low

float ph = pivothigh(prd, prd)

float pl = pivotlow(prd, prd)



// drawl Pivot Points if "showpivot" is enabled

plotshape(ph and showpivot, text="H",  style=shape.labeldown, color=na, textcolor=color.red, location=location.abovebar, transp=0, offset = -prd)

plotshape(pl and showpivot, text="L",  style=shape.labeldown, color=na, textcolor=color.lime, location=location.belowbar, transp=0, offset = -prd)



// calculate the Center line using pivot points

var float center = na

float lastpp = ph ? ph : pl ? pl : na

if lastpp

    if na(center)

        center := lastpp

    else

        //weighted calculation

        center := (center * 2 + lastpp) / 3



// upper/lower bands calculation

Up = center - (Factor * atr(Pd))

Dn = center + (Factor * atr(Pd))



// get the trend

float TUp = na

float TDown = na

Trend = 0

TUp := close[1] > TUp[1] ? max(Up, TUp[1]) : Up

TDown := close[1] < TDown[1] ? min(Dn, TDown[1]) : Dn

Trend := close > TDown[1] ? 1: close < TUp[1]? -1: nz(Trend[1], 1)

Trailingsl = Trend == 1 ? TUp : TDown



// plot the trend

linecolor = Trend == 1 and nz(Trend[1]) == 1 ? color.lime : Trend == -1 and nz(Trend[1]) == -1 ? color.red : na

plot(Trailingsl, color = linecolor ,  linewidth = 2, title = "PP SuperTrend")

 

plot(showcl ? center : na, color = showcl ? center < hl2 ? color.blue : color.red : na)



// check and plot the signals

bsignal = Trend == 1 and Trend[1] == -1

ssignal = Trend == -1 and Trend[1] == 1

plotshape(bsignal and showlabel ? Trailingsl : na, title="Buy", text="Buy", location = location.absolute, style = shape.labelup, size = size.tiny, color = color.lime, textcolor = color.black, transp = 0)

plotshape(ssignal and showlabel ? Trailingsl : na, title="Sell", text="Sell", location = location.absolute, style = shape.labeldown, size = size.tiny, color = color.red, textcolor = color.white, transp = 0)



//get S/R levels using Pivot Points

float resistance = na

float support = na

support := pl ? pl : support[1]

resistance := ph ? ph : resistance[1]



// if enabled then show S/R levels

plot(showsr and support ? support : na, color = showsr and support ? color.lime : na, style = plot.style_circles, offset = -prd)

plot(showsr and resistance ? resistance : na, color = showsr and resistance ? color.red : na, style = plot.style_circles, offset = -prd)



// alerts

alertcondition(Trend == 1 and Trend[1] == -1, title='Buy Signal', message='Buy Signal')

alertcondition(Trend == -1 and Trend[1] == 1, title='Sell Signal', message='Sell Signal')

alertcondition(change(Trend), title='Trend Changed', message='Trend Changed')

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