Deviation Scaled VWAP with Fractal Energy for ThinkorSwim

Assume you mean price. Not a fan of or use alerts but should be something like,
Alert(close crosses below DSVWAP, "", Alert.BAR, Sound.Bell);
Alert(close crosses above DSVWAP, "", Alert.BAR, Sound.Bell);
 
Assume you mean price. Not a fan of or use alerts but should be something like,
Alert(close crosses below DSVWAP, "", Alert.BAR, Sound.Bell);
Alert(close crosses above DSVWAP, "", Alert.BAR, Sound.Bell);
Great thank you
 
Assume you mean price. Not a fan of or use alerts but should be something like,
Alert(close crosses below DSVWAP, "", Alert.BAR, Sound.Bell);
Alert(close crosses above DSVWAP, "", Alert.BAR, Sound.Bell);
Ok great I’ll try it thank you
 
Be glad to try but please explain the problem better. Right now I have no idea what you mean. I added the alert to the study on my chart and see no difference.
 
When I added the alert I got errors idk maybe I did something wrong. I’ll see if I can fix. Thank you
 
When I added the alert I got errors idk maybe I did something wrong. I’ll see if I can fix. Thank you


@Billions This is actually a relatively simple fix, noticed you have been struggling with this so I have incorporated those alerts into the study for you. Here we go

Code:
# Deviation Scaled VWAP with Fractual Energy Coloring.
# Adapted from ToS DSMA
# Mobius FE added with two choices of coloring in the code,
# < > .5
# and > .618 between and below .382
#
# Horserider 12/1/2019

input length = 55;

def zeros = vwap - vwap[2];
def filter = reference EhlersSuperSmootherFilter(price = zeros, "cutoff length" = 0.5 * length);
def rms = Sqrt(Average(Sqr(filter), length));
def scaledFilter = filter / rms;
def alpha = 5 * AbsValue(scaledFilter) / length;
def deviationScaledVWAP = CompoundValue(1, alpha * vwap + (1 - alpha) * deviationScaledVWAP[1], vwap);

#Inputs:
input nFE = 8;#hint nFE: length for Fractal Energy calculation.
input AlertOn = no;
input Glength  = 13;
input betaDev =  8;
input data = close;

def w = (2 * Double.Pi / Glength);
def beta = (1 - Cos(w)) / (Power(1.414, 2.0 / betaDev) - 1 );
def alphafe = (-beta + Sqrt(beta * beta + 2 * beta));
def Go = Power(alphafe, 4) * open +
             4 * (1 – alphafe) * Go[1] – 6 * Power( 1 - alphafe, 2 ) * Go[2] +
             4 * Power( 1 - alphafe, 3 ) * Go[3] - Power( 1 - alphafe, 4 ) * Go[4];
def Gh = Power(alphafe, 4) * high +
             4 * (1 – alphafe) * Gh[1] – 6 * Power( 1 - alphafe, 2 ) * Gh[2] +
             4 * Power( 1 - alphafe, 3 ) * Gh[3] - Power( 1 - alphafe, 4 ) * Gh[4];
def Gl = Power(alphafe, 4) * low +
             4 * (1 – alphafe) * Gl[1] – 6 * Power( 1 - alphafe, 2 ) * Gl[2] +
             4 * Power( 1 - alphafe, 3 ) * Gl[3] - Power( 1 - alphafe, 4 ) * Gl[4];
def Gc = Power(alphafe, 4) * data +
             4 * (1 – alphafe) * Gc[1] – 6 * Power( 1 - alphafe, 2 ) * Gc[2] +
             4 * Power( 1 - alphafe, 3 ) * Gc[3] - Power( 1 - alphafe, 4 ) * Gc[4];
# Variables:
def o;
def h;
def l;
def c;
def CU1;
def CU2;
def CU;
def CD1;
def CD2;
def CD;
def L0;
def L1;
def L2;
def L3;

