ThinkScript help with HMA alert message - futures io
futures io

ThinkScript help with HMA alert message

Discussion in ThinkOrSwim

    1. trending_up 1,329 views
    2. thumb_up 3 thanks given
    3. group 2 followers
    1. forum 2 posts
    2. attach_file 1 attachments

Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

Search this Thread

ThinkScript help with HMA alert message

(login for full post details)
  #1 (permalink)
ny, ny/us
Posts: 3 since Aug 2019
Thanks: 1 given, 0 received

Good morning forum,
Below is a script that I added an alert that is triggering a buy & sell message at the same time whenever I open a chart which to me doesn't make sense...I thought that the condition would only look at the last met condition and trigger a buy or sell message.


declare upper;

input price = CLOSE;
input HMA_Length = 8;
input lookback = 2;
input labels=no;

plot HMA = HullMovingAvg(price = price, length = HMA_Length);

def delta = HMA[1] - HMA[lookback + 1];
def delta_per_bar = delta / lookback;

def next_bar = HMA[1] + delta_per_bar;

def concavity = if HMA > next_bar then 1 else -1;

plot turning_point = if concavity[1] != concavity then HMA else double.nan;

HMA.AssignValueColor(Color = if concavity[1] == -1 then
if HMA > HMA[1] then else else
if HMA < HMA[1] then color.yellow else;


turning_point.SetPaintingStrategy(paintingStrategy = PaintingStrategy.POINTS);

plot MA_Max = if HMA[-1] < HMA and HMA > HMA[1] then HMA else Double.NaN;

plot MA_Min = if HMA[-1] > HMA and HMA < HMA[1] then HMA else Double.Nan;

plot sell = if turning_point and concavity == -1 then high else double.nan;

plot buy = if turning_point and concavity == 1 then low else double.nan;

def ROC = HMA - next_bar;

addLabel(yes and labels, concat("ROC: " , ROC), color = if concavity < 0 then if ROC[1] > ROC then else else if ROC[1] < ROC then else;

def arrow_plots = high-low;
def plothigh = high + arrow_plots * 0.3;
def plotlow = low - arrow_plots * 0.3;

plot arrowUP = if MA_Min then plotlow else double.nan;

plot arrowdown = if MA_Max then plothigh else double.nan;

def condition1 = if isnan(HMA[-1] > HMA and HMA < HMA[1]) then 1 else 0;
def condition2 = if isnan(HMA[-1] < HMA and HMA > HMA[1]) then 1 else 0;

Alert(condition1, "MA Min Buy", Alert.Bar, Sound.Chimes);
Alert(condition2, "MA Max Sell", Alert.Bar, Sound.Chimes);

Reply With Quote

Can you help answer these questions
from other members on futures io?
Advice on SetBreakeven Exit on daily bars
Order cumulation
Alternative to Mcginley Dynamic MA
Sierra Chart
ACSIL and "Add Symbol Study"
Sierra Chart
Tradestation 10 work offline
Best Threads (Most Thanked)
in the last 7 days on futures io
Vinny E-Mini & Algobox Review TRADE ROOM
268 thanks
59 thanks
Would you share your Holy Grail?
58 thanks
Spoo-nalysis ES e-mini futures S&P 500
47 thanks
24 thanks
(login for full post details)
  #2 (permalink)
Posts: 28 since Aug 2018
Thanks: 20 given, 44 received

zentrader618 View Post
def condition1 = if isnan(HMA[-1] > HMA and HMA < HMA[1]) then 1 else 0;
def condition2 = if isnan(HMA[-1] < HMA and HMA > HMA[1]) then 1 else 0;

Looks like the bug is that condition1 and condition2 are always true. I haven't programmed in ThinkScript what does HMA[-1] mean in this context?

I assume HMA is the current value, same as HMA[0] and HMA[1] is the previous value, is HMA[-1] the value in the next time period? If that's the case the next time period does not yet exist at the moment you load the chart so isnan always returns true, which results in the bug you're experiencing.

Reply With Quote
The following 3 users say Thank You to ivoTrades for this post:
(login for full post details)
  #3 (permalink)
ny, ny/us
Posts: 3 since Aug 2019
Thanks: 1 given, 0 received

Hi there ivoTrades,

You are correct in that HMA[-1] is the next bar. Thanks for the comment about isnan. I will do more research on how to correct that.

Attached Thumbnails
Click image for larger version

Name:	image_333.png
Views:	54
Size:	20.7 KB
ID:	306531  
Reply With Quote

futures io Trading Community Platforms and Indicators ThinkOrSwim > ThinkScript help with HMA alert message

Last Updated on November 15, 2020

Upcoming Webinars and Events

NinjaTrader Indicator Challenge!


Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada),
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts