RSI with Auto Levels for ThinkorSwim

a3ctrader

New member
I often use DataProfile to automatically set levels for my indicators as different futures/stocks will exhibit different price behavior. The more chart history displayed, the more stable these auto levels will be. The use of DataProfile can be applied to many other more complex indicators.

Code:
declare lower;

def NetChgAvg = MovingAverage(AverageType.WILDERS, Close - Close[1], 14);
def TotChgAvg = MovingAverage(AverageType.WILDERS, AbsValue(Close - Close[1]), 14);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

plot RSI = Round(50 * (ChgRatio + 1), 2);
RSI.SetDefaultColor(Color.Dark_Gray);
RSI.SetLineWeight(2);
RSI.HideBubble();

def Data = RSI;
def Condition = BarNumber() == 1;

input NormalValueAreaPercent = 68;
profile DataProfileNVA = DataProfile(data = Data, pricePerRow = PricePerRow.TICKSIZE, startNewProfile = Condition, onExpansion = Yes, "value area percent" = NormalValueAreaPercent);
def NormalVAH = DataProfileNVA.GetHighestValueArea();
def NormalVAL = DataProfileNVA.GetLowestValueArea();

input ExtremeValueAreaPercent = 95;
profile DataProfileEVA = DataProfile(data = Data, pricePerRow = PricePerRow.TICKSIZE, startNewProfile = Condition, onExpansion = Yes, "value area percent" = ExtremeValueAreaPercent);
def ExtremeVAH = DataProfileEVA.GetHighestValueArea();
def ExtremeVAL = DataProfileEVA.GetLowestValueArea();

plot ExtremeLineHigh = ExtremeVAH;
ExtremeLineHigh.SetDefaultColor(CreateColor(255, 102, 102));
ExtremeLineHigh.SetLineWeight(5);
ExtremeLineHigh.HideBubble();
ExtremeLineHigh.HideTitle();

AddCloud(NormalVAH, NormalVAL, Color.GRAY);

plot ExtremeLineLow = ExtremeVAL;
ExtremeLineLow.SetDefaultColor(CreateColor(102, 102, 255));
ExtremeLineLow.SetLineWeight(5);
ExtremeLineLow.HideBubble();
ExtremeLineLow.HideTitle();

HloAZ9b.png
 

Similar threads

Top