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

Status
Not open for further replies.
I still have no idea how to put two-time frames on one chart. Can someone explain how this is done? I'm sure a lot of people want to know how to adust two different time frames on one chart. I'm thinking the 1min and 30minute together.
Add the indicator twice in studies, and just change their timeframe.
 

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

Add the indicator twice in studies, and just change their timeframe.

add a new study using this code below then change the aggregation period to 30 Min

Code:
#-----------------------------------

input aggregationPeriod = AggregationPeriod.MIN;
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 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(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.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 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.LINE);
Fib1.SetDefaultColor(Color.White);

plot Fib2 = f2;
Fib2.SetPaintingStrategy(PaintingStrategy.Line);
Fib2.SetDefaultColor(Color.White);

plot Fib3 = f3;
Fib3.SetPaintingStrategy(PaintingStrategy.Line);
Fib3.SetDefaultColor(Color.White);
Fib3.SetLineWeight(2);

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

# Display Label

AddLabel(yes, Concat("Alt SA Period: ", if aggregationperiod < 3600000 then aggregationperiod/60000 + "m" else if aggregationperiod < 86400000 then aggregationperiod/3600000 + "h" else if aggregationperiod < 604800000 then aggregationperiod/86400000 + "D" else if aggregationperiod < 2592000000 then aggregationperiod/604800000 + "Wk" else if aggregationperiod < 31536000000 then aggregationperiod/2592000000 + "Mo" else aggregationperiod/31536000000 + "Yr"),color.WHITE);
 
oops never mind . I got the scanner

I want to be able to see any new trend changes. I had the scanner i just needed to change the time frame to daily
 
@brmeehan Here you go:

Bullish scanner:

Code:
# blackFLAG Futures Trading SwingArm Scan Code

# BULLISH CODE
# Source: TD Ameritrade IP Company, Inc. (c) 2009-2016
#
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;

Bearish scanner:

Code:
# blackFLAG Futures Trading SwingArm Scan Code
# BEARISH CODE
#
# TD Ameritrade IP Company, Inc. (c) 2009-2016
#
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;
 
@BenTen Can you help direct me to where I copy the scanner codes to please? Also; can I set scanners for Daily and 4 Hourly timeframes? And am I able to set these scans on a watch list? Thanks in advance.
 
Hello,

Thanks to @fjr1300 and the rest of the community for this work it is amazing.
Before my questions, I already spent hours looking, testing and still not successful or at least not full understood. Can you please help on these 2 points?

A) BUY Support/SELL Resistance Bubbles and BUY/SELL Confirmed are generated from 2 different indicators, correct? The first ones from SwingArm_ATR_TREND_With_Trigger and the second one from Hull Mov Average?
I managed to use the second code from post #59, but the indication does not work well together on stocks i.e. I have confirmation without the first buy/sell bubbles. (I used period 255 on 2 min chart)

B) I am still confused between SwingArm_ATR_TREND_With_Trigger & Futures_Swingarm_ATRTrail. Why 2 indicators? wasn't possible to write all in one single indicator?

2020-07-22-04-57-05.jpg
 
Last edited:
Could you clarify the strategy here, I'm a little unsure as to how you use the Hull Moving Averages and the swingarm. Thanks!
I am working through this still myself, and results may very but ....

Look to see how the Hull at times moves in agreement with the Swing arm. For example If the Hull is bearish along with a swing arm, you can get some potential downward follow through. When the Hull turns bullish in this scenario, that is a mixed condition, and you may want to be flat. We all trade differently, but this is something I personally consider.

The 55 length setting indicates a potential for a larger move than the 20 length setting (and the 55 is very often is in agreement with the Swing Arm) but when the 55 is wrong the loss tends to be larger.

The points made that the Hull can chop more than once in a row are very valid - especially end of day churn, and during lunch hours EST. The larger the chart time frame the less the chop, but the larger the hit when it happens (and it will).

