abcsthinkscript
New member
Hello Fellows!
I am new to this forum and I don't know how to code so just wondering if any expert here can help convert this REX Oscillator indicator code into thinkscript?
I poked around and found this link of the MT4 code....
and this one on trading view.....
Many thanks in advance!
PS: I believe the default settings will have to be tweaked a bit. Hope you guys can find success with it as well!
I am new to this forum and I don't know how to code so just wondering if any expert here can help convert this REX Oscillator indicator code into thinkscript?
I poked around and found this link of the MT4 code....
Code:
//+------------------------------------------------------------------+
//| Rex.mq4 |
//| Copyright © 2014, Gehtsoft USA LLC |
//| http://fxcodebase.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2014, Gehtsoft USA LLC"
#property link "http://fxcodebase.com"
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Green
#property indicator_color2 Red
extern int Smoothing_Length=14;
extern int Smoothing_Method=0; // 0 - SMA
// 1 - EMA
// 2 - SMMA
// 3 - LWMA
extern int Signal_Length=14;
extern int Signal_Method=0; // 0 - SMA
// 1 - EMA
// 2 - SMMA
// 3 - LWMA
double Rex[], Signal[];
double TVB[];
int init()
{
IndicatorShortName("Rex oscillator");
IndicatorDigits(Digits);
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,Rex);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,Signal);
SetIndexStyle(2,DRAW_NONE);
SetIndexBuffer(2,TVB);
return(0);
}
int deinit()
{
return(0);
}
int start()
{
if(Bars<=3) return(0);
int ExtCountedBars=IndicatorCounted();
if (ExtCountedBars<0) return(-1);
int limit=Bars-2;
if(ExtCountedBars>2) limit=Bars-ExtCountedBars-1;
int pos;
pos=limit;
while(pos>=0)
{
TVB[pos]=3.*Close[pos]-(Low[pos]+Open[pos]+High[pos]);
pos--;
}
pos=limit;
while(pos>=0)
{
Rex[pos]=iMAOnArray(TVB, 0, Smoothing_Length, 0, Smoothing_Method, pos)/Point;
pos--;
}
pos=limit;
while(pos>=0)
{
Signal[pos]=iMAOnArray(Rex, 0, Signal_Length, 0, Signal_Method, pos);
pos--;
}
return(0);
}
and this one on trading view.....
//@version=4
study("REX", overlay=false)
// Best used as an exit indicator at default settings.
// Also doing well in entering positions by using TEMA(14) for REX and SMA(14) as signal.
// You need to tune it yourself according to your trading style.
// Use at your own risk.
//
// Vitelot/Yanez/Vts Oct 2019
//
// Oct 2019: added zero line and OS/OB lines (currently commented out)
//
rex_ma_type = input(type=input.string, defval="SMA", options=["EMA","SMA", "Tenkan","TEMA"], title="REX MA type")
smoothing = input(14, title="Smoothing length", minval=1)
sig_ma_type = input(type=input.string, defval="SMA", options=["EMA","SMA", "Tenkan","TEMA"], title="Signal MA type")
smoothing_sig = input(14, title="Signal smoothing length", minval=1)
tenkan(sig, len) =>
0.5 * (highest(sig, len) + lowest(sig, len))
// triple ema
tema(src, len) =>
v2 = ema(src, len)
v = 3 * (v2 - ema(v2, len)) + ema(ema(v2, len), len) // Triple Exponential
v
ma(t, sig, len) =>
sss = float(na)
if t == "SMA"
sss := sma(sig, len)
if t == "EMA"
sss := ema(sig, len)
if t == "TEMA"
sss := tema(sig, len)
if t == "Tenkan"
sss := tenkan(sig, len)
sss
tvb = 3*close-open-high-low
rex = ma(rex_ma_type, tvb, smoothing)
sig = ma(sig_ma_type, rex, smoothing_sig)
plot(rex, color=#3342c1ff, linewidth=2)
plot(sig, color=#d2a344ff)
hline(0, title="Zero line", color=#ffffff80)
//stddev_period = 200
//bup = 2*stdev(rex,stddev_period)+sma(rex,stddev_period)
//bdn = -2*stdev(rex,stddev_period)+sma(rex,stddev_period)
//plot(bup, color=#ffff0080, style=plot.style_circles, title="Band up")
//plot(bdn, color=#ffff0080, style=plot.style_circles, title="Band down")
Many thanks in advance!
PS: I believe the default settings will have to be tweaked a bit. Hope you guys can find success with it as well!
Last edited: