###############################
input AtrMult = 1.00;
input nATR = 6;
input AvgType = AverageType.HULL;
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;
def SuperTrend = ST;
def Signal = If Supertrend crosses above close then 1 else if Supertrend crosses below close then 2 else 0;
addlabel(yes,if signal==1 then "SHORT" else if signal==2 then "LONG " else "neutral",color.Black);
assignBackgroundColor(
if signal==1 then color.RED else if signal==2 then color.GREEN else if signal==0 then color.yellow else color.black) ;
##End of code##
########################################################################
and I use this for the swing arms
############################################################
# 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 code#
Here is the workbook that I customized: Blackflag Swingarm + different time frames overlayed.
https://tos.mx/dX2ClE5
I also made a video explaining how to add the different time frames to your chart. You should find this useful.
VIDEO LINK: https://screencast-o-matic.com/watch/cYioYlEnzh
@mcallen Thanks, how do I switch between the time zones myself? I'd like to experiment with different times on one chart.
Nice! I guess I didn't catch how to do that. Can you give me some info on how to set that up on my chart?any reason why you didn't want to use labels?
Nice! I guess I didn't catch how to do that. Can you give me some info on how to set that up on my chart?
# 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]
#Combined Watchlist code to produce in chart label.
#Set the aggperiod to the timeframe you want the zone to monitor.
#Add the study multiple times and set them to different aggperoids to montior multiple times.
input aggperiod = 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);
####### agg Label
#def aggperiod = AggregationPeriod.FIVE_MIN;
def highagg = high(period = aggperiod);
def lowagg = low(period = aggperiod);
def closeagg = close(period = aggperiod);
def HiLoagg = Min(highagg - lowagg, 1.5 * Average(highagg - lowagg, ATRPeriod));
def HRefagg = if lowagg <= highagg[1]
then highagg - closeagg[1]
else (highagg - closeagg[1]) - 0.5 * (lowagg - highagg[1]);
def LRefagg = if highagg >= lowagg[1]
then closeagg[1] - lowagg
else (closeagg[1] - lowagg) - 0.5 * (lowagg[1] - highagg);
def trueRangeagg;
switch (trailType) {
case modified:
trueRangeagg = Max(HiLoagg, Max(HRefagg, LRefagg));
case unmodified:
trueRangeagg = TrueRange(highagg, closeagg, lowagg);
}
def lossagg = ATRFactor * MovingAverage(averageType, trueRangeagg, ATRPeriod);
def stateagg = {default init, long, short};
def trailagg;
switch (stateagg[1]) {
case init:
if (!IsNaN(lossagg)) {
switch (firstTrade) {
case long:
stateagg = stateagg.long;
trailagg = closeagg - lossagg;
case short:
stateagg = stateagg.short;
trailagg = closeagg + lossagg;
}
} else {
stateagg = stateagg.init;
trailagg = Double.NaN;
}
case long:
if (closeagg > trailagg[1]) {
stateagg = stateagg.long;
trailagg = Max(trailagg[1], closeagg - lossagg);
} else {
stateagg = stateagg.short;
trailagg = closeagg + lossagg;
}
case short:
if (closeagg < trailagg[1]) {
stateagg = stateagg.short;
trailagg = Min(trailagg[1], closeagg + lossagg);
} else {
stateagg = stateagg.long;
trailagg = closeagg - lossagg;
}
}
def BuySignalagg = Crosses(stateagg == stateagg.long, 0, CrossingDirection.ABOVE);
def SellSignalagg = Crosses(stateagg == stateagg.short, 0, CrossingDirection.ABOVE);
def exagg = if BuySignalagg then highagg else if SellSignalagg then lowagg else if stateagg == stateagg.long then Max(exagg[1], highagg) else if stateagg == stateagg.short then Min(exagg[1], lowagg) else exagg[1];
def TrailingStop_agg = trailagg;
def f1_agg = exagg + (trailagg - exagg) * fib1Level / 100;
def f2_agg = exagg + (trailagg - exagg) * fib2Level / 100;
def f3_agg = exagg + (trailagg - exagg) * fib3Level / 100;
def l100_agg = trailagg + 0;
def Fib1_agg = f1_agg;
def Fib2_agg = f2_agg;
def Fib3_agg = f3_agg;
def bullAboveZone_agg = stateagg == stateagg.long and closeagg > Fib1_agg;
def bullZone2_agg = stateagg == stateagg.long and closeagg <= Fib1_agg and closeagg > Fib2_agg;
def bullZone3_agg = stateagg == stateagg.long and closeagg <= Fib2_agg and closeagg > Fib3_agg;
def bullZone4_agg = stateagg == stateagg.long and closeagg <= Fib3_agg and closeagg > TrailingStop_agg;
def bearZone2_agg = stateagg == stateagg.short and closeagg >= Fib1_agg and closeagg < Fib2_agg;
def bearZone3_agg = stateagg == stateagg.short and closeagg >= Fib2_agg and closeagg < Fib3_agg;
def bearZone4_agg = stateagg == stateagg.short and closeagg >= Fib3_agg and closeagg < TrailingStop_agg;
#def period = if aggperiod / 60000 < 60 then aggperiod / 60000 + "m" else aggperiod + "";
AddLabel(yes, concat(if aggperiod < 3600000 then aggperiod/60000 + "m" else if aggperiod < 86400000 then aggperiod/3600000 + "h" else if aggperiod < 604800000 then aggperiod/86400000 + "D" else if aggperiod < 2592000000 then aggperiod/604800000 + "Wk" else if aggperiod < 31536000000 then aggperiod/2592000000 + "Mo" else aggperiod/31536000000 + "Yr", if bullZone2_agg then ": ZONE 2" else if bullZone3_agg then ": ZONE 3" else if bullZone4_agg then ": ZONE 4" else if bearZone2_agg then ": ZONE 2" else if bearZone3_agg then ": ZONE 3" else if bearZone4_agg then ": ZONE 4" else ""), if stateagg == stateagg.long then Color.GREEN else Color.RED);
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Start a new thread and receive assistance from our community.
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.
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.