# Calculations
o = (Go + Gc[1]) / 2;
h = Max(Gh, Gc[1]);
l = Min(Gl, Gc[1]);
c = (o + h + l + Gc) / 4;
def gamma = Log(Sum((Max(Gh, Gc[1]) - Min(Gl, Gc[1])), nFE) /
        (Highest(Gh, nFE) - Lowest(Gl, nFE)))
            / Log(nFE);
L0 = (1 – gamma) * Gc + gamma * L0[1];
L1 = -gamma * L0 + L0[1] + gamma * L1[1];
L2 = -gamma * L1 + L1[1] + gamma * L2[1];
L3 = -gamma * L2 + L2[1] + gamma * L3[1];
if L0 >= L1
then {
    CU1 = L0 - L1;
    CD1 = 0;
} else {
    CD1 = L1 - L0;
    CU1 = 0;
}
if L1 >= L2
then {
    CU2 = CU1 + L1 - L2;
    CD2 = CD1;
} else {
    CD2 = CD1 + L2 - L1;
    CU2 = CU1;
}
if L2 >= L3
then {
    CU = CU2 + L2 - L3;
    CD = CD2;
} else {
    CU = CU2;
    CD = CD2 + L3 - L2;
}
plot DSVWAP = deviationScaledVWAP;
#DSVWAP.SetDefaultColor(GetColor(1));
#DSVWAP.DefineColor("Up", GetColor(1));
#DSVWAP.DefineColor("Down", GetColor(0));
#DSVWAP.AssignValueColor(if gamma < .5 then DSVWAP.Color("Down") else DSVWAP.Color("Up"));

DSVWAP.AssignValueColor(if gamma > .618  then Color.CYAN else if gamma < .382   then Color.MAGENTA else Color.WHite);

Alert(close crosses below DSVWAP, "", Alert.BAR, Sound.Ring);
Alert(close crosses above DSVWAP, "", Alert.BAR, Sound.Bell);
 
I have a vwap crossover I really like displays the average above and below

Code:
input length = 9;    #hint length: Moving Average period length.
input type = AverageType.EXPONENTIAL; #hint type: Moving Average type.

## rth is true if in regular trading hours else false.
def rth = RegularTradingStart(GetYYYYMMDD()) - GetTime() < 0 and RegularTradingEnd(GetYYYYMMDD()) - GetTime() > 0;

def volumeSum = if rth then CompoundValue(1, volumeSum[1] + volume, volume) else 0;

def volumeVwapSum = if rth then CompoundValue(1, volumeVwapSum[1] + volume * vwap, volume * vwap) else 0;

def volumeVwap2Sum = if rth then CompoundValue(1, volumeVwap2Sum[1] + volume * Sqr(vwap), volume * Sqr(vwap)) else 0;

def price = if volumeSum != 0 then volumeVwapSum / volumeSum else Double.NaN;

plot VWAP = if !isNaN(close) then price else if !isNaN(close[1]) then price[1] else Double.NaN;

plot Avg = MovingAverage(type, if rth then close else Double.NaN, length);

VWAP.setDefaultColor(Color.PLUM);
VWAP.HideBubble();
VWAP.HideTitle();
VWAP.SetLineWeight(2);

Avg.setDefaultColor(CreateColor(0, 192, 255));
Avg.HideBubble();
Avg.HideTitle();
Avg.SetLineWeight(1);

def entry = close;

AddVerticalLine(Avg crosses above VWAP, "", Color.GREEN, 3);
AddVerticalLine(Avg crosses below VWAP, "", Color.RED, 3);
 
***I have a different study I trade it on the 5 min this is what I have. Can I add it :
Code:
input price = hl2;

input superfast_length = 8;#5
input fast_length = 13;#8
input slow_length = 13;#13
input jawDisplace = -8;#-8
input teethDisplace = -5;#-5
input lipsDisplace = -3;#-3
input averageType = AverageType.WILDERS;

def mov_avg5 = MovingAverage(averageType, price[-lipsDisplace], superfast_length);
def mov_avg8 = MovingAverage(averageType, price[-teethDisplace], fast_length);
def mov_avg13 = MovingAverage(averageType, price[-jawDisplace], slow_length);

