最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

pine script - pineScript to thinkScript - request - Stack Overflow

matteradmin3PV0评论

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);

Post a comment

comment list (0)

  1. No comments so far