blackFLAG FTS - SwingArm Trend Indicator using ATRTrailing Stop and Fibonacci Retracements

Status
Not open for further replies.
Adding the 50% zone defeats the purpose of the strategy.

@chewie76, there are many fib strategies. I, and every fib trader I know outside of this forum, use the 50%. I don't trade the swingarm strategy so I can't say if the 50 is appropriate for the strat discussed on this thread. But if the 50 is working for you, I encourage you to continue to study price action in that zone. It can be very profitable!

Best wishes!
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Can anyone tell me what the long red and green vertical lines mean? I presume it is a change in momentum but would just like clarification.

NVTT1C6.png
 
That is interesting and simple... when do you get out of the trade? Do you pick a target or just get out when at the MAs crossover?


Mainly using support and resistance levels. First & foremost the lowest zone of the swing arm is the initial stop loss. However, that is obviously only for trades that quickly change direction unexpectedly resulting in a controlled loss. Which again, is not often with the SMA crossover's.

For profit taking, you could use the Swing Arm break or MA crossover as an exit signal, but you will give back some profits always, and possibly in the worst case only basically break even after commissions. I would say a Trailing stop loss would be the best bet, but I don't have much experience with them. Main problem with using other exit indicators is most are too sensitive , so you get "shaken out" of the trade and then the swing arm goes on for another $20-30 after you close the position haha
 
  • Like
Reactions: GGC
@ribitzki21490 I assume you're talking about the thick red and green line from the SwingArm indicator? If so, that is the ATR Trailing Stop line.
 
@henry1224 Did you custom create the labels showing momentum on other time frames? Overlaying 2 at a time is nice but that looks great too. Thanks for sharing.
 
I have noticed that there are updated files for members, can you please give us some idea of what the improvements are?
 
@GGC The latest update will contain grid charts, which include everything that Jose is currently using in his setup and the settings/configurations he has on his chart. All you have to do is import it.
 
Can someone please help me get the script for the Singarm Alternate time frame . i want to get two swing arm time frames onto one chart.
Thanks
 
@henry1224 Did you custom create the labels showing momentum on other time frames? Overlaying 2 at a time is nice but that looks great too. Thanks for sharing.
All of the labels are based on the 10x Indicator from simpler trading, They provide guidance from the higher time frames.

I don't know if the forum administrators would allow for sharing of proprietary indicators? or Indicators that contain sections of proprietary code?
If they allow it , I will share the code.

Henry
 
Hey,

Code:
# blackFLAG FTS SwingArms
# StudyName: blackFLAG_Futures_SwingArm_ATRTrail
# My preferred setting is 28 / 5 FOR ALL TIMEFRAMES
# Edited by: Jose Azcarate
# blackFLAG Futures Trading - FOR EDUCATIONAL PURPOSES ONLY
# TWITTER: @blackflagfuture

# SwingArm Watchlist by [USER=278]@fishstick1229[/USER]
# * Updated code below is to be used for custom watchlist column only **

#Updated text display by [USER=4199]@Fishbed[/USER]

input trailType = {default modified, unmodified};
input ATRPeriod = 28;
input ATRFactor = 5;
input firstTrade = {default long, short};
input averageType = AverageType.WILDERS;

input fib1Level = 61.8;
input fib2Level = 78.6;
input fib3Level = 88.6;

Assert(ATRFactor > 0, "'atr factor' must be positive: " + ATRFactor);

def HiLo = Min(high - low, 1.5 * Average(high - low, ATRPeriod));
def HRef = if low <= high[1]
    then high - close[1]
    else (high - close[1]) - 0.5 * (low - high[1]);
def LRef = if high >= low[1]
    then close[1] - low
    else (close[1] - low) - 0.5 * (low[1] - high);

def trueRange;
switch (trailType) {
case modified:
    trueRange = Max(HiLo, Max(HRef, LRef));
case unmodified:
    trueRange = TrueRange(high, close, low);
}
def loss = ATRFactor * MovingAverage(averageType, trueRange, ATRPeriod);

