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

Status
Not open for further replies.
Depending on the timeframe you use, I've added a 50 fib to the code because it tends to bounce off it as well.
 
@BenTen Do you know who is the best to help setup on mobile? Can he send me what he has for the setup in mobile phone?

I am trying to make it look like that on "red" & "green"
 
Seriously? You are trading with real money using a system you don't know how to use yet and lose 2,600, and the very next day you are still trading with real money? WTF?
Yes, as the strategies are all there. Getting slippage and stop loss getting jumped over are all things that unfortunately happen. Small trades dont suffer from it, larger positions do. The on demand is useless as I can in any single night make tens thousands there. I played around with that with actual funds I have in my trading accounts and its simply not accurate. Its good to practice and getting familiar with platform. Well at least thats all I got out of it. The executions are instant zero slippage and lets not forget the emotions.

That all being yes you are correct I should be more careful and am making constant adjustments. I get much better at a flaw I had and discover others along the way. I have to limit the amount of strategies and concentrate on a selected few on my watchlist. Appreciate the concern I really do. Believe me I am not trying to blowout again.
 
  • Like
Reactions: DDW
I have added upper fib zones and added colored clouds and fixed the labels to this indicator
===============================================================
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.



#-----------------------------------

#Modified 6/29/2020 by Henry Z Kaczmarczyk added upper fib zones, added upper clouds, fixed labels

#-----------------------------------

# 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 fib0Level = 0;

Input fib1Level = 11.4;

input fib2Level = 23.6;

input fib3Level = 38.2;

Input fib4Level = 50.0;

input fib5Level = 61.8;

input fib6Level = 78.6;

input fib7Level = 88.6;



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

Fib0.SetDefaultColor(Color.White);

Fib0.SetLineWeight(2);

plot Fib1 = f1;

Fib1.SetPaintingStrategy(PaintingStrategy.LINE);

Fib1.SetDefaultColor(Color.White);

Fib1.SetLineWeight(2);

plot Fib2 = f2;

Fib2.SetPaintingStrategy(PaintingStrategy.Line);

Fib2.SetDefaultColor(Color.White);

plot Fib3 = f3;

Fib3.SetPaintingStrategy(PaintingStrategy.Line);

Fib3.SetDefaultColor(Color.White);

Fib3.SetLineWeight(1);

plot Fib4 = f4;

Fib4.SetPaintingStrategy(PaintingStrategy.LINE);

Fib4.SetDefaultColor(Color.White);

Fib4.SetLineWeight(1);

plot Fib5 = f5;

Fib5.SetPaintingStrategy(PaintingStrategy.LINE);

Fib5.SetDefaultColor(Color.White);

Fib5.SetLineWeight(1);

plot Fib6 = f6;

Fib6.SetPaintingStrategy(PaintingStrategy.Line);

Fib6.SetDefaultColor(Color.White);

Fib6.SetLineWeight(2);

plot Fib7 = f7;

Fib7.SetPaintingStrategy(PaintingStrategy.Line);

Fib7.SetDefaultColor(Color.White);

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 atr = Average(TrueRange(high, close, low), 14);



plot LS1 = if l5 then low - atr else Double.NaN;

plot LS2 = if l6 then low - 1.5 * atr else Double.NaN;

plot LS3 = if l7 then low - 2 * atr else Double.NaN;

plot SS1 = if s5 then high + atr else Double.NaN;

plot SS2 = if s6 then high + 1.5 * atr else Double.NaN;

plot SS3 = if s7 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 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 ohlc4 > TrailingStop then "BUY SUPPORT - BUY ZONES 2,3 or 4" else "SELL RESISTANCE - SELL ZONES 2,3 or 4", if ohlc4 > TrailingStop then Color.GREEN else Color.Red);



AddLabel(yes," SWING TRADING STRATEGY : ",color.WHITE);

AddLabel(yes, if ohlc4 > TrailingStop then "* IF * SWINGARM Is BULLISH - Wait For Entry Confirmation" else "* IF * SWINGARM - Is BEARISH - Wait For Entry Confirmation", if ohlc4 > TrailingStop then Color.GREEN else Color.RED);

Here is the full version

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

# 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 trailType = {default modified, unmodified};
input ATRPeriod = 28;
input ATRFactor = 5;
input firstTrade = {default long, short};
input averageType = AverageType.WILDERS;

Input fib0Level = 0;
Input fib1Level = 11.4;
input fib2Level = 23.6;
input fib3Level = 38.2;
Input fib4Level = 50.0;
input fib5Level = 61.8;
input fib6Level = 78.6;
input fib7Level = 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 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.LINE);
Fib0.SetDefaultColor(Color.White);
Fib0.SetLineWeight(2);
plot Fib1 = f1;
Fib1.SetPaintingStrategy(PaintingStrategy.LINE);
Fib1.SetDefaultColor(Color.White);
Fib1.SetLineWeight(2);
plot Fib2 = f2;
Fib2.SetPaintingStrategy(PaintingStrategy.Line);
Fib2.SetDefaultColor(Color.White);
plot Fib3 = f3;
Fib3.SetPaintingStrategy(PaintingStrategy.Line);
Fib3.SetDefaultColor(Color.White);
Fib3.SetLineWeight(1);
plot Fib4 = f4;
Fib4.SetPaintingStrategy(PaintingStrategy.LINE);
Fib4.SetDefaultColor(Color.White);
Fib4.SetLineWeight(1);
plot Fib5 = f5;
Fib5.SetPaintingStrategy(PaintingStrategy.LINE);
Fib5.SetDefaultColor(Color.White);
Fib5.SetLineWeight(1);
plot Fib6 = f6;
Fib6.SetPaintingStrategy(PaintingStrategy.Line);
Fib6.SetDefaultColor(Color.White);
Fib6.SetLineWeight(2);
plot Fib7 = f7;
Fib7.SetPaintingStrategy(PaintingStrategy.Line);
Fib7.SetDefaultColor(Color.White);
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 atr = Average(TrueRange(high, close, low), 14);

