DEMA Crossover with Heikin-Ashi Candle Confirmation for ThinkorSwim

@hexis777 Try this code:

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
#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);

plot DEMA_green = demaCrossingOverGoingUp;
plot DEMA_red = demaCrossingOverGoingDown;
Dema_green.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DEMA_red.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_Down);

Scan for DEMA_green and DEMA_red.
 

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

@hexis777 Try this code:

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
#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);

plot DEMA_green = demaCrossingOverGoingUp;
plot DEMA_red = demaCrossingOverGoingDown;
Dema_green.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DEMA_red.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_Down);

Scan for DEMA_green and DEMA_red.
master @BenTen , it does not work, add this study 2 days ago and create a scan for 1H and 30M but it does not scan or alert the signal :(
 
@hexis777 How did you do it? Did you save the scanner as a watchlist and select the option to get alerted?
 
@hexis777 How did you do it? Did you save the scanner as a watchlist and select the option to get alerted?
yes bro,
1. I have saved the new study using script from post # 61 with the name ScanforDEMA_GreenAndDEMA_Red
2. I have created 2 scans of 1H and 30M using this script: ScanforDEMA_GreenAndDEMA_Red (). "DEMA_green" is true

but the system does not alert or inform when the required event occurs
 
Built up this DEMA Crossover strategy with Heikin-Ashi candle confirmation. Works best in Daily setup.

wLa2tbp.png


ThinkScript Code

Rich (BB 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]);

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);
Hi,

Thanks for this interesting strategy. It is possible to add sound alerts when buy/sell signals appear?

Thank you in advance,
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
510 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