Hello,
I am new to quantconnect, I would like to know if its possible to run a custom rsi indicator on the 233 minute or 4hr time frame on the spy
the code for the custom rsi
declare lower;
# Inputs:
input p = close;
input gamma = .236;
# Variables:
def L0;
def L1;
def L2;
def L3;
def CU;
def CD;
plot RSI;
plot OB;
plot OS;
plot ArrowUp;
plot ArrowDn;
# Script
script Laguerre{
input a = close;
input gamma = .5;
def L0 = ((1 - gamma) * a) + (gamma * L0[1]);
def L1 = (-gamma * L0) + L0[1] + (gamma * L1[1]);
def L2 = (-gamma * L1) + L1[1] + (gamma * L2[1]);
def L3 = (-gamma * L2) + L2[1] + (gamma * L3[1]);
plot Laguerre = (L0 + (2 * L1) + L2) / 4;
}
L0 = (1 – gamma) * p + gamma * L0[1];
L1 = - gamma * L0 + L0[1] + gamma * L1[1];
L2 = - gamma * L1 + L1[1] + gamma * L2[1];
L3 = - gamma * L2 + L2[1] + gamma * L3[1];
CU =
If L0 >= L1 then L0 - L1
Else If L1 >= L2 then CU[1] + L1 - L2
Else If L2 >= L3 then CU[1] + L2 - L3
Else 0;
CD =
If L0 <= L1 then L1 - L0
Else If L1 <= L2 then CD[1] + L2 - L1
Else If L2 <= L3 then CD[1] + L3 - L2
Else 0;
RSI =
Laguerre(a = if CU + CD <> 0 then CU / (CU + CD) else 0, gamma = 0);
OB =
if isNaN(RSI) then Double.NaN else .8;
OS =
if isNaN(RSI) then Double.NaN else .2;
RSI.SetDefaultColor(Color.Cyan);
OB.SetDefaultColor(Color.Yellow);
OS.SetDefaultColor(Color.Yellow);
AddCloud(OB,1,Color.Light_Red);
AddCloud(OS,0,Color.Light_Green);
ArrowUp = if RSI crosses above OS then OS else Double.Nan;
ArrowUp.SetPaintingStrategy(PaintingStrategy.Arrow_UP);
ArrowUP.SetLineWeight(3);
ArrowUp.SetDefaultColor(Color.Green);
ArrowDn = if RSI crosses below OB then OB else Double.NaN;
ArrowDn.SetPaintingStrategy(PaintingStrategy.Arrow_Down);
ArrowDn.SetLineWeight(3);
ArrowDn.SetDefaultColor(Color.Red);
Alert(!isNaN(ArrowUp), "", Alert.Bar, Sound.Ring);
Alert(!isNaN(ArrowDn), "", Alert.Bar, Sound.Ring);
Thanks
Best Regards
Roger
Michael Handschuh
var close = Identity("SPY", TimeSpan.FromMinutes(barSizeInMinutes)); var rsi = new RelativeStrengthIndex(14).Of(close);
If you require the full trade bar you can use consolidators:var consolidator = new TradeBarConsolidator(TimeSpan.FromMinutes(barSizeInMinutes)); SubscriptionManager.AddConsolidator("SPY", consolidator); consolidator.DataConsolidated += OnCustomBarSize; // later in file public void OnCustomBarSize(TradeBar customBarSizeTradeBar) { // do special logic on time frame }
Roger M. Benites
Michael Handschuh
Roger M. Benites
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!