plot LS1 = if l5 then low - atr else Double.NaN;
plot LS2 = if l6 then low - 1.5 * atr else Double.NaN;
plot LS3 = if l7 then low - 2 * atr else Double.NaN;
plot SS1 = if s5 then high + atr else Double.NaN;
plot SS2 = if s6 then high + 1.5 * atr else Double.NaN;
plot SS3 = if s7 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 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," DAY TRADING STRATEGY : ",color.WHITE);
AddLabel(yes, if ohlc4 > TrailingStop then "* IF * 5 Min. SWINGARM Is BULLISH - Buy 1 Min. Zone 4" else "* IF * 5 MIN. SWINGARM - Is BEARISH - Sell 1 Min Zone 4", if ohlc4 > TrailingStop then Color.GREEN else Color.Red);
AddLabel(yes, if ohlc4 > TrailingStop then "BUY SUPPORT - BUY ZONES 2,3 or 4" else "SELL RESISTANCE - SELL ZONES 2,3 or 4", if ohlc4 > TrailingStop then Color.GREEN else Color.Red);

AddLabel(yes," SWING TRADING STRATEGY : ",color.WHITE);
AddLabel(yes, if ohlc4 > TrailingStop then "* IF * SWINGARM Is BULLISH - Wait For Entry Confirmation" else "* IF * SWINGARM - Is BEARISH - Wait For Entry Confirmation", if ohlc4 > TrailingStop then Color.GREEN else Color.RED);
 
Last edited by a moderator:
Dear @dmaffo I am sorry to hear about your experience. Based on a $25k account, you overextended yourself in size to experience such as loss. You should not be trading live as I can see you are not ready for it. Stop trading live and figure this thing out before risking your capital. Watch the videos and do your homework. If not, I would rather you give the money to charity to be put to good use. Regards. ps, I do not mean to be harsh with you, it is just better to be direct.
 
Things look good from far away, but as you get closer, they look far from being good!
Better to do your homework than to flunk out!
 
I added a "Target" line fib to this indicator to give me a target when there is continuation of price movement in the same direction. In the indicator, I added a "n1" fib, for negative 1. The fib level is -27.2. I made it a yellow dashed line. I changed the color of the fib lines to suit my trading. In the screen shot, if the price does not retrace past the 61.8 yellow or the 50 green, then I expect continuation of price to hit the target of -27.2 target dashed yellow line. In this example, it occurs twice highlighted in yellow. This example is on the 4 min chart. But can be used on any time frame. Price could continue to move in the same direction even past the -27.2, but it gives me an initial target to hit. I added the below code in the appropriate spots within the code. See pic.

Input fibn1Level = -27.2;
def fn1 = ex + (trail - ex) * fibn1Level / 100;
plot Fibn1 = fn1;
Fibn1.SetPaintingStrategy(PaintingStrategy.dashes);
Fibn1.SetDefaultColor(Color.yellow);
Fibn1.SetLineWeight(2);

HhlOYMR.png
 
Here is another explanation of hitting the -27.2 target on Gold /GC on a 4 min chart. Price hits the 50 and then hits the target multiple times in a continuing trend. When price doesn't hit the target, it shows signs that a reversal is likely and in this case, a reversal did occur. If price doesn't reach the 50, then price has strength to go beyond the target which took place after the second time it hit the 50 and target. If price reaches well past the 50, then hitting the target is not as likely. Interesting stuff!

qMOL8LI.png
 
for some reason the alerts wont appear when price crosses any fib level. using this code below. is this one out of date?

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/27/2020
# Top Left Labels Wording for DayTrading

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

#-----------------------------------
#-----------------------------------
# BUY & SELL CONFIRMATION LABELS 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, DAILY 75 PERIOD.  "This settings are for futures"
#-----------------------------------
#-----------------------------------


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.Ring);
Alert(l2, "Price crossed below Fib2 level in long trend", Alert.BAR, Sound.Ring);
Alert(l3, "Price crossed below Fib3 level in long trend", Alert.BAR, Sound.Ring);
Alert(s1, "Price crossed above Fib1 level in short trend", Alert.BAR, Sound.Ring);
Alert(s2, "Price crossed above Fib2 level in short trend", Alert.BAR, Sound.Ring);
Alert(s3, "Price crossed above Fib3 level in short trend", Alert.BAR, Sound.Ring);
 
All, After I started using the SwingArm indicators, my TOS charts became very slow in loading different instruments and also getting lag in streaming data. Anyone else having this problem, and any suggestions to have this resolved ? Appreciate any suggestions/comments.
 
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
473 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