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

Status
Not open for further replies.
D

[deleted]13

Guest
This thread has exhausted its substantive discussion of this indicator so it has been locked
This thread is still available for reading. If looking for specific information in this thread, here is a great hack for searching many-paged threads.


The SwingArm is an idea I had using the ATRTrailingStop and modifying it to have FIB Retracements into it. "I am not a coder..." I hired someone to help me out in getting it done. For chart examples of recent setups, you can view them below. Happy trading to all.

It can be used on any timeframe. The best for me (day trading) is the 10-minute chart. For Swing Trading, the 4 hours chart works well. Alerts can be set up using an ATRTrailingStop scan. If interested, I can provide the code here as well. There are tons of information on my website about the way it works. I will be updating it soon. (work in progress as the system gets more and more simplified with the help of people in this amazing group.)

The tools provided by this group make this a very valuable trading strategy.
Code:
# Original Code From: TD Ameritrade IP Company, Inc. (c) 2009-2020
# Original StudyName: ATRTrailingStop
# Type: Study

# blackFLAG FTS SwingArms
# Edited by: Jose Azcarate
# blackFLAG Futures Trading - FOR EDUCATIONAL PURPOSES ONLY
# TWITTER: @blackflagfuture
# Settings Vary. My preferred setting is 28 / 5  But also use 30 / 8 and 5 / 3.5 depending on strategy.

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

plot TrailingStop = trail;

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

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 f1 = ex + (trail - ex) * fib1Level / 100;
def f2 = ex + (trail - ex) * fib2Level / 100;
def f3 = ex + (trail - ex) * fib3Level / 100;
def l100 = trail + 0;

plot Fib1 = f1;
Fib1.SetPaintingStrategy(PaintingStrategy.POINTS);
Fib1.SetDefaultColor(Color.BLACK);
Fib1.Hide();

plot Fib2 = f2;
Fib2.SetPaintingStrategy(PaintingStrategy.POINTS);
Fib2.SetDefaultColor(Color.BLACK);
Fib2.Hide();

plot Fib3 = f3;
Fib3.SetPaintingStrategy(PaintingStrategy.POINTS);
Fib3.SetDefaultColor(Color.BLACK);
Fib3.Hide();

AddCloud(f1, f2, Color.LIGHT_GREEN, Color.LIGHT_RED, no);
AddCloud(f2, f3, Color.GREEN, Color.RED, no);
AddCloud(f3, l100, Color.DARK_GREEN, Color.DARK_RED, no);

def l1 = state[1] == state.long and close crosses below f1[1];
def l2 = state[1] == state.long and close crosses below f2[1];
def l3 = state[1] == state.long and close crosses below f3[1];
def s1 = state[1] == state.short and close crosses above f1[1];
def s2 = state[1] == state.short and close crosses above f2[1];
def s3 = state[1] == state.short and close crosses above f3[1];

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

plot LS1 = if l1 then low - atr else Double.NaN;
plot LS2 = if l2 then low - 1.5 * atr else Double.NaN;
plot LS3 = if l3 then low - 2 * atr else Double.NaN;
plot SS1 = if s1 then high + atr else Double.NaN;
plot SS2 = if s2 then high + 1.5 * atr else Double.NaN;
plot SS3 = if s3 then high + 2 * atr 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 Fib1 level in long trend", Alert.BAR, Sound.Bell);
Alert(l2, "Price crossed below Fib2 level in long trend", Alert.BAR, Sound.Bell);
Alert(l3, "Price crossed below Fib3 level in long trend", Alert.BAR, Sound.Bell);
Alert(s1, "Price crossed above Fib1 level in short trend", Alert.BAR, Sound.Bell);
Alert(s2, "Price crossed above Fib2 level in short trend", Alert.BAR, Sound.Bell);
Alert(s3, "Price crossed above Fib3 level in short trend", Alert.BAR, Sound.Bell);

https://tos.mx/jhDv0Pt

ivPYaIS.png


 
Last edited by a moderator:
@fjr1300 Hello can you post the code for the turning points with the bubbles buy support sell resistance ? What kind of bars are on the hourly chart can you share more details and the grid ? Thanks
 
@fjr1300 Hello can you post the code for the turning points with the bubbles buy support sell resistance ? What kind of bars are on the hourly chart can you share more details and the grid ? Thanks

Hi. This is what I added at the bottom of the study (Hull Moving Average Turning Points) to have the bubbles show at max or min.

AddChartBubble(MA_MAX == MA_MAX , MA_MAX , "SELL RESISTANCE" , Color.RED,no);

AddChartBubble(MA_MIN == MA_MIN , MA_MIN , "BUY SUPPORT" , Color.GREEN, yes);


As far as the bars, I use Heiken Ashi Candles.
 
THANKS what settings for the hourly are you using for the Hull ?
That above code for the bubbles producers errors can you check and let me know what i need to change

Edit: i got it worked
 
Last edited by a moderator:
Thank you so much for your sharing! Can someone write a scan version for this study to show when stocks "swingarm breakdown" or "swingarm breakup" on different timeframe such as 5 mins, 10 mins, 30 mins, 1 hours, 4 hours and daily?

