Can someone please help me add alert to the code

rbalu1978

New member
Hello, thanks to everyone for sharing your expertise in this forum. Greatly appreciate the same.

I am using the below code which I took from user STB (that post is flagged for no more replies) for scalping futures. Thanks for the code. Is it possible to add an audio alert to the code? Can someone please help me.

https://usethinkscript.com/threads/...ntry-signals-for-thinkorswim.2365/#post-28235

###### TIME ######

input zoneStartAM = 830;
input zoneEndAM = 1130;
input zoneStartPM = 1230;
input zoneEndPM = 1500;
input zoneEndclose = 1509;
input type = {default NOTRADE, REVERSAL};
def highBar;
def lowBar;
def highBar2;
def lowBar2;

switch (type){
case NOTRADE:
highBar = if SecondsTillTime(zoneStartAM) <= 0 and SecondsTillTime(zoneEndAM) >= 0 then HighestAll(open) else Double.NaN;
lowBar = if SecondsTillTime(zoneStartAM) <= 0 and SecondsTillTime(zoneEndAM) >= 0 then LowestAll(close) else Double.NaN;
case REVERSAL:
lowBar = if SecondsTillTime(zoneStartAM) <= 0 and SecondsTillTime(zoneEndAM) >= 0 then HighestAll(open) else Double.NaN;
highBar = if SecondsTillTime(zoneStartAM) <= 0 and SecondsTillTime(zoneEndAM) >= 0 then LowestAll(close) else Double.NaN;
}

switch (type){
case NOTRADE:
highBar2 = if SecondsTillTime(zoneStartPM) <= 0 and SecondsTillTime(zoneEndPM) >= 0 then HighestAll(open) else Double.NaN;
lowBar2 = if SecondsTillTime(zoneStartPM) <= 0 and SecondsTillTime(zoneEndPM) >= 0 then LowestAll(close) else Double.NaN;
case REVERSAL:
lowBar2 = if SecondsTillTime(zoneStartPM) <= 0 and SecondsTillTime(zoneEndPM) >= 0 then HighestAll(open) else Double.NaN;
highBar2 = if SecondsTillTime(zoneStartPM) <= 0 and SecondsTillTime(zoneEndPM) >= 0 then LowestAll(close) else Double.NaN;
}



###### TIME END #####

def adspdl = low("$adspd");
def adspdh = high("$adspd");
def adspdc = close("$adspd");
def volspd = close("$volspd");

def HMA = MovingAverage(AverageType.HULL, close, 21);

input numDevDn = -2.0;
input numDevUp = 2.0;
input timeFrame = {default DAY, WEEK, MONTH};

def cap = getAggregationPeriod();
def errorInAggregation =
timeFrame == timeFrame.DAY and cap >= AggregationPeriod.WEEK or
timeFrame == timeFrame.WEEK and cap >= AggregationPeriod.MONTH;
assert(!errorInAggregation, "timeFrame should be not less than current chart aggregation period");

def yyyyMmDd = getYyyyMmDd();
def periodIndx;
switch (timeFrame) {
case DAY:
periodIndx = yyyyMmDd;
case WEEK:
periodIndx = Floor((daysFromDate(first(yyyyMmDd)) + getDayOfWeek(first(yyyyMmDd))) / 7);
case MONTH:
periodIndx = roundDown(yyyyMmDd / 100, 0);
}
def isPeriodRolled = compoundValue(1, periodIndx != periodIndx[1], yes);

def volumeSum;
def volumeVwapSum;
def volumeVwap2Sum;

if (isPeriodRolled) {
volumeSum = volume;
volumeVwapSum = volume * vwap;
volumeVwap2Sum = volume * Sqr(vwap);
} else {
volumeSum = compoundValue(1, volumeSum[1] + volume, volume);
volumeVwapSum = compoundValue(1, volumeVwapSum[1] + volume * vwap, volume * vwap);
volumeVwap2Sum = compoundValue(1, volumeVwap2Sum[1] + volume * Sqr(vwap), volume * Sqr(vwap));
}
def price = volumeVwapSum / volumeSum;
def deviation = Sqrt(Max(volumeVwap2Sum / volumeSum - Sqr(price), 0));