def state = {default init, long, short};
def trail;
switch (state[1]) {
case init:
    if (!IsNaN(loss)) {
        switch (firstTrade) {
        case long:
            state = state.long;
            trail = close - loss;
        case short:
            state = state.short;
            trail = close + loss;
    }
    } else {
        state = state.init;
        trail = Double.NaN;
    }
case long:
    if (close > trail[1]) {
        state = state.long;
        trail = Max(trail[1], close - loss);
    } else {
        state = state.short;
        trail = close + loss;
    }
case short:
    if (close < trail[1]) {
        state = state.short;
        trail = Min(trail[1], close + loss);
    } else {
        state = state.long;
        trail = close - loss;
    }
}

def BuySignal = Crosses(state == state.long, 0, CrossingDirection.ABOVE);
def SellSignal = Crosses(state == state.short, 0, CrossingDirection.ABOVE);

def ex = if BuySignal then high else if SellSignal then low else if state == state.long then Max(ex[1], high) else if state == state.short then Min(ex[1], low) else ex[1];

def TrailingStop = trail;
def f1 = ex + (trail - ex) * fib1Level / 100;
def f2 = ex + (trail - ex) * fib2Level / 100;
def f3 = ex + (trail - ex) * fib3Level / 100;
def l100 = trail + 0;
def Fib1 = f1;
def Fib2 = f2;
def Fib3 = f3;

def bullAboveZone = state == state.long and close > Fib1;
def bullZone2 = state == state.long and close <= Fib1 and close > Fib2;
def bullZone3 = state == state.long and close <= Fib2 and close > Fib3;
def bullZone4 = state == state.long and close <= Fib3 and close > TrailingStop;

def bearZone2 = state == state.short and close >= Fib1 and close < Fib2;
def bearZone3 = state == state.short and close >= Fib2 and close < Fib3;
def bearZone4 = state == state.short and close >= Fib3 and close < TrailingStop;

# watchlist
assignBackgroundColor(if state == state.long then Color.green else Color.red);
AddLabel(yes, if bullZone2 then "ZONE2"  else if bullZone3 then "ZONE3"  else if bullZone4 then "BUY ZONE4" else if bearZone2 then " ZONE 2"  else if bearZone3 then " ZONE3"  else if bearZone4 then "SELL ZONE4" else " ",  if bullZone4 or bearZone4 then color.BLUE else Color.BLACK);

If you need help installing it, please take a look at this video below:

 
@technicallydreaming I like the looks of this! Can you share please.

Also, just out of curiosity, is it possible to remove the S2,S3,S4, R1, R2, R3, etc, and only keep the long and short bubbles? The reason why I ask is that I plan to use this with two time frames overlapping each other like everyone else is doing but im not sure is it will be too much clutter with all the extra support and resistance bubbles. Have you tried using this with two time frames on top of each other yet?
 
Here is my version of BlackFlag_SwingArms
  • I changed the fib lines to eighths, extended them to the full range 8 zones
  • I plot it 1 time frame greater than the chart
  • I painted the bars based on my 4EMA Rank short term > long term =Cyan else Orange
  • I also added the SuperTrend

Code:
####################################################

Declare Upper;
Def price =(Open+Close)/2;
Input Length1 =3;
Input Length2 =6;
Input Length3 =9;
Input Length4 =12;
Input Length5 =15;
Input Length6 =30;
Input Length7 =45;
Input Length8 =60;
input averageType = AverageType.exponential;
input AtrMult = 1.00;
input nATR = 6;
input AvgType = AverageType.HULL;
input PaintBars = no;
###I don't use this paint bar of the Supertrend########
input aggregationPeriod = AggregationPeriod.MIN;
input trailType = {default modified, unmodified};
input ATRPeriod = 28;
input ATRFactor = 5;
input firstTrade = {default long, short};
input averageType2 = AverageType.WILDERS;

#### 4 EMA Rank##########
def D1 = MovingAverage(AveragetYPE,Price,length1);
def D2 = MovingAverage(AverageType,price,Length2);
def D3 = MovingAverage(AverageType,price,Length3);
def D4 = MovingAverage(AverageType,price,Length4);
def W1 = MovingAverage(AveragetYPE,Price,length5);
def W2 = MovingAverage(AverageType,price,Length6);
def W3 = MovingAverage(AverageType,price,Length7);
def W4 = MovingAverage(AverageType,price,Length8);