#moving averages

Plot Superfast = mov_avg5;
Superfast.SetLineWeight(2);
plot Fast = mov_avg8;
#Fast.SetStyle(Curve.short_DASH);
Fast.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Fast.SetLineWeight(3); 
plot Slow = mov_avg13;
Slow.SetLineWeight(2);

Superfast.SetDefaultColor(Color.GREEN);
Fast.SetDefaultColor(Color.RED);
Slow.SetDefaultColor(Color.BLUE);

DefineGlobalColor("Bullish", Color.BLUE);
DefineGlobalColor("Bearish", Color.MAGENTA);
AddCloud(Superfast, Fast, globalColor("Bullish"), globalColor("Bearish"));

def buy = mov_avg5 > mov_avg8 and mov_avg8 > mov_avg13 and low > mov_avg5;

def stopbuy = mov_avg5 <= mov_avg8;

def buynow = !buy[1] and buy;

def buysignal = CompoundValue(1, if buynow and !stopbuy then 1 else if buysignal[1]==1 and stopbuy then 0 else buysignal[1], 0);


plot Buy_Signal = buysignal[1] == 0 and buysignal==1;

Buy_signal.setpaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

Buy_signal.setdefaultColor(color.dark_GREEN);

Buy_signal.hidetitle();

#Alert(condition = buysignal[1] == 0 and buysignal == 1, text = "Buy Signal", sound = Sound.Bell, "alert type" = Alert.BAR);


plot Momentum_Down = buysignal[1] ==1 and buysignal==0;

Momentum_down.setpaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

Momentum_Down.setdefaultColor(color.yellow);

Momentum_down.hidetitle();

#Alert(condition = buysignal[1] == 1 and buysignal == 0, text = "Momentum_Down", sound = Sound.Bell, "alert type" = Alert.BAR);


def sell = mov_avg5 < mov_avg8 and mov_avg8 < mov_avg13 and high < mov_avg5;

def stopsell = mov_avg5 >= mov_avg8;

def sellnow = !sell[1] and sell;

def sellsignal = CompoundValue(1, if sellnow and !stopsell then 1 else if sellsignal[1]==1 and stopsell then 0 else sellsignal[1], 0);


Plot Sell_Signal = sellsignal[1] ==0 and sellsignal;

Sell_signal.setpaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_down);

sell_signal.setDefaultColor(color.red);

Sell_signal.hidetitle();

#Alert(condition = sellsignal[1] == 0 and sellsignal == 1, text = "Sell Signal", sound = Sound.Bell, "alert type" = Alert.BAR);


Plot Momentum_Up = sellsignal[1]==1 and sellSignal==0;

Momentum_up.setpaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_up);

Momentum_up.setDefaultColor(color.yellow);

Momentum_up.hidetitle();

#Alert(condition = sellsignal[1] == 1 and sellSignal == 0, text = "Momentum_Up", sound = Sound.Bell, "alert type" = Alert.BAR);


#plot Colorbars = if buysignal ==1 then 1 else if sellsignal ==1 then 2 else if buysignal ==0 or sellsignal==0 then 3 else 0;

#colorbars.hide();

#Colorbars.definecolor("Buy_Signal_Bars", color.dark_green);

#Colorbars.definecolor("Sell_Signal_Bars", color.red);

#Colorbars.definecolor("Neutral", color.yellow);

#AssignPriceColor(if Colorbars ==1 then colorbars.color("buy_signal_bars") else if colorbars ==2 then colorbars.color("Sell_Signal_bars") else  colorbars.color("neutral"));

#end
 
Unclear what you're asking - Re-articulate your request giving all pertinent details, that way it would provide all the background info to better assist you
 
@tomsk Sorry Im looking for an alert as to when the arrows show up example buy sell here is the scriptI appreciate any help:

input price = hl2;

input superfast_length = 8;#5
input fast_length = 13;#8
input slow_length = 13;#13
input jawDisplace = -8;#-8
input teethDisplace = -5;#-5
input lipsDisplace = -3;#-3
input averageType = AverageType.WILDERS;