So really this is very similar to many other strategies, we are using lagging indicators which means you will at times get into trades late, and you will be wrong some of the time.

So just eyeball a chart and watch how the Swing Arm and the Hull work together. I always paper trade first, and I have no issue using shares as a start to a strategy to just learn how it reacts live - not as efficient a deployment of capital as micros of course but you can't beat the commission cost, especially as you are starting out.

Ping me on discord if you want to speak further.
 
  • Like
Reactions: DDW
can you provide the code? It's hard going through 30 pages of comments to find the scanner haha

Code:
# Original Code From: TD Ameritrade IP Company, Inc. (c) 2009-2020
# Original StudyName: ATRTrailingStop
# Type: Study

# 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
# UPDATED: 5/16/2020
# MODIFIED: 6/11/20 - allows defining the period you want the swingarm to draw - This is an add-on to be used with the main SwingArm Script, all alters have been removed.

# NOTE:  WHEN IMPORTING STUDY, MAKE SURE YOU UPDATE THE LOOK AND FEEL TO MATCH MY CHARTS WITHIN THE STUDY SETTINGS. 

#-----------------------------------
#-----------------------------------
# BUY & SELL ALERTS ARE CREATED BY THE HULL MOVING AVERAGE TURNING POINTS STUDY AND MUST BE IN AGREEMENT WITH SWINGARM SUPPORT OR RESISTANCE ZONES TO BE VALID. (UseThinkScript.com by mashume - Upper Study).  MY UPDATED CODE INCLUDES THE BUY / SELL BUBBLES. THE SETTINGS ARE:  1 MIN: 255 PERIOD; 5 MIN: 255 PERIOD; 4 HOUR 255 PERIOD.
#-----------------------------------
#-----------------------------------

input aggregationPeriod = AggregationPeriod.MIN;
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 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(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.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 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.LINE);
Fib1.SetDefaultColor(Color.White);

plot Fib2 = f2;
Fib2.SetPaintingStrategy(PaintingStrategy.Line);
Fib2.SetDefaultColor(Color.White);

plot Fib3 = f3;
Fib3.SetPaintingStrategy(PaintingStrategy.Line);
Fib3.SetDefaultColor(Color.White);
Fib3.SetLineWeight(2);

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

# Display Label

AddLabel(yes, Concat("Alt SA Period: ", if aggregationperiod < 3600000 then aggregationperiod/60000 + "m" else if aggregationperiod < 86400000 then aggregationperiod/3600000 + "h" else if aggregationperiod < 604800000 then aggregationperiod/86400000 + "D" else if aggregationperiod < 2592000000 then aggregationperiod/604800000 + "Wk" else if aggregationperiod < 31536000000 then aggregationperiod/2592000000 + "Mo" else aggregationperiod/31536000000 + "Yr"),color.WHITE);
 
If the group can help me clarify 1 thing... when I have a watchlist with the SwingArm scanner logic.. I get various results.. Zone6, Zone3, etc. whether Red or Green. For this example, 30min time period, Zone4... What does the Zone4 part signify relative to the chart and the Swing arm? thanks
 
Can someone help explain this false breakout. How do you handle a sell signal followed by an immediate buy signal.

fEoGNxN.png
 
Last edited:
So when you say higher time frame how many timeframes would you normally look for confirmation (30M to an 1hr ) or you need it up to a day. in my example up to 10m was all green

It's not just about the higher time frames being green, it's also about where the price is in relation to the zones. That's where reading price action/ the TMO oscillator comes into play. Most false signals on the Swingarm can be avoided by confirming if the Future/ Stock/ Etc is overbought or oversold. If the price is way far from the zones then it's a more substantial risk to go into a trade. As Jose says the price "moves in waves". Your objective as a trader is atempt to catch price at the right moment. Or just be close enough that you are not shaken out of good trades because of a momentary loss.
 
Last edited:
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
366 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