Parabolic RSI [ChartPrime] in MQL5 — converted from Pine Script
The Parabolic RSI [ChartPrime] indicator by ChartPrime, 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).
Inputs
| Input | Default |
|---|---|
| RSI Length | 14 |
| Threshold: ⭱ | 70 |
| ⤓ | 30 |
| SAR | true |
| Start | 0.02 |
| Increment | 0.02 |
| Maximum | 0.2 |
| color_up | #EEA47F |
| color_dn | #00539C |
Converted MQL5
Save as parabolic-rsi-chartprime.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: ca5785ff28a1 status: CLEAN
//| notes: 0 unsupported, 0 warn, 11 info
//| Review, compile and backtest before trading.
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Parabolic RSI [ChartPrime]
//| 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_separate_window
#property indicator_buffers 17
#property indicator_plots 15
#property indicator_label1 "RSI Background Fill"
#property indicator_type1 DRAW_FILLING
#property indicator_color1 clrDodgerBlue
#property indicator_width1 1
#property indicator_label2 "RSI"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrDodgerBlue
#property indicator_width2 1
#property indicator_label3 "RSI Upper Band"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrDodgerBlue
#property indicator_width3 1
#property indicator_label4 "RSI Middle Band"
#property indicator_type4 DRAW_LINE
#property indicator_color4 clrDodgerBlue
#property indicator_width4 1
#property indicator_label5 "RSI Lower Band"
#property indicator_type5 DRAW_LINE
#property indicator_color5 clrDodgerBlue
#property indicator_width5 1
#property indicator_label6 "Plot6"
#property indicator_type6 DRAW_NONE
#property indicator_color6 clrDodgerBlue
#property indicator_width6 1
#property indicator_label7 "SAR"
#property indicator_type7 DRAW_COLOR_ARROW
#property indicator_color7 clrDodgerBlue
#property indicator_width7 1
#property indicator_label8 "Rsi Up"
#property indicator_type8 DRAW_ARROW
#property indicator_color8 clrDodgerBlue
#property indicator_width8 1
#property indicator_label9 "Rsi Dn"
#property indicator_type9 DRAW_ARROW
#property indicator_color9 clrDodgerBlue
#property indicator_width9 1
#property indicator_label10 "Rsi Up"
#property indicator_type10 DRAW_ARROW
#property indicator_color10 clrDodgerBlue
#property indicator_width10 1
#property indicator_label11 "Rsi Dn"
#property indicator_type11 DRAW_ARROW
#property indicator_color11 clrDodgerBlue
#property indicator_width11 1
#property indicator_label12 "Chart Strong Rsi Up"
#property indicator_type12 DRAW_ARROW
#property indicator_color12 clrDodgerBlue
#property indicator_width12 1
#property indicator_label13 "Chart Strong Rsi Dn"
#property indicator_type13 DRAW_ARROW
#property indicator_color13 clrDodgerBlue
#property indicator_width13 1
#property indicator_label14 "Chart Rsi Up"
#property indicator_type14 DRAW_ARROW
#property indicator_color14 clrDodgerBlue
#property indicator_width14 1
#property indicator_label15 "Chart Rsi Dn"
#property indicator_type15 DRAW_ARROW
#property indicator_color15 clrDodgerBlue
#property indicator_width15 1
#include "PineRuntime.mqh"
//--- plot buffers
double PineFill0[];
double PineFill1[];
double Buf2[];
double Buf3[];
double Buf4[];
double Buf5[];
double Buf6[];
double Buf7[];
double Buf8[];
double Buf9[];
double Buf10[];
double Buf11[];
double Buf12[];
double Buf13[];
double Buf14[];
double Buf15[];
double Buf16[];
color __pal6[64]; // the colours plot 6 has drawn so far; see pine_color_slot
int __paln6 = 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 rsi = PINE_NA;
double sar_rsi = PINE_NA;
double isBelow[];
bool sig_up = false;
bool sig_dn = false;
bool s_sig_up = false;
bool s_sig_dn = false;
double sar = PINE_NA;
color sar_col = clrNONE;
//--- live-tick rollback: the state each bar started from
double __sv_rsi;
double __si_rsi;
double __sv_sar_rsi;
double __si_sar_rsi;
bool __sv_sig_up;
bool __si_sig_up;
bool __sv_sig_dn;
bool __si_sig_dn;
bool __sv_s_sig_up;
bool __si_s_sig_up;
bool __sv_s_sig_dn;
bool __si_s_sig_dn;
double __sv_sar;
double __si_sar;
color __sv_sar_col;
color __si_sar_col;
int __pineSnapBar = -1;
void __pineSaveState()
{
__sv_rsi = rsi;
__sv_sar_rsi = sar_rsi;
__sv_sig_up = sig_up;
__sv_sig_dn = sig_dn;
__sv_s_sig_up = s_sig_up;
__sv_s_sig_dn = s_sig_dn;
__sv_sar = sar;
__sv_sar_col = sar_col;
pine_draw_mark();
__pineSaveGen++; // helpers' static arrays snapshot lazily
}
void __pineRestoreState()
{
rsi = __sv_rsi;
sar_rsi = __sv_sar_rsi;
sig_up = __sv_sig_up;
sig_dn = __sv_sig_dn;
s_sig_up = __sv_s_sig_up;
s_sig_dn = __sv_s_sig_dn;
sar = __sv_sar;
sar_col = __sv_sar_col;
pine_draw_rollback();
__pineRestoreGen++;
__pineRestoreSaveGen = __pineSaveGen;
}
void __pineSaveInitial()
{
__si_rsi = rsi;
__si_sar_rsi = sar_rsi;
__si_sig_up = sig_up;
__si_sig_dn = sig_dn;
__si_s_sig_up = s_sig_up;
__si_s_sig_dn = s_sig_dn;
__si_sar = sar;
__si_sar_col = sar_col;
pine_draw_save_initial();
}
void __pineRestoreInitial()
{
rsi = __si_rsi;
sar_rsi = __si_sar_rsi;
sig_up = __si_sig_up;
sig_dn = __si_sig_dn;
s_sig_up = __si_s_sig_up;
s_sig_dn = __si_s_sig_dn;
sar = __si_sar;
sar_col = __si_sar_col;
pine_draw_reset();
__pineInitGen++;
}
double __st0[]; // accumulator for one stateful call site
double __stb0[]; // secondary buffer (e.g. true range for ATR)
double __fl_pine_sar_src_high[]; // history of `src_high`, a local of pine_sar() the script reads with [n]
double __fl_pine_sar_src_low[]; // history of `src_low`, a local of pine_sar() the script reads with [n]
double __fl_pine_sar_result[]; // history of `result`, a local of pine_sar() the script reads with [n]
double __fl_pine_sar_maxMin[]; // history of `maxMin`, a local of pine_sar() the script reads with [n]
double __fl_pine_sar_acceleration[]; // history of `acceleration`, a local of pine_sar() the script reads with [n]
double __fl_pine_sar_isBelow_l[]; // history of `isBelow_l`, a local of pine_sar() the script reads with [n]
double __fi0[]; // persistent local has been initialized
double __fi1[]; // persistent local has been initialized
double __fi2[]; // persistent local has been initialized
double __fi3[]; // persistent local has been initialized
double __ti0[]; // materialised ta.* source: rsi
//--- inputs
input int len = 14; // RSI Length
input int upper_ = 70; // Threshold: ⭱
input int lower_ = 30; // ⤓
input bool display_sar = true; // SAR
input double start = 0.02; // Start
input double inc = 0.02; // Increment
input double max = 0.2; // Maximum
input color color_up = C'238,164,127';
input color color_dn = C'0,83,156';
//--- user functions
void pine_sar(const double &src[], const double start, const double inc, const double max, const int __pineBar, double &__out0, bool &__out1)
{
__fl_pine_sar_src_high[__pineBar] = (src[__pineBar] + 1);
__fl_pine_sar_src_low[__pineBar] = (src[__pineBar] - 1);
if(pine_na(__fi0[__pineBar]))
{
__fl_pine_sar_result[__pineBar] = PINE_NA;
__fi0[__pineBar] = 1;
}
if(pine_na(__fi1[__pineBar]))
{
__fl_pine_sar_maxMin[__pineBar] = PINE_NA;
__fi1[__pineBar] = 1;
}
if(pine_na(__fi2[__pineBar]))
{
__fl_pine_sar_acceleration[__pineBar] = PINE_NA;
__fi2[__pineBar] = 1;
}
if(pine_na(__fi3[__pineBar]))
{
__fl_pine_sar_isBelow_l[__pineBar] = false;
__fi3[__pineBar] = 1;
}
bool isFirstTrendBar = false;
if((__pineBar <= (len + 2)))
{
if((src[__pineBar] > pine_hist(src, __pineBar, (int)(1))))
{
__fl_pine_sar_isBelow_l[__pineBar] = true;
__fl_pine_sar_maxMin[__pineBar] = __fl_pine_sar_src_high[__pineBar];
__fl_pine_sar_result[__pineBar] = pine_hist(__fl_pine_sar_src_low, __pineBar, (int)(1));
}
else
{
__fl_pine_sar_isBelow_l[__pineBar] = false;
__fl_pine_sar_maxMin[__pineBar] = __fl_pine_sar_src_low[__pineBar];
__fl_pine_sar_result[__pineBar] = pine_hist(__fl_pine_sar_src_high, __pineBar, (int)(1));
}
isFirstTrendBar = true;
__fl_pine_sar_acceleration[__pineBar] = start;
}
__fl_pine_sar_result[__pineBar] = (__fl_pine_sar_result[__pineBar] + (__fl_pine_sar_acceleration[__pineBar] * (__fl_pine_sar_maxMin[__pineBar] - __fl_pine_sar_result[__pineBar])));
if(__fl_pine_sar_isBelow_l[__pineBar])
{
if((__fl_pine_sar_result[__pineBar] > __fl_pine_sar_src_low[__pineBar]))
{
isFirstTrendBar = true;
__fl_pine_sar_isBelow_l[__pineBar] = false;
__fl_pine_sar_result[__pineBar] = MathMax(__fl_pine_sar_src_high[__pineBar], __fl_pine_sar_maxMin[__pineBar]);
__fl_pine_sar_maxMin[__pineBar] = __fl_pine_sar_src_low[__pineBar];
__fl_pine_sar_acceleration[__pineBar] = start;
}
}
else
{
if((__fl_pine_sar_result[__pineBar] < __fl_pine_sar_src_high[__pineBar]))
{
isFirstTrendBar = true;
__fl_pine_sar_isBelow_l[__pineBar] = true;
__fl_pine_sar_result[__pineBar] = MathMin(__fl_pine_sar_src_low[__pineBar], __fl_pine_sar_maxMin[__pineBar]);
__fl_pine_sar_maxMin[__pineBar] = __fl_pine_sar_src_high[__pineBar];
__fl_pine_sar_acceleration[__pineBar] = start;
}
}
if((!isFirstTrendBar))
{
if(__fl_pine_sar_isBelow_l[__pineBar])
{
if((__fl_pine_sar_src_high[__pineBar] > __fl_pine_sar_maxMin[__pineBar]))
{
__fl_pine_sar_maxMin[__pineBar] = __fl_pine_sar_src_high[__pineBar];
__fl_pine_sar_acceleration[__pineBar] = MathMin((__fl_pine_sar_acceleration[__pineBar] + inc), max);
}
}
else
{
if((__fl_pine_sar_src_low[__pineBar] < __fl_pine_sar_maxMin[__pineBar]))
{
__fl_pine_sar_maxMin[__pineBar] = __fl_pine_sar_src_low[__pineBar];
__fl_pine_sar_acceleration[__pineBar] = MathMin((__fl_pine_sar_acceleration[__pineBar] + inc), max);
}
}
}
if(__fl_pine_sar_isBelow_l[__pineBar])
{
__fl_pine_sar_result[__pineBar] = MathMin(__fl_pine_sar_result[__pineBar], pine_hist(__fl_pine_sar_src_low, __pineBar, (int)(1)));
if((__pineBar > 1))
{
__fl_pine_sar_result[__pineBar] = MathMin(__fl_pine_sar_result[__pineBar], pine_hist(__fl_pine_sar_src_low, __pineBar, (int)(2)));
}
}
else
{
__fl_pine_sar_result[__pineBar] = MathMax(__fl_pine_sar_result[__pineBar], pine_hist(__fl_pine_sar_src_high, __pineBar, (int)(1)));
if((__pineBar > 1))
{
__fl_pine_sar_result[__pineBar] = MathMax(__fl_pine_sar_result[__pineBar], pine_hist(__fl_pine_sar_src_high, __pineBar, (int)(2)));
}
}
__out0 = __fl_pine_sar_result[__pineBar];
__out1 = __fl_pine_sar_isBelow_l[__pineBar];
return;
}
int OnInit()
{
SetIndexBuffer(0, PineFill0, INDICATOR_DATA);
SetIndexBuffer(1, PineFill1, INDICATOR_DATA);
SetIndexBuffer(2, Buf2, INDICATOR_DATA);
SetIndexBuffer(3, Buf3, INDICATOR_DATA);
SetIndexBuffer(4, Buf4, INDICATOR_DATA);
SetIndexBuffer(5, Buf5, INDICATOR_DATA);
SetIndexBuffer(6, Buf6, INDICATOR_DATA);
SetIndexBuffer(7, Buf7, INDICATOR_DATA);
SetIndexBuffer(8, Buf8, INDICATOR_COLOR_INDEX);
SetIndexBuffer(9, Buf9, INDICATOR_DATA);
SetIndexBuffer(10, Buf10, INDICATOR_DATA);
SetIndexBuffer(11, Buf11, INDICATOR_DATA);
SetIndexBuffer(12, Buf12, INDICATOR_DATA);
SetIndexBuffer(13, Buf13, INDICATOR_DATA);
SetIndexBuffer(14, Buf14, INDICATOR_DATA);
SetIndexBuffer(15, Buf15, INDICATOR_DATA);
SetIndexBuffer(16, Buf16, INDICATOR_DATA);
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(0, PLOT_LINE_COLOR, 0, C'194,146,87');
PlotIndexSetInteger(0, PLOT_LINE_COLOR, 1, C'194,146,87');
PlotIndexSetInteger(2, PLOT_LINE_COLOR, C'120,123,134');
PlotIndexSetInteger(3, PLOT_LINE_COLOR, pine_color_new((color)(C'120,123,134'), 50));
PlotIndexSetInteger(4, PLOT_LINE_COLOR, C'120,123,134');
PlotIndexSetInteger(6, PLOT_DRAW_TYPE, DRAW_COLOR_ARROW);
PlotIndexSetInteger(6, PLOT_ARROW, 159);
PlotIndexSetInteger(7, PLOT_DRAW_TYPE, DRAW_ARROW);
PlotIndexSetInteger(7, PLOT_ARROW, 110);
PlotIndexSetInteger(8, PLOT_DRAW_TYPE, DRAW_ARROW);
PlotIndexSetInteger(8, PLOT_ARROW, 110);
PlotIndexSetInteger(9, PLOT_DRAW_TYPE, DRAW_ARROW);
PlotIndexSetInteger(9, PLOT_ARROW, 159);
PlotIndexSetInteger(10, PLOT_DRAW_TYPE, DRAW_ARROW);
PlotIndexSetInteger(10, PLOT_ARROW, 159);
PlotIndexSetInteger(11, PLOT_DRAW_TYPE, DRAW_ARROW);
PlotIndexSetInteger(11, PLOT_ARROW, 110);
PlotIndexSetInteger(12, PLOT_DRAW_TYPE, DRAW_ARROW);
PlotIndexSetInteger(12, PLOT_ARROW, 110);
PlotIndexSetInteger(13, PLOT_DRAW_TYPE, DRAW_ARROW);
PlotIndexSetInteger(13, PLOT_ARROW, 110);
PlotIndexSetInteger(14, PLOT_DRAW_TYPE, DRAW_ARROW);
PlotIndexSetInteger(14, PLOT_ARROW, 110);
PlotIndexSetInteger(5, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(5, PLOT_DRAW_TYPE, DRAW_NONE);
IndicatorSetString(INDICATOR_SHORTNAME, "Parabolic RSI [ChartPrime]");
__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[])
{
__fl_pine_sar_result[__pineBar] = __pineBar > 0 ? __fl_pine_sar_result[__pineBar - 1] : PINE_NA;
__fi0[__pineBar] = __pineBar > 0 ? __fi0[__pineBar - 1] : PINE_NA;
__fl_pine_sar_maxMin[__pineBar] = __pineBar > 0 ? __fl_pine_sar_maxMin[__pineBar - 1] : PINE_NA;
__fi1[__pineBar] = __pineBar > 0 ? __fi1[__pineBar - 1] : PINE_NA;
__fl_pine_sar_acceleration[__pineBar] = __pineBar > 0 ? __fl_pine_sar_acceleration[__pineBar - 1] : PINE_NA;
__fi2[__pineBar] = __pineBar > 0 ? __fi2[__pineBar - 1] : PINE_NA;
__fl_pine_sar_isBelow_l[__pineBar] = __pineBar > 0 ? __fl_pine_sar_isBelow_l[__pineBar - 1] : PINE_NA;
__fi3[__pineBar] = __pineBar > 0 ? __fi3[__pineBar - 1] : PINE_NA;
if(__pineBar > 0)
{
isBelow[__pineBar] = isBelow[__pineBar - 1];
}
rsi = pine_rsi(close, __st0, __stb0, __pineBar, (int)(len));
double __tc0_0 = PINE_NA;
bool __tc0_1 = false;
__ti0[__pineBar] = rsi;
pine_sar(__ti0, start, inc, max, __pineBar, __tc0_0, __tc0_1);
sar_rsi = __tc0_0;
isBelow[__pineBar] = __tc0_1;
sig_up = (((isBelow[__pineBar] != pine_hist(isBelow, __pineBar, (int)(1))) && isBelow[__pineBar]) && (__pineBar < __pineLastBar));
sig_dn = (((isBelow[__pineBar] != pine_hist(isBelow, __pineBar, (int)(1))) && (!isBelow[__pineBar])) && (__pineBar < __pineLastBar));
s_sig_up = ((((isBelow[__pineBar] != pine_hist(isBelow, __pineBar, (int)(1))) && isBelow[__pineBar]) && (__pineBar < __pineLastBar)) && (sar_rsi <= lower_));
s_sig_dn = ((((isBelow[__pineBar] != pine_hist(isBelow, __pineBar, (int)(1))) && (!isBelow[__pineBar])) && (__pineBar < __pineLastBar)) && (sar_rsi >= upper_));
if(display_sar)
{
sar = ((isBelow[__pineBar] != pine_hist(isBelow, __pineBar, (int)(1))) ? PINE_NA : sar_rsi);
}
sar_col = (isBelow[__pineBar] ? color_up : color_dn);
0 /* fill dropped: visual only */;
0 /* fill dropped: visual only */;
Buf2[__pineBar] = rsi;
Buf3[__pineBar] = upper_;
Buf4[__pineBar] = 50;
Buf5[__pineBar] = lower_;
Buf6[__pineBar] = 50;
double __pinePlotValue6 = sar;
double __pinePlotColour6 = (double)(sar_col);
Buf7[__pineBar] = __pinePlotValue6;
Buf8[__pineBar] = pine_color_slot(6, pine_na(__pinePlotColour6) ? clrNONE : (color)__pinePlotColour6, __pal6, __paln6);
Buf9[__pineBar] = pine_truthy(((sig_up && (sar_rsi >= lower_)) ? sar_rsi : PINE_NA)) ? ((sig_up && (sar_rsi >= lower_)) ? sar_rsi : PINE_NA) : EMPTY_VALUE;
Buf10[__pineBar] = pine_truthy(((sig_dn && (sar_rsi <= upper_)) ? sar_rsi : PINE_NA)) ? ((sig_dn && (sar_rsi <= upper_)) ? sar_rsi : PINE_NA) : EMPTY_VALUE;
Buf11[__pineBar] = pine_truthy((s_sig_up ? sar_rsi : PINE_NA)) ? (s_sig_up ? sar_rsi : PINE_NA) : EMPTY_VALUE;
Buf12[__pineBar] = pine_truthy((s_sig_dn ? sar_rsi : PINE_NA)) ? (s_sig_dn ? sar_rsi : PINE_NA) : EMPTY_VALUE;
Buf13[__pineBar] = s_sig_up ? low[__pineBar] : EMPTY_VALUE;
Buf14[__pineBar] = s_sig_dn ? high[__pineBar] : EMPTY_VALUE;
Buf15[__pineBar] = (sig_up && (sar_rsi >= lower_)) ? low[__pineBar] : EMPTY_VALUE;
Buf16[__pineBar] = (sig_dn && (sar_rsi <= upper_)) ? high[__pineBar] : EMPTY_VALUE;
PineFill0[__pineBar] = Buf3[__pineBar];
PineFill1[__pineBar] = Buf5[__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(isBelow, rates_total);
ArrayResize(__st0, rates_total);
ArrayResize(__stb0, rates_total);
ArrayResize(__fl_pine_sar_src_high, rates_total);
ArrayResize(__fl_pine_sar_src_low, rates_total);
ArrayResize(__fl_pine_sar_result, rates_total);
ArrayResize(__fl_pine_sar_maxMin, rates_total);
ArrayResize(__fl_pine_sar_acceleration, rates_total);
ArrayResize(__fl_pine_sar_isBelow_l, rates_total);
ArrayResize(__fi0, rates_total);
ArrayResize(__fi1, rates_total);
ArrayResize(__fi2, rates_total);
ArrayResize(__fi3, rates_total);
ArrayResize(__ti0, rates_total);
if(prev_calculated == 0)
{
ArrayInitialize(isBelow, PINE_NA);
ArrayInitialize(__st0, PINE_NA);
ArrayInitialize(__stb0, PINE_NA);
ArrayInitialize(__fl_pine_sar_src_high, PINE_NA);
ArrayInitialize(__fl_pine_sar_src_low, PINE_NA);
ArrayInitialize(__fl_pine_sar_result, PINE_NA);
ArrayInitialize(__fl_pine_sar_maxMin, PINE_NA);
ArrayInitialize(__fl_pine_sar_acceleration, PINE_NA);
ArrayInitialize(__fl_pine_sar_isBelow_l, PINE_NA);
ArrayInitialize(__fi0, PINE_NA);
ArrayInitialize(__fi1, PINE_NA);
ArrayInitialize(__fi2, PINE_NA);
ArrayInitialize(__fi3, PINE_NA);
ArrayInitialize(__ti0, 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
© ChartPrime — Mozilla Public License 2.0. Reproduced for attribution and comparison; the converted code above is a derivative work offered under the same licence.
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ChartPrime
//@version=6
indicator("Parabolic RSI [ChartPrime]", overlay = false)
// --------------------------------------------------------------------------------------------------------------------}
// 𝙐𝙎𝙀𝙍 𝙄𝙉𝙋𝙐𝙏𝙎
// --------------------------------------------------------------------------------------------------------------------{
len = input.int(14, "RSI Length", group = "RSI")
upper_ = input.int(70, "Threshold: ⭱", inline = "Threshold")
lower_ = input.int(30, " ⤓", inline = "Threshold")
display_sar = input.bool(true, "SAR", group = "SAR")
start = input.float(0.02, "Start", step = 0.01, inline = "sar", group = "SAR")
inc = input.float(0.02, "Increment", step = 0.01, inline = "sar", group = "SAR")
max = input.float(0.2, "Maximum", step = 0.01, inline = "sar", group = "SAR")
color_up = input.color(#EEA47F, "", inline = "c")
color_dn = input.color(#00539C, "", inline = "c")
// --------------------------------------------------------------------------------------------------------------------}
// 𝙄𝙉𝘿𝙄𝘾𝘼𝙏𝙊𝙍 𝘾𝘼𝙇𝘾𝙐𝙇𝘼𝙏𝙄𝙊𝙉𝙎
// --------------------------------------------------------------------------------------------------------------------{
rsi = ta.rsi(close, len)
pine_sar(src, start, inc, max) =>
src_high = src+1
src_low = src-1
var float result = na
var float maxMin = na
var float acceleration = na
var bool isBelow = false
bool isFirstTrendBar = false
if bar_index <= len+2
if src > src[1]
isBelow := true
maxMin := src_high
result := src_low[1]
else
isBelow := false
maxMin := src_low
result := src_high[1]
isFirstTrendBar := true
acceleration := start
result := result + acceleration * (maxMin - result)
if isBelow
if result > src_low
isFirstTrendBar := true
isBelow := false
result := math.max(src_high, maxMin)
maxMin := src_low
acceleration := start
else
if result < src_high
isFirstTrendBar := true
isBelow := true
result := math.min(src_low, maxMin)
maxMin := src_high
acceleration := start
if not isFirstTrendBar
if isBelow
if src_high > maxMin
maxMin := src_high
acceleration := math.min(acceleration + inc, max)
else
if src_low < maxMin
maxMin := src_low
acceleration := math.min(acceleration + inc, max)
if isBelow
result := math.min(result, src_low[1])
if bar_index > 1
result := math.min(result, src_low[2])
else
result := math.max(result, src_high[1])
if bar_index > 1
result := math.max(result, src_high[2])
[result, isBelow]
[sar_rsi, isBelow] = pine_sar(rsi, start, inc, max)
sig_up = isBelow != isBelow[1] and isBelow and barstate.isconfirmed
sig_dn = isBelow != isBelow[1] and not isBelow and barstate.isconfirmed
s_sig_up = isBelow != isBelow[1] and isBelow and barstate.isconfirmed and sar_rsi <= lower_
s_sig_dn = isBelow != isBelow[1] and not isBelow and barstate.isconfirmed and sar_rsi >= upper_
var sar = float(na)
if display_sar
sar := isBelow != isBelow[1] ? na : sar_rsi
sar_col = isBelow ? color_up : color_dn
// --------------------------------------------------------------------------------------------------------------------}
// 𝙑𝙄𝙎𝙐𝘼𝙇𝙄𝙕𝘼𝙏𝙄𝙊𝙉
// --------------------------------------------------------------------------------------------------------------------{
rsiPlot = plot(rsi, "RSI", color=chart.fg_color)
rsiUpperBand = hline(upper_, "RSI Upper Band", color=#787B86)
midline = hline(50, "RSI Middle Band", color=color.new(#787B86, 50))
rsiLowerBand = hline(lower_, "RSI Lower Band", color=#787B86)
fill(rsiUpperBand, rsiLowerBand, color=#c292571a, title="RSI Background Fill")
midLinePlot = plot(50, color = na, editable = false, display = display.none)
fill(rsiPlot, midLinePlot, 100, 70, top_color = color.new(color.red, 0), bottom_color = color.new(color.orange, 100), title = "Overbought Gradient Fill")
fill(rsiPlot, midLinePlot, 30, 0, top_color = color.new(color.red, 100), bottom_color = color.new(color.orange, 0), title = "Oversold Gradient Fill")
sar_p = plot(sar, "SAR", color = sar_col, style = plot.style_circles)
plotshape(sig_up and sar_rsi >= lower_ ? sar_rsi : na, "Rsi Up", shape.diamond, location.absolute, size = size.tiny, color = sar_col)
plotshape(sig_dn and sar_rsi <= upper_ ? sar_rsi : na, "Rsi Dn", shape.diamond, location.absolute, size = size.tiny, color = sar_col)
plotchar(s_sig_up ? sar_rsi : na, "Rsi Up", "◈", location.absolute, size = size.tiny, color = sar_col)
plotchar(s_sig_dn ? sar_rsi : na, "Rsi Dn", "◈", location.absolute, size = size.tiny, color = sar_col)
plotshape(s_sig_up, "Chart Strong Rsi Up", shape.diamond, location.belowbar, size = size.small, color = sar_col, force_overlay = true)
plotshape(s_sig_dn, "Chart Strong Rsi Dn", shape.diamond, location.abovebar, size = size.small, color = sar_col, force_overlay = true)
plotshape(sig_up and sar_rsi >= lower_, "Chart Rsi Up", shape.diamond, location.belowbar, size = size.tiny, color = sar_col, force_overlay = true)
plotshape(sig_dn and sar_rsi <= upper_, "Chart Rsi Dn", shape.diamond, location.abovebar, size = size.tiny, color = sar_col, force_overlay = true)
// --------------------------------------------------------------------------------------------------------------------}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 converterMore: all example conversions · how Pine Script maps to MQL5 · how the engine measures