Reputation: 133
I want to conver the pivot point Supertrend indicator to ThinkScript- but I am unable to ;
==== I converted the pineScript to ThinkScript - but its not work; and as far as I could debug issue is with "TUp" and "TDown"
declare lower;
input ATRPeriod = 10;
input ATRFactor = 3;
input PivotPointPeriod = 2;
input showLabels = yes;
def ATR = Average(TrueRange(high, close, low), ATRPeriod);
def ph = if high == Highest(high, PivotPointPeriod * 2 + 1) then high else Double.NaN;
def pl = if low == Lowest(low, PivotPointPeriod * 2 + 1) then low else Double.NaN;
rec center = if !IsNaN(ph) then ph else if !IsNaN(pl) then pl else center[1];
def UpperBand = center - ATRFactor * ATR;
def LowerBand = center + ATRFactor * ATR;
rec TUp = if close[1] > TUp[1] then Max(UpperBand, TUp[1]) else UpperBand;
rec TDown = if close[1] < TDown[1] then Min(LowerBand, TDown[1]) else LowerBand;
def Trend = if close > TDown[1] then 1 else if close < TUp[1] then -1 else Trend[1];
def TrailSL = if Trend == 1 then TUp else TDown;
plot SuperTrend = TrailSL;
SuperTrend.SetDefaultColor(GetColor(1));
SuperTrend.SetLineWeight(2);
# Plot Buy/Sell signals
def BuySignal = Trend == 1 and Trend[1] == -1;
def SellSignal = Trend == -1 and Trend[1] == 1;
AddChartBubble(showLabels and BuySignal, low, "Buy", Color.GREEN, no);
AddChartBubble(showLabels and SellSignal, high, "Sell", Color.RED, yes);
# Alerts for buy/sell
Alert(BuySignal, "Buy Signal", Alert.BAR, Sound.Chime);
Alert(SellSignal, "Sell Signal", Alert.BAR, Sound.Bell);
Upvotes: 0
Views: 33