def DCondition1 = If(D1 > D2 and D2 > D3 and D3 > D4, 5,
If((D1 > D2 and D2 > D4 and D4 > D3) or (D1 > D3 and D3 > D2 and D2 > D4) or
(D2 > D1 and D1 > D3 and D3 > D4), 4, If(D2 > D1 and D1 > D4 and D4 > D3, 3,
If((D1 > D3 and D3 > D4 and D4 > D2) or ( D1 > D4 and D4 > D2 and D2 > D3)  or
(D2 > D3 and D3 > D1 and D1 > D4)  or (D3 > D1 and D1 > D2 and D2 > D4) , 2,
If((D1 > D4 and D4 > D3 and D3 > D2) or (D3 > D2 and D2 > D1 and D1 > D4), 1, 0)))));
def DCondition2 = If(D4 > D3 and D3 > D2 and D2 > D1, -5,
If((D3 > D4 and D4 > D2 and D2 > D1) or (D4 > D2 and D2 > D3 and D3 > D1) or
(D4 > D3 and D3 > D1 and D1 > D2), -4, If(D3 > D4 and D4 > D1 and D1 > D2, -3,
If((D2 > D4 and D4 > D3 and D3 > D1) or (D3 > D2 and D2 > D4 and D4 > D1)  or
(D4 > D1 and D1 > D3 and D3 > D2)  or (D4 > D2 and D2 > D1 and D1 > D3) , -2,
If((D2 > D3 and D3 > D4 and D4 > D1) or (D4 > D1 and D1 > D2 and D2 > D3), -1, 0)))));
def WCondition1 = If(W1 > W2 and W2 > W3 and W3 > W4, 50,
If((W1 > W2 and W2 > W4 and W4 > W3) or (W1 > W3 and W3 > W2 and W2 > W4) or
(W2 > W1 and W1 > W3 and W3 > W4), 40, If(W2 > W1 and W1 > W4 and W4 > W3, 30,
If((W1 > W3 and W3 > W4 and W4 > W2) or ( W1 > W4 and W4 > W2 and W2 > W3)  or
(W2 > W3 and W3 > W1 and W1 > W4)  or (W3 > W1 and W1 > W2 and W2 > W4) , 20,
If((W1 > W4 and W4 > W3 and W3 > W2) or (W3 > W2 and W2 > W1 and W1 > W4), 10, 0)))));
def WCondition2 = If(W4 > W3 and W3 > W2 and W2 > W1, -50,
If((W3 > W4 and W4 > W2 and W2 > W1) or (W4 > W2 and W2 > W3 and W3 > W1) or
(W4 > W3 and W3 > W1 and W1 > W2), -40, If(W3 > W4 and W4 > W1 and W1 > W2, -30,
If((W2 > W4 and W4 > W3 and W3 > W1) or (W3 > W2 and W2 > W4 and W4 > W1)  or
(W4 > W1 and W1 > W3 and W3 > W2)  or (W4 > W2 and W2 > W1 and W1 > W3) , -20,
If((W2 > W3 and W3 > W4 and W4 > W1) or (W4 > W1 and W1 > W2 and W2 > W3), -10, 0)))));
def WT = (WCondition1+WCondition2);
def TT = (WCondition1+WCondition2+DCondition1+DCondition2);
DefineGlobalColor(“Long”,Color.Cyan);
DefineGlobalColor(“Short”,Color.Orange);
DefineGlobalColor("Neutral”,Color.YELLOW);
Def Long = TT > WT;
Def Short = TT < WT;

AssignPriceColor(If Long then GlobalColor(“Long”) else if  Short then GlobalColor(“Short”) else GlobalColor("Neutral"));

plot arrowup=if TT crosses above WT then Low - ATR(1) else double.Nan;
arrowup.setPaintingStrategy(paintingStrategy.ARROW_UP);
arrowup.setDefaultColor(color.Cyan);

plot arrowdown=if TT crosses below WT then High + ATR(1) else double.NaN;
arrowdown.setPaintingStrategy(paintingStrategy.ARROW_dowN);
arrowdown.setDefaultColor(color.Dark_Orange);
Input Label = yes;
AddLabel(Label, if TT >WT then "4MR > W" else "4MR < W", if TT > WT then Color.Cyan else Color.Orange);

##########Supertrend###############

def ATR = ATR("length" = nATR, "average type" = AvgType);
def UP_Band_Basic = HL2 + (AtrMult * ATR);
def LW_Band_Basic = HL2 + (-AtrMult * ATR);

def UP_Band = if ((UP_Band_Basic < UP_Band[1]) or (close[1] > UP_Band[1])) then UP_Band_Basic else UP_Band[1];
def LW_Band = if ((LW_Band_Basic > LW_Band[1]) or (close[1] < LW_Band[1])) then LW_Band_Basic else LW_Band[1];

def ST = if ((ST[1] == UP_Band[1]) and (close < UP_Band)) then UP_Band
else if ((ST[1] == UP_Band[1]) and (close > Up_Band)) then LW_Band
else if ((ST[1] == LW_Band[1]) and (close > LW_Band)) then LW_Band
else if ((ST[1] == LW_Band) and (close < LW_Band)) then UP_Band
else LW_Band;

plot SuperTrend = ST;
SuperTrend.AssignValueColor(if close < ST then Color.RED else Color.GREEN);
AssignPriceColor(if PaintBars and close < ST

                then Color.Dark_Orange

               else if PaintBars and close > ST

                    then Color.Cyan

                     else Color.CURRENT);
SuperTrend.setLineWeight(3);
plot ArrowDownST = Supertrend crosses above close;
ArrowDownST.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
ArrowDownST.SetDefaultColor(Color.RED);
ArrowDownST.SetLineWeight(3);

plot ArrowUpST = Supertrend crosses below close;
ArrowUpST.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
ArrowUpST.SetDefaultColor(Color.GREEN);
ArrowUpST.SetLineWeight(3);

##############swingArm#################

def fib0Level = 0;
def fib1Level = 12.5;
def fib2Level = 25;
def fib3Level = 37.5;
def fib4Level = 50.0;
def fib5Level = 62.5;
def fib6Level = 75;
def fib7Level = 87.5;

Assert(ATRFactor > 0, "'atr factor' must be positive: " + ATRFactor);
def open = Open(Period = aggregationPeriod);
def high = high(period = aggregationPeriod);
def low = low(period = aggregationPeriod);
def close = close(period = aggregationPeriod);

def HiLo = Min(high - low, 1.5 * Average(high - low, ATRPeriod));
def HRef = if low <= high[1]
    then high - close[1]
    else (high - close[1]) - 0.5 * (low - high[1]);
def LRef = if high >= low[1]
    then close[1] - low
    else (close[1] - low) - 0.5 * (low[1] - high);

def trueRange;
switch (trailType) {
case modified:
    trueRange = Max(HiLo, Max(HRef, LRef));
case unmodified:
    trueRange = TrueRange(high, close, low);
}
def loss = ATRFactor * MovingAverage(averageType2, trueRange, ATRPeriod);

def state = {default init, long, short};
def trail;
switch (state[1]) {
case init:
    if (!IsNaN(loss)) {
        switch (firstTrade) {
        case long:
            state = state.long;
            trail = close - loss;
        case short:
            state = state.short;
            trail = close + loss;
    }
    } else {
        state = state.init;
        trail = Double.NaN;
    }
case long:
    if (close > trail[1]) {
        state = state.long;
        trail = Max(trail[1], close - loss);
    } else {
        state = state.short;
        trail = close + loss;
    }
case short:
    if (close < trail[1]) {
        state = state.short;
        trail = Min(trail[1], close + loss);
    } else {
        state = state.long;
        trail = close - loss;
    }
}

def BuySignal = Crosses(state == state.long, 0, CrossingDirection.ABOVE);
def SellSignal = Crosses(state == state.short, 0, CrossingDirection.ABOVE);

def ex = if BuySignal then high else if SellSignal then low else if state == state.long then Max(ex[1], high) else if state == state.short then Min(ex[1], low) else ex[1];

plot TrailingStop = trail;

TrailingStop.SetPaintingStrategy(PaintingStrategy.POINTS);
TrailingStop.DefineColor("Long", Color.GREEN);
TrailingStop.DefineColor("Short", Color.RED);
TrailingStop.SetLineWeight(5);
TrailingStop.AssignValueColor(if state == state.long
   then TrailingStop.Color("Long")
   else TrailingStop.Color("Short"));
#TrailingStop.hide();

plot Extremum = ex;
Extremum.SetPaintingStrategy(PaintingStrategy.POINTS);
Extremum.DefineColor("HH", Color.GREEN);
Extremum.DefineColor("LL", Color.RED);
Extremum.AssignValueColor(if state == state.long
    then Extremum.Color("HH")
    else Extremum.Color("LL"));
Extremum.Hide();
def f0 = ex + (trail - ex) * fib0Level / 100;
def f1 = ex + (trail - ex) * fib1Level / 100;
def f2 = ex + (trail - ex) * fib2Level / 100;
def f3 = ex + (trail - ex) * fib3Level / 100;
def f4 = ex + (trail - ex) * fib4Level / 100;
def f5 = ex + (trail - ex) * fib5Level / 100;
def f6 = ex + (trail - ex) * fib6Level / 100;
def f7 = ex + (trail - ex) * fib7Level / 100;
def l100 = trail + 0;

plot Fib0 = f0;
Fib0.SetPaintingStrategy(PaintingStrategy.dashes);
Fib0.DefineColor("Long", Color.Dark_Red);
Fib0.DefineColor("Short", Color.Dark_Green);
Fib0.AssignValueColor(if state == state.long
   then Fib0.Color("Long")
   else Fib0.Color("Short"));
Fib0.SetLineWeight(2);
plot Fib1 = f1;
Fib1.SetPaintingStrategy(PaintingStrategy.dashes);
Fib1.DefineColor("Long", Color.Dark_Red);
Fib1.DefineColor("Short", Color.Dark_Green);
Fib1.AssignValueColor(if state == state.long
   then Fib1.Color("Long")
   else Fib1.Color("Short"));
Fib1.SetLineWeight(2);
plot Fib2 = f2;
Fib2.SetPaintingStrategy(PaintingStrategy.dashes);
Fib2.DefineColor("Long", Color.Light_Red);
Fib2.DefineColor("Short", Color.Light_Green);
Fib2.AssignValueColor(if state == state.long
   then Fib2.Color("Long")
   else Fib2.Color("Short"));
plot Fib3 = f3;
Fib3.SetPaintingStrategy(PaintingStrategy.dashes);
Fib3.DefineColor("Long", Color.Light_Red);
Fib3.DefineColor("Short", Color.Light_Green);
Fib3.AssignValueColor(if state == state.long
   then Fib3.Color("Long")
   else Fib3.Color("Short"));
Fib3.SetLineWeight(1);
plot Fib4 = f4;
Fib4.SetPaintingStrategy(PaintingStrategy.points);
Fib4.SetDefaultColor(Color.White);
Fib4.SetLineWeight(1);
plot Fib5 = f5;
Fib5.SetPaintingStrategy(PaintingStrategy.dashes);
Fib5.DefineColor("Long", Color.Light_Green);
Fib5.DefineColor("Short", Color.Light_Red);
Fib5.AssignValueColor(if state == state.long
   then Fib5.Color("Long")
   else Fib5.Color("Short"));
Fib5.SetLineWeight(1);
plot Fib6 = f6;
Fib6.SetPaintingStrategy(PaintingStrategy.dashes);
Fib6.DefineColor("Long", Color.Light_Green);
Fib6.DefineColor("Short", Color.Light_Red);
Fib6.AssignValueColor(if state == state.long
   then Fib6.Color("Long")
   else Fib6.Color("Short"));
Fib6.SetLineWeight(2);
plot Fib7 = f7;
Fib7.SetPaintingStrategy(PaintingStrategy.dashes);
Fib7.DefineColor("Long", Color.Dark_Green);
Fib7.DefineColor("Short", Color.Dark_Red);
Fib7.AssignValueColor(if state == state.long
   then Fib7.Color("Long")
   else Fib7.Color("Short"));
Fib7.SetLineWeight(2);

AddCloud(f0, f1, Color.dark_Red, Color.Dark_Green, no);
AddCloud(f1, f2, Color.Red, Color.Green, no);
AddCloud(f2, f3, Color.Light_Red, Color.Light_Green, no);
AddCloud(f5, f6, Color.LIGHT_GREEN, Color.LIGHT_RED, no);
AddCloud(f6, f7, Color.GREEN, Color.RED, no);
AddCloud(f7, l100, Color.DARK_GREEN, Color.DARK_RED, no);

def l5 = state[1] == state.long and close crosses below f5[1];
def l6 = state[1] == state.long and close crosses below f6[1];
def l7 = state[1] == state.long and close crosses below f7[1];
def s5 = state[1] == state.short and close crosses above f5[1];
def s6 = state[1] == state.short and close crosses above f6[1];
def s7 = state[1] == state.short and close crosses above f7[1];

def atrSA = Average(TrueRange(high, close, low), 14);

plot LS1 = if l5 then low - atrSA else Double.NaN;
plot LS2 = if l6 then low - 1.5 * atrSA else Double.NaN;
plot LS3 = if l7 then low - 2 * atrSA else Double.NaN;
plot SS1 = if s5 then high + atrSA else Double.NaN;
plot SS2 = if s6 then high + 1.5 * atrSA else Double.NaN;
plot SS3 = if s7 then high + 2 * atrSA else Double.NaN;

LS1.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
LS1.SetDefaultColor(Color.GREEN);
LS1.SetLineWeight(1);
LS1.Hide();
LS2.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
LS2.SetDefaultColor(Color.GREEN);
LS2.SetLineWeight(1);
LS2.Hide();
LS3.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
LS3.SetDefaultColor(Color.GREEN);
LS3.SetLineWeight(1);
LS3.Hide();

SS1.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
SS1.SetDefaultColor(Color.RED);
SS1.SetLineWeight(1);
SS1.Hide();
SS2.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
SS2.SetDefaultColor(Color.RED);
SS2.SetLineWeight(1);
SS2.Hide();
SS3.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
SS3.SetDefaultColor(Color.RED);
SS3.SetLineWeight(1);
SS3.Hide();

#Alert(l1, "Price crossed below Fib5 level in long trend", Alert.BAR, Sound.Bell);
#Alert(l2, "Price crossed below Fib6 level in long trend", Alert.BAR, Sound.Bell);
#Alert(l3, "Price crossed below Fib7 level in long trend", Alert.BAR, Sound.Bell);
#Alert(s1, "Price crossed above Fib5 level in short trend", Alert.BAR, Sound.Bell);
#Alert(s2, "Price crossed above Fib6 level in short trend", Alert.BAR, Sound.Bell);
#Alert(s3, "Price crossed above Fib7 level in short trend", Alert.BAR, Sound.Bell);


# *******************************************************
# DAY TRADING SETTINGS USING 1 AND 5 MINUTE CHARTS

#AddLabel(yes, "Alt SA Period: " + aggregationPeriod/60000 +"m",color.WHITE);
AddLabel(yes, if price> TrailingStop then "BUY SUPPORT - BUY ZONES 5,6 or 7" else "SELL RESISTANCE - SELL ZONES 5,6 or 7", if price > TrailingStop then Color.GREEN else Color.Red);

# SWING TRADING SETTINGS USING 4 HOUR CHART ( needs work below )

AddLabel(yes," SWING TRADING STRATEGY : ",color.WHITE);
AddLabel(yes, if price> TrailingStop then "* IF * SWINGARM Is BULLISH - Wait For Entry Confirmation" else "* IF * SWINGARM - Is BEARISH - Wait For Entry Confirmation", if price> TrailingStop then Color.GREEN else Color.RED);
########### End of indicator code############

Now here is my watchlist code

Code:
#################################
# SwingArm Watchlist by [USER=278]@fishstick1229[/USER]
# * Updated code below is to be used for custom watchlist column only **

#Updated text display by [USER=4199]@Fishbed[/USER]

input trailType = {default modified, unmodified};
input ATRPeriod = 28;
input ATRFactor = 5;
input firstTrade = {default long, short};
input averageType = AverageType.WILDERS;

def fib0Level = 0;
def fib1Level = 12.5;
def fib2Level = 25;
def fib3Level = 37.5;
def fib4Level = 50.0;
def fib5Level = 62.5;
def fib6Level = 75;
def fib7Level = 87.5;

Assert(ATRFactor > 0, "'atr factor' must be positive: " + ATRFactor);

def HiLo = Min(high - low, 1.5 * Average(high - low, ATRPeriod));
def HRef = if low <= high[1]
    then high - close[1]
    else (high - close[1]) - 0.5 * (low - high[1]);
def LRef = if high >= low[1]
    then close[1] - low
    else (close[1] - low) - 0.5 * (low[1] - high);

def trueRange;
switch (trailType) {
case modified:
    trueRange = Max(HiLo, Max(HRef, LRef));
case unmodified:
    trueRange = TrueRange(high, close, low);
}
def loss = ATRFactor * MovingAverage(averageType, trueRange, ATRPeriod);

def state = {default init, long, short};
def trail;
switch (state[1]) {
case init:
    if (!IsNaN(loss)) {
        switch (firstTrade) {
        case long:
            state = state.long;
            trail = close - loss;
        case short:
            state = state.short;
            trail = close + loss;
    }
    } else {
        state = state.init;
        trail = Double.NaN;
    }
case long:
    if (close > trail[1]) {
        state = state.long;
        trail = Max(trail[1], close - loss);
    } else {
        state = state.short;
        trail = close + loss;
    }
case short:
    if (close < trail[1]) {
        state = state.short;
        trail = Min(trail[1], close + loss);
    } else {
        state = state.long;
        trail = close - loss;
    }
}

def BuySignal = Crosses(state == state.long, 0, CrossingDirection.ABOVE);
def SellSignal = Crosses(state == state.short, 0, CrossingDirection.ABOVE);

def ex = if BuySignal then high else if SellSignal then low else if state == state.long then Max(ex[1], high) else if state == state.short then Min(ex[1], low) else ex[1];

def TrailingStop = trail;
def f0 = ex + (trail - ex) * fib0Level / 100;
def f1 = ex + (trail - ex) * fib1Level / 100;
def f2 = ex + (trail - ex) * fib2Level / 100;
def f3 = ex + (trail - ex) * fib3Level / 100;
def f4 = ex + (trail - ex) * fib4Level / 100;
def f5 = ex + (trail - ex) * fib5Level / 100;
def f6 = ex + (trail - ex) * fib6Level / 100;
def f7 = ex + (trail - ex) * fib7Level / 100;
def l100 = trail + 0;
def Fib0 = f0;
def Fib1 = f1;
def Fib2 = f2;
def Fib3 = f3;
def Fib4 = f4;
def Fib5 = f5;
def Fib6 = f6;
def Fib7 = f7;



def bullAboveZone = state == state.long and close > Fib4;
def bearBelowZone = state == state.short and close < Fib4;
def bullZone1 = state == state.long and close <= Fib0 and close > Fib1;
def bullZone2 = state == state.long and close <= Fib1 and close > Fib2;
def bullZone3 = state == state.long and close <= Fib2 and close > Fib3;
def bullZone4 = state == state.long and close <= Fib3 and close > Fib4;
def bullZone5 = state == state.long and close <= Fib4 and close > Fib5;
def bullZone6 = state == state.long and close <= Fib5 and close > Fib6;
def bullZone7 = state == state.long and close <= Fib6 and close > Fib7;
def bullZone8 = state == state.long and close <= Fib7 and close > TrailingStop;

def bearZone1= state == state.short and close >= Fib0 and close < Fib1;
def bearZone2 = state == state.short and close >= Fib1 and close < Fib2;
def bearZone3 = state == state.short and close >= Fib2 and close < Fib3;
def bearZone4 = state == state.short and close >= Fib3 and close < Fib4;
def bearZone5 = state == state.short and close >= Fib4 and close < Fib5;
def bearZone6 = state == state.short and close >= Fib5 and close < Fib6;
def bearZone7 = state == state.short and close >= Fib6 and close < Fib7;
def bearZone8 = state == state.short and close >= Fib7 and close < TrailingStop;

# watchlist
assignBackgroundColor(if state == state.long then Color.green else Color.red);
AddLabel(yes, if bullZone1 then “ZONE1” else if bullZone2 then "ZONE2"  else if bullZone3 then "ZONE3" else if bullZone4 then "ZONE4" else if bullZone5 then “ZONE5” else if bullZone6 then “ZONE6” else if bullZone7 then “ZONE7” else if bullZone8 then “BUY ZONE8”else if bearZone1 then “ZONE1” else if bearZone2 then " ZONE 2"  else if bearZone3 then " ZONE3"  else if bearZone4 then " ZONE4" else if bearZone5 then “ZONE5” else if bearZone6 then “ZONE6” else if bearZone7 then “ZONE7” else if bearZone8 then “SELL ZONE8” else " ",  if bullZone8 or bearZone8 then color.BLUE else Color.BLACK);
##########end of Watchlist Code###########
 
Last edited by a moderator:
Having an issue when I attempt to make the aggregation period 1 hour on a 1minute chart, the aggregation appears as just a long green or red line with no zones appearing, how can I fix this?
 
Status
Not open for further replies.

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
196 Online
Create Post

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top