Surrey - UK
Posts: 41 since Sep 2015
Thanks Given: 12
Thanks Received: 8
|
Hi There,
I have based a strategy off RSI in the think or swim platform, moving over to automation with mc.net but im not sure if these 2 RSI's formulas are the same.
Feedback be great thanks,
RSI CALCULATION
THINK OR SWIM - (CORRECT ONE WHICH STRATEGY IS BASED OFF)
declare lower;
input length = 14;
input over_Bought = 70;
input over_Sold = 30;
input price = close;
input averageType = AverageType.WILDERS;
def NetChgAvg = MovingAverage(averageType, price - price[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
plot RSI = 50 * (ChgRatio + 1);
plot OverSold = over_Sold;
plot OverBought = over_Bought;
RSI.DefineColor("OverBought", GetColor(5));
RSI.DefineColor("Normal", GetColor(7));
RSI.DefineColor("OverSold", GetColor(1));
RSI.AssignValueColor(if RSI > over_Bought then RSI.color("OverBought") else if RSI < over_Sold then RSI.color("OverSold") else RSI.color("Normal"));
OverSold.SetDefaultColor(GetColor(8));
OverBought.SetDefaultColor(GetColor(8));
MC.NET RSI CODE
using System;
using System.Drawing;
namespace PowerLanguage.Indicator
{
public class RSI : IndicatorObject
{
private Function.RSI m_rsi1;
private VariableSeries<Double> m_myrsi;
private IPlotObject Plot1;
private IPlotObject Plot2;
private IPlotObject Plot3;
public RSI(object ctx) :
base(ctx){
overbcolor = Color.Red;
overscolor = Color.Cyan;
overbought = 70;
oversold = 30;
length = 14;
}
[Input]
public int length { get; set; }
[Input]
public double oversold { get; set; }
[Input]
public double overbought { get; set; }
[Input]
public Color overscolor { get; set; }
[Input]
public Color overbcolor { get; set; }
protected override void Create(){
m_rsi1 = new Function.RSI(this);
m_myrsi = new VariableSeries<Double>(this);
Plot1 =
AddPlot(new PlotAttributes("RSI", 0, Color.Silver,
Color.Empty, 0, 0, true));
Plot2 =
AddPlot(new PlotAttributes("OverBot", 0, Color.Green,
Color.Empty, 0, 0, true));
Plot3 =
AddPlot(new PlotAttributes("OverSld", 0, Color.Green,
Color.Empty, 0, 0, true));
}
protected override void StartCalc(){
m_rsi1.price = Bars.Close;
m_rsi1.length = length;
}
protected override void CalcBar(){
m_myrsi.Value = m_rsi1[0];
Plot1.Set(0, m_myrsi.Value);
Plot2.Set(0, overbought);
Plot3.Set(0, oversold);
if (PublicFunctions.DoubleGreater(m_myrsi.Value, overbought)){
Plot1.Colors[0] = overbcolor;
}
else{
if (PublicFunctions.DoubleLess(m_myrsi.Value, oversold)){
Plot1.Colors[0] = overscolor;
}
}
if (this.CrossesOver(m_myrsi, oversold)){
Alerts.Alert("Indicator exiting oversold zone");
}
else{
if (this.CrossesUnder(m_myrsi, overbought)){
Alerts.Alert("Indicator exiting overbought zone");
}
}
}
}
}
|