NinjaTrader's Fibonacci SuperTrend For ThinkOrSwim

john3

Active member
2019 Donor
Convert Fibonacci SuperTrend from NinjaTrader?

Would someone please convert this from Ninja to Thinkorswim?

I appreciate it.
 
Last edited by a moderator:

barbaros

Well-known member
@john3 Try this. I'm not sure how close i was able to get it. Let me know how far it is off. I don't have NinjaTrader to compare.

Python:
# Fibonacci SuperTrend
# converted from www.FreeIndicators.com
# 
# 20200615 - barbaros

input length = 14;
input retrace = 38.2;
input useHighLow = yes;
input showArrows = yes;
input colorBars = yes;
input audioAlerts = yes;

def h = if useHighLow then high else close;
def l = if useHighLow then low else close;
def minL = Lowest(l, length);
def maxH = Highest(h, length);

def hh = if h > maxH[1] then h else hh[1];
def ll = if l < minL[1] then l else ll[1];
def trend = if h > maxH[1] then 1 else if l < minL[1] then -1 else trend[1];
def isTrend = trend == 1;

def MyRange = hh-ll;
def Retracement = retrace/100;
def BuyPrice = ll + (Retracement * MyRange);
def SellPrice = hh - (Retracement * MyRange);

def UpTrend = if isTrend and !isTrend[1] then SellPrice else if isTrend and SellPrice > UpTrend[1] then SellPrice else Uptrend[1];
def DownTrend = if !isTrend && isTrend[1] then BuyPrice else if !isTrend and BuyPrice < DownTrend[1] then BuyPrice else DownTrend[1];

# Plots

plot TrendLine = if isTrend then UpTrend else DownTrend;
TrendLine.assignValueColor(if isTrend then Color.GREEN else Color.RED);

plot UpArrow = if showArrows and isTrend and !isTrend[1] then yes else no;
UpArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

plot DownArrow = if showArrows and !isTrend && isTrend[1] then yes else no;
DownArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

# Color Bars

AssignPriceColor(if colorBars and isTrend then Color.GREEN else if colorBars then Color.RED else Color.CURRENT);

# Alerts

Alert(isTrend and !isTrend[1], "Up Trend", Alert.BAR, Sound.Ding);
Alert(!isTrend && isTrend[1], "Down Trend", Alert.BAR, Sound.Ding);
 
Last edited:

john3

Active member
2019 Donor
@barbaros Thank you very much, but it doesn't seem to match the Ninja's version. Maybe the issue is that changing the settings in the code doesn't seem to change anything. For example, I've changed "length" and "useHighLow," but it didn't seem to do anything.
 

barbaros

Well-known member
@john3 I might have messed something up in the translation. I updated the previous post. May be try that version.
 
Last edited:
  • Like
Reactions: HEC

Similar threads

Top