DEMA Crossover with Heikin-Ashi Candle Confirmation for ThinkorSwim

I ported this over to Easylanguage for Tradestation - I didn't know that TOS didn't have autotrading. Either way... strategy still holds up in Tradestation going forward testing for futures. Equities might be harder since there can be a lot of overnight movement. Weekends are the mostly the only issue with Futures.


Anyway you could share the tradestation code for this strategy? Thank you
 
Please use the DEMA_HA code with caution - the way it is built gives an advantage in the back-test that is very difficult to repeat in live trading. The three lines of code that cause an issue in my view are:

def demaCrossingOverGoingUp = demaSlow < demaFast and demaSlow[-1] > demaFast[-1];

AddOrder(OrderType.SELL_AUTO, sell equals 1, open, 100, Color.RED, Color.RED, "Sell @" + open);
AddOrder(OrderType.BUY_AUTO, buy equals 1, open, 100, Color.GREEN, Color.GREEN, "Buy @" + open);

I tested with 8 tick Range Bars with over 5000 trades and then did an Out of Sample test. With this code I could not repeat the back-test results because many of the entries could not be made as signaled with this code.

Made a few changes in the code.

def demaSlow = DEMA(close, 8);#8
def demaFast = DEMA(close, 21);#21
plot demaFastlt = DEMA(close, 50);#50
demaFastlt.SetLineWeight(2);
plot demaFastvlt = DEMA(close, 200);#200
demaFastvlt.SetLineWeight(4);

def HAclose = ohlc4;
def HAopen = CompoundValue(1,(HAopen[1] + HAclose[1]) / 2,
(open[1] + close[1]) / 2);
def HAhigh = Max(Max(high, HAopen), HAclose);
def HAlow = Min(Min(low, HAopen), HAclose);

def demaCrossingOverGoingDown = demaSlow[1] > demaFast[1] and demaSlow < demaFast;
def demaCrossingOverGoingUp = demaSlow < demaFast and demaSlow[-1] > demaFast[-1];

def HARed = HAOpen > HAclose;
def HAGreen = !HARed;
def HADecidedRed = HARed and HAHigh == HAopen;
def HADecidedGreen = HAGreen and HAlow == HAOpen;

######################################################################################
######################################################################################

#def sellsignal = demaCrossingOverGoingDown and (HADecidedRed or HADecidedRed[1] or HADecidedRed[2]);
def sellsignal = demaCrossingOverGoingDown and close < demaFastlt and (HADecidedRed or HADecidedRed[1] or HADecidedRed[2]);

#def buysignal = demaCrossingOverGoingUp and (HADecidedGreen or HADecidedGreen[1] or HADecidedGreen[2]);
def buysignal = demaCrossingOverGoingUp and close > demaFastlt and (HADecidedGreen or HADecidedGreen[1] or HADecidedGreen[2]);

#When testing need to turn the comment "" off
AddOrder(OrderType.SELL_AUTO, sellsignal equals 1, close, 1, Color.RED, Color.RED, "DEMA Sell @" + close);
AddOrder(OrderType.BUY_AUTO, buysignal equals 1, close[-1], 1, Color.GREEN, Color.GREEN, "DEMA Buy @" + close);

#AddVerticalLine(close crosses demaFastvlt, close, Color.yellow, Curve.SHORT_DASH);
#AddVerticalLine(buysignal, close, Color.GREEN, Curve.SHORT_DASH);

AddChartBubble(demaCrossingOverGoingUp, low,"DEMA HA",Color.dark_green);
AddChartBubble(demaCrossingOverGoingDown, high,"DEMA HA",Color.dark_red);

#Alert
def alerttrigger1 = buysignal;
def alerttrigger2 = sellsignal;

input alerttext1 = " ++++++++++ DEMA + HA +++++++++++ ";
input alerttext2 = " ---------- DEMA - HA ---------- ";
input UseAlerts = {false, default true};
input AlertType = {default "BAR", "ONCE", "TICK"};

def at = AlertType;

input AlertSound = {"Chimes", "Bell", default "Ring", "NoSound", "Ding"};

Alert (alerttrigger1 and UseAlerts, alerttext1, if at == 1 then Alert.ONCE else if at == 2 then Alert.TICK else Alert.BAR, AlertSound);

Alert (alerttrigger2 and UseAlerts, alerttext2, if at == 1 then Alert.ONCE else if at == 2 then Alert.TICK else Alert.BAR, AlertSound);
---
Hi my friend. Please, Where can I find this script to use it in the TOS Scanner tool to search for Stocks that have the indicator (DEMA HA) shown in the study to perform Call operations?
Thanks
 
@harber09 The script provided in this thread is a backtesting strategy; here is the modified version of it to be used as an indicator. I added the buy and sell arrows to help you scan for signals.

Code:
def demaSlow = DEMA(close, 8);
def demaFast = DEMA(close, 21);

def HAclose = ohlc4;
def HAopen = CompoundValue(1,(HAopen[1] + HAclose[1]) / 2,
(open[1] + close[1]) / 2);
def HAhigh = Max(Max(high, HAopen), HAclose);
def HAlow = Min(Min(low, HAopen), HAclose);

def demaCrossingOverGoingDown = demaSlow[1] > demaFast[1] and demaSlow < demaFast;
def demaCrossingOverGoingUp = demaSlow < demaFast and demaSlow[-1] > demaFast[-1];