def VWAP = price;



AssignPriceColor(if adspdl < adspdl[1] && close < vwap && close< hma && volume > volume[1] then Color.RED else if adspdh > adspdh[1] && close > vwap && close > hma && volume>volume[1] then Color.GREEN else Color.GRAY);


####LONGS####

AddOrder(OrderType.BUY_TO_OPEN,secondsTillTime(zoneStartAM) <= 0 && secondsTillTime(zoneEndAM) >= 0 and adspdh > adspdh[1] && close > vwap && vwap>vwap[1]&& volume>volume[1] , name = "Buy open AM @"+open[-1], 1, Color.ORANGE, Color.green);

AddOrder(OrderType.BUY_TO_OPEN,secondsTillTime(zoneStartpM) <= 0 && secondsTillTime(zoneEndpM) >= 0 and adspdh > adspdh[1] && close > vwap && vwap>vwap[1]&& volume>volume[1] , name = "Buy open AM @"+open[-1], 1, Color.ORANGE, Color.green);



##SHORTS###

AddOrder(OrderType.sell_TO_OPEN,secondsTillTime(zoneStartAM) <= 0 && secondsTillTime(zoneEndAM) >= 0 and adspdl < adspdl[1] && close < vwap && vwap<vwap[1]&& volume>volume[1] , name = "Sell open AM @"+open[-1], 1, Color.ORANGE, Color.RED);

AddOrder(OrderType.sell_TO_OPEN,secondsTillTime(zoneStartpM) <= 0 && secondsTillTime(zoneEndpM) >= 0 and adspdl < adspdl[1] && close < vwap && volume>volume[1] , name = "Sell open PM @"+open[-1], 1, Color.ORANGE, Color.RED);

####Close orders######

addorder(orderType.SELL_TO_CLOSE, adspdh < adspdh[1], name = "Sell close @"+open[-1],1,color.orange, color.red);

addorder(orderType.buy_TO_CLOSE, adspdl > adspdl[1],name = "Buy close @"+open[-1],1,color.orange, color.red);

###Market close orders####

addorder(orderType.buy_TO_CLOSE, secondsTillTime(zoneEndclose) <= 0 , name = "Buy Market Close @"+open[-1],1,color.orange, color.red);

addorder(orderType.sell_TO_CLOSE, secondsTillTime(zoneEndclose) <= 0 , name = "Sell Market Close @"+open[-1],1,color.orange, color.red);
 
Last edited by a moderator:
Solution
Hello, thanks to everyone for sharing your expertise in this forum. Greatly appreciate the same.

I am using the below code which I took from user STB (that post is flagged for no more replies) for scalping futures. Thanks for the code. Is it possible to add an audio alert to the code? Can someone please help me.

https://usethinkscript.com/threads/...ntry-signals-for-thinkorswim.2365/#post-28235
@STB has not been seen for a while. As he is not available to provide support for his strategy, the thread has been closed.

Read more about strategy alerts:
https://usethinkscript.com/threads/strategy-alerts-in-thinkorswim.8711/
Hello, thanks to everyone for sharing your expertise in this forum. Greatly appreciate the same.

I am using the below code which I took from user STB (that post is flagged for no more replies) for scalping futures. Thanks for the code. Is it possible to add an audio alert to the code? Can someone please help me.

https://usethinkscript.com/threads/...ntry-signals-for-thinkorswim.2365/#post-28235
@STB has not been seen for a while. As he is not available to provide support for his strategy, the thread has been closed.

Read more about strategy alerts:
https://usethinkscript.com/threads/strategy-alerts-in-thinkorswim.8711/
 
Last edited:
Solution
I think the first step is to plot arrows for the trades...

I would think something like

def sell_TO_OPEN = secondsTillTime(zoneStartAM) <= 0 && secondsTillTime(zoneEndAM) >= 0 and adspdl < adspdl[1] && close < vwap && vwap<vwap[1]&& volume>volume[1];

sell_TO_OPEN.SetPaintingStrategy(PaintingStrategy.Arrow_Down);


I am not near my PC, so just copy pasted it. See if it works, then will have to inverse for long. Kindly share if you get it to work.
 
Last edited:

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
415 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