def mov_avg5 = MovingAverage(averageType, price[-lipsDisplace], superfast_length);
def mov_avg8 = MovingAverage(averageType, price[-teethDisplace], fast_length);
def mov_avg13 = MovingAverage(averageType, price[-jawDisplace], slow_length);

#moving averages

Plot Superfast = mov_avg5;
Superfast.SetLineWeight(2);
plot Fast = mov_avg8;
#Fast.SetStyle(Curve.short_DASH);
Fast.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Fast.SetLineWeight(3);
plot Slow = mov_avg13;
Slow.SetLineWeight(2);

Superfast.SetDefaultColor(Color.GREEN);
Fast.SetDefaultColor(Color.RED);
Slow.SetDefaultColor(Color.BLUE);

DefineGlobalColor("Bullish", Color.BLUE);
DefineGlobalColor("Bearish", Color.MAGENTA);
AddCloud(Superfast, Fast, globalColor("Bullish"), globalColor("Bearish"));

def buy = mov_avg5 > mov_avg8 and mov_avg8 > mov_avg13 and low > mov_avg5;

def stopbuy = mov_avg5 <= mov_avg8;

def buynow = !buy[1] and buy;

def buysignal = CompoundValue(1, if buynow and !stopbuy then 1 else if buysignal[1]==1 and stopbuy then 0 else buysignal[1], 0);


plot Buy_Signal = buysignal[1] == 0 and buysignal==1;

Buy_signal.setpaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

Buy_signal.setdefaultColor(color.dark_GREEN);

Buy_signal.hidetitle();

#Alert(condition = buysignal[1] == 0 and buysignal == 1, text = "Buy Signal", sound = Sound.Bell, "alert type" = Alert.BAR);


plot Momentum_Down = buysignal[1] ==1 and buysignal==0;

Momentum_down.setpaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

Momentum_Down.setdefaultColor(color.yellow);

Momentum_down.hidetitle();

#Alert(condition = buysignal[1] == 1 and buysignal == 0, text = "Momentum_Down", sound = Sound.Bell, "alert type" = Alert.BAR);


def sell = mov_avg5 < mov_avg8 and mov_avg8 < mov_avg13 and high < mov_avg5;

def stopsell = mov_avg5 >= mov_avg8;

def sellnow = !sell[1] and sell;

def sellsignal = CompoundValue(1, if sellnow and !stopsell then 1 else if sellsignal[1]==1 and stopsell then 0 else sellsignal[1], 0);


Plot Sell_Signal = sellsignal[1] ==0 and sellsignal;

Sell_signal.setpaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_down);

sell_signal.setDefaultColor(color.red);

Sell_signal.hidetitle();

#Alert(condition = sellsignal[1] == 0 and sellsignal == 1, text = "Sell Signal", sound = Sound.Bell, "alert type" = Alert.BAR);


Plot Momentum_Up = sellsignal[1]==1 and sellSignal==0;

Momentum_up.setpaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_up);

Momentum_up.setDefaultColor(color.yellow);

Momentum_up.hidetitle();

#Alert(condition = sellsignal[1] == 1 and sellSignal == 0, text = "Momentum_Up", sound = Sound.Bell, "alert type" = Alert.BAR);


#plot Colorbars = if buysignal ==1 then 1 else if sellsignal ==1 then 2 else if buysignal ==0 or sellsignal==0 then 3 else 0;

#colorbars.hide();

#Colorbars.definecolor("Buy_Signal_Bars", color.dark_green);

#Colorbars.definecolor("Sell_Signal_Bars", color.red);

#Colorbars.definecolor("Neutral", color.yellow);

#AssignPriceColor(if Colorbars ==1 then colorbars.color("buy_signal_bars") else if colorbars ==2 then colorbars.color("Sell_Signal_bars") else colorbars.color("neutral"));

#end
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
512 Online
Create Post

Similar threads

Similar threads

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