Code:
input trailType = {default modified, unmodified};
input ATRPeriod = 28;
input ATRFactor = 5;
input firstTrade = {default long, short};
input averageType = AverageType.WILDERS;
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;
}
}
plot BuySignal = if Crosses(state == state.long, 0, CrossingDirection.ABOVE) then low else Double.NaN;
BuySignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
plot SellSignal = if Crosses(state == state.short, 0, CrossingDirection.ABOVE) then high else Double.NaN;
SellSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
plot TrailingStop = trail;
TrailingStop.SetPaintingStrategy(PaintingStrategy.POINTS);
TrailingStop.DefineColor("Buy", GetColor(0));
TrailingStop.DefineColor("Sell", GetColor(1));
TrailingStop.AssignValueColor(if state == state.long
then TrailingStop.Color("Sell")
else TrailingStop.Color("Buy"));
Alert(BuySignal, "Trail Stop Long Entry", Alert.BAR, Sound.DING);
Alert(SellSignal, "Trail Stop Short Entry", Alert.BAR, Sound.DING);

AddChartBubble(BuySignal == BuySignal , BuySignal , "SWINGARM BREAKUP", Color.GREEN,no);
AddChartBubble(SellSignal == SellSignal , SellSignal , "SWINGARM BREAKDOWN", Color.RED, yes);
 
I have it. I will post it.

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2009-2016

# Source: Pete Hann LLC
# https://www.hahn-tech.com/
# NOTE:  SELECT ON THE BOTTOM EITHER PLOT BUY Signals OR PLOT SELL SIGNALS.  Just move the # to the one you want to scan for.

input trailType = {default modified, unmodified};
input ATRPeriod = 28;
input ATRFactor = 5;
input firstTrade = {default long, short};
input averageType = AverageType.WILDERS;
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);
# move comment markers dependin on which of these two you want to run
plot scan = BuySignal;
#plot scan = SellSignal;
 
Last edited by a moderator:
@Craighaber71 No. I do not have one for the buy / sell bubbles. Only for the SwingArm breakup or breakdown. Hopefully someone in this group can come up with it..I do have an alert that goes to your email / text when it occurs.

BUY OR SELL EMAIL OR TEXT ALERT FOR SWINGARMS BREAKUP OR BREAKDOWN:

Code:
# blackFLAG FTS Code J Azcarate
# Two & Ten Minute Chart Alert - # BUY  Alert - # BULLISH Alert
# NOTE:  Right-click on your chart, then select CREATE ALERT.  Select Drop Down "Price" and click on STUDY.  EDIT and place the code.  Select TRIGGER if: TRUE  Below, select Set Alert Rules and click on #1 Recreate alert for reverse crossover and also silent opposite alert.  Then Click Apply Settings. The Alert will appear on your MarketWatch tab.

# SETTINGS:  I prefer to set up two alerts one for 255 periods on 10 min chart and for 2 Minute chart - Use 200 Period  The code below was originally for a crossover, but using just one period, it works fine.

input price = close;
input lengthOne = 255;
input displaceOne = 0;
input lengthTwo = 255;
input displaceTwo = 0;

def hmaOne = MovingAverage(AverageType.HULL, price, lengthOne)[-displaceOne];
def hmaTwo = MovingAverage(AverageType.HULL, price, lengthTwo)[-displaceTwo];

#---------- Signals Section
def up = hmaOne > hmaOne[1] and hmaTwo > hmaTwo[1];
def down = hmaOne < hmaOne[1] and hmaTwo < hmaTwo[1];

def upArrow = up and !up[1];
def downArrow = down and !down[1];

# use this signal to be notified only AFTER signal bar CLOSES, ONLY up arrows
# (signals are locked in and cannot be reversed)
plot signal = upArrow[1];

# use this signal to be notified only AFTER signal bar CLOSES, ONLY down arrows
# (signals are locked in and cannot be reversed)
#plot signal = downArrow[1];

BUY SETUPS FOR /ES FUTURES Using blackFLAG FTS SwingArms and buy zones.

This morning's short Setup. Just 1 ES mini as I study the great tools available here on UseThinkScript. Using my Swingarms and other tools discussed in this thread. Grateful to a @BenTen @horserider @mashume for their great work.

YBaUM01.jpg
 
Last edited by a moderator:
@fjr1300 this is extremely informative indicator.
what does the long vs. short option mean? I tried switching but there appears to be no changes?

I am not sure I understand. Please explain. be specific. provide me a link to the chart or code you are referring to so I can help you. Happy to do it.
 
@fjr1300 Thank you for posting this and your hard work.
I'm trying to come up with a strategy with this indicator. What would you do to minimize unexpected reversals like this?
I see it trigger on a breakout but then reverses to test your nerves...

T1sLiRK.png
 
@barbaros I see the indicator settings are not matching mine. That will make it very difficult to understand. Start with changing the ATR settings from dots to lines. and resend me the same chart. Use heiken ashi candles as well.
 
@fjr1300
based on your script above in post 1:

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

This code here, I tried switching both, but doesnt seem to have any changes?
 
@Playstation That is not to be edited at all. You may be misunderstanding what is posted. I am happy to screen share with you and discuss your questions. You can direct message me and we can meet via zoom or something for a few minutes.
 
@barbaros I recommend you study the charts on my Twitter feed. You can click on the media link and see the sequence of charts over time. Probably, you will get a better understanding. @blackflagfuture
 
Status
Not open for further replies.

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
466 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