def HARed = HAOpen > HAclose;
def HAGreen = !HARed;
def HADecidedRed = HARed and HAHigh == HAopen;
def HADecidedGreen = HAGreen and HAlow == HAOpen;

def sell = demaCrossingOverGoingDown and (HADecidedRed or HADecidedRed[1] or HADecidedRed[2]);

def buy = demaCrossingOverGoingUp and (HADecidedGreen or HADecidedGreen[1] or HADecidedGreen[2]);

# Plot Confirmed Signals
plot bullish = buy;
bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bullish.SetDefaultColor(Color.CYAN);
bullish.SetLineWeight(1);
plot bearish = sell;
bearish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
bearish.SetDefaultColor(Color.MAGENTA);
bearish.SetLineWeight(1);
 
Hello,
How could I apply the code to work in my whatchlist and/or make a sound when a buy or sell happens?
Thank you!

Can I save it as a study and use auto buy condition to execute automatically?
Thanks
 
Hi! I was just looking for some clarity regarding the DEMA + HA strategy posted here:

The [-1] bars for the going up signal is throwing me off. Does that mean it is looking into the future to create the signal? but the going down seems normal. Would that cause a delay in the signal?

Thank you so much for your time!
 
  • Like
Reactions: ALF
@BenTen Sometimes I am not seeing Bullish Signal though the candle looks green and price go up. Is this fully tested? Can you please confirm.
 
@csrkk Do you have an example? If so, please post a screenshot of it. That way I can investigate.

@hexis777 Use the code from message #45 and scan for the up/down arrows.
hi my friend, thanks for your help., Comparing the strategy script in message #19, the position "DEMA HA" Bubble is different or not displayed using the script in message #45. Could you please create a scan script based on the script from message #19.
Thank you so much

Using script in Message #19 (is very good)
Script-using-Message-19.png


Using script in Message #45
Script-using-Message-45.png
 
@hexis777 Here is the modified code based on the script from message #19. I added up and down arrows so you can use it with the scanner.

Code:
def demaSlow = DEMA(close, 8);#8
def demaFast = DEMA(close, 21);#21
plot demaFastlt = DEMA(close, 50);#50
demaFastlt.SetLineWeight(2);
plot demaFastvlt = DEMA(close, 200);#200
demaFastvlt.SetLineWeight(4);

def HAclose = ohlc4;
def HAopen = CompoundValue(1,(HAopen[1] + HAclose[1]) / 2,
(open[1] + close[1]) / 2);
def HAhigh = Max(Max(high, HAopen), HAclose);
def HAlow = Min(Min(low, HAopen), HAclose);

def demaCrossingOverGoingDown = demaSlow[1] > demaFast[1] and demaSlow < demaFast;
def demaCrossingOverGoingUp = demaSlow < demaFast and demaSlow[-1] > demaFast[-1];

def HARed = HAOpen > HAclose;
def HAGreen = !HARed;
def HADecidedRed = HARed and HAHigh == HAopen;
def HADecidedGreen = HAGreen and HAlow == HAOpen;

######################################################################################
######################################################################################

#def sellsignal = demaCrossingOverGoingDown and (HADecidedRed or HADecidedRed[1] or HADecidedRed[2]);
def sellsignal = demaCrossingOverGoingDown and close < demaFastlt and (HADecidedRed or HADecidedRed[1] or HADecidedRed[2]);

#def buysignal = demaCrossingOverGoingUp and (HADecidedGreen or HADecidedGreen[1] or HADecidedGreen[2]);
def buysignal = demaCrossingOverGoingUp and close > demaFastlt and (HADecidedGreen or HADecidedGreen[1] or HADecidedGreen[2]);

#AddVerticalLine(close crosses demaFastvlt, close, Color.yellow, Curve.SHORT_DASH);
#AddVerticalLine(buysignal, close, Color.GREEN, Curve.SHORT_DASH);

AddChartBubble(demaCrossingOverGoingUp, low,"DEMA HA",Color.dark_green);
AddChartBubble(demaCrossingOverGoingDown, high,"DEMA HA",Color.dark_red);

#Alert
def alerttrigger1 = buysignal;
def alerttrigger2 = sellsignal;

input alerttext1 = " ++++++++++ DEMA + HA +++++++++++ ";
input alerttext2 = " ---------- DEMA - HA ---------- ";
input UseAlerts = {false, default true};
input AlertType = {default "BAR", "ONCE", "TICK"};

def at = AlertType;

input AlertSound = {"Chimes", "Bell", default "Ring", "NoSound", "Ding"};

Alert (alerttrigger1 and UseAlerts, alerttext1, if at == 1 then Alert.ONCE else if at == 2 then Alert.TICK else Alert.BAR, AlertSound);

Alert (alerttrigger2 and UseAlerts, alerttext2, if at == 1 then Alert.ONCE else if at == 2 then Alert.TICK else Alert.BAR, AlertSound);

# Plot Signals
plot bullish = demaCrossingOverGoingUp;
bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bullish.SetDefaultColor(Color.CYAN);
bullish.SetLineWeight(1);
plot bearish = demaCrossingOverGoingDown;
bearish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
bearish.SetDefaultColor(Color.MAGENTA);
bearish.SetLineWeight(1);
 
@hexis777 I assume you are referring to the script I posted in message #54. If so, watch the video from this thread. Scan for bullish signals.
Hi master, the script from message # 54 works fine to only search for arrows pointing up., But what I would like please is to search for the value "DEMA Buy @ ..." which cannot be done with the script from message # 54
Thanks ,)
 

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