CryptoRox

[AutoView] Automate it -Heiken Ashi, No pyramiding or repainting

Alerts on Heiken Ashi candles using a resolution and no repainting. This script was initially just a test script that lead to solving a few issues around repainting, and pyramiding.

Building scripts for automation has been tricky due to us being forced to use pyramiding and of course, finding all the things that caused charts to repaint when live trading vs back testing. Over the course of all these builds, we've successfully found ways around all the issues. So here they are, with an explanation.

Heiken Ashi candles, they used to cause repainting depending on how they were used, and of course, the alerts were not consistent and/or firing when they should've. To solve this, we added a resolution, and only use the previous HA candle in our strategy. This eliminates all repainting as the candle is complete and we're not trying to predict the future. This simultaneously eliminated all alert issues as long as you use "crossing down on condition".

No pyramiding, this is something that is built right into strategies and back testing. However, getting a study to do it for alerts and automation via AutoView was tricky. The solution: we get the time of the last long and the last short, down to the second. If the last long was more recent then the last short, then we will not open another long. It's actually a simple, almost face palm solution that should not have likely taken this long to figure out.

In playing around with both of these new solutions, I found that by simply acting on the previous 3 hour Heiken Ashi close, this strategy performs well across multiple markets. The only thing that you really need to play with is, where you'll take profit and cut your losses.

In this strategy you'll see that each order can potentially margin call on x200, or double according to my take profit and stop loss. It lacks some consistency and the drawdown is pretty heavy. Change the TP to 40 and SL to 20, suddenly you see a more consistent and steady incline. Take a 20 pip loss or a 40 pip win is much nicer in my books compared to tp 60 and sl 60.

Anyways, I hope these new solutions help the community in both making some extra cash and improving your own personal strategies.

As per the usual, feel free to contact me on here, or request an invite to our free private slack group by sending me your email.

Referral Tax:
AutoView, a Chrome Extension that allows for trade automation using TradingView alerts.
http://bit.ly/1OjeQr7

1Broker, used to automate your trades on commodities , stocks , forex , indices and more...
https://1broker.com/m/r.php?i=3228
Comment: Here is the alert script
HeikenAshi[1]
Comment: All orders are now being tracked in a Google Sheet for public viewing.

Since: 04/01/2016 05:01:00
Net Profit = 170 pips

Link for tracked statistics here:
http://bit.ly/1W48xxM
Remove from Favorite Scripts Add to Favorite Scripts
//@version=2
strategy("HeikenAshi[1]", title="Strategy", overlay=false, default_qty_value=100)

//Heiken Ashi Candles
Factor = 3
Pd = 7
isHA = input(true, "HA Candles", bool)

data = isHA ? heikenashi(tickerid) : tickerid
res = input("180", "Resolution", resolution)

o = security(data, res, open[1])
c = security(data, res, close[1])
h = security(data, res, low[1])
l = security(data, res, high[1])

long = c > o
short = c < o

last_long = long ? time : nz(last_long[1])
last_short = short ? time : nz(last_short[1])

long_signal = crossover(last_long, last_short)
short_signal = crossover(last_short, last_long)

strategy.entry("long", strategy.long, when=long_signal)
strategy.entry("short", strategy.short, when=short_signal)

TP = input(60) * 10 //+ 2
SL = input(60) * 10 //- 2
TS = input(0) * 10
CQ = 100

TPP = (TP > 0) ? TP : na
SLP = (SL > 0) ? SL : na
TSP = (TS > 0) ? TS : na

strategy.exit("Close Long", "long", qty_percent=CQ, profit=TPP, loss=SLP, trail_points=TSP)
strategy.exit("Close Short", "short", qty_percent=CQ, profit=TPP, loss=SLP, trail_points=TSP)
bingetrader
a year ago
Thanks for this CryptoRox! I know you worked long and hard on this, looking forward to trying it out and helping to improve it.
+2 Reply
TASAVANT
a year ago
Cant set the resolution to 4 hours and it looks that performance on the 1 min time frame improves using 3 hour period and above....
+1 Reply
CryptoRox PRO TASAVANT
a year ago
If you simply go into the code, on line 10 you can change the resolution from 180 to 240 to get the 4 hour candles. I'm not sure why TV limits the resolution like they do.
If you'd like to remove their restrictions, just change line 10 to
res = input("180", "Resolution")
this will give you a lot more freedom in the settings.
Reply
TASAVANT CryptoRox
a year ago
Thanks
Reply
TradeWithConfidence CryptoRox
4 months ago
Can we use a "60" resolution for a 1H?
Reply
Krsnadeva
11 months ago
Hello and thanks for your dedication!
I am having an issue with setting up my alerts to use with autoview, I understood I have to create an alert as clicking on the "clock" on the right side of the chart and hitting the plus sign, right? Mine tells me I can't create an alert for this type of chart, mine is setup as Heikin Ashi, 15 min .... Any help would be appreciated :)
Reply
Krsnadeva Krsnadeva
11 months ago
I was able to create the alert changing to regular candels, now .... is there a way to triger an alert on strategy.exit? since mine uses a TS of 5 pips and 1broker dont have TS.

tks again
Reply
CryptoRox PRO Krsnadeva
11 months ago
Sadly 1 broker does not have TS compatibility. There is going to be an AutoView update that'll allow it soon, but there's still an issue with TS on TradingView. Trailing Stops require tick by tick data, so using them in a back test will give inaccurate results. To use a Trailing Stop, you need to leave your chart open, and forward test (let it run) to see where a TS would actually trigger.
Hope that helps and makes sense, apologies for the delayed response.
Reply
Krsnadeva CryptoRox
11 months ago
Thank you! Yeah it makes sense ... So I am reworking it without the TS.

I already got the alerts to trigger the positions on 1broker, but it seem to give me a fixed TP/SL of 30 pips, actually 3, (USDJPY), I tried setting to sl=20 and sl=200, still same, Eventually I'll figure it out :)

And thanks again for sharing your expertise with us mere mortals!
Reply
CryptoRox PRO Krsnadeva
11 months ago
Thanks for the generous comments.
On USDJPY the SL might need you to keep adding some 0's to it as the price is so much different from the usual forex markets, or atleast that's my assumption lol. Just play around on a low leverage setup so you don't throw money away during your testing/setup phase.
Keep me posted on this.
Reply
Krsnadeva CryptoRox
11 months ago
Thanks CryptoRox, will do, still struggling a little with alerts not firing the order on 1broker, but thats part of the game :)

It seems that no meter the sl=XX I put I always get the same 30 SL and TP. So my orders on 1broker last just a few seconds.

http://i66.tinypic.com/13z04tw.jpg

http://i65.tinypic.com/2jdq9w.jpg
Thank again!
Reply
Krsnadeva Krsnadeva
11 months ago
Just an update .... seem that TP=4000 SL=2000 worked on USDJPY!

Yay! will keep testing n let you know :)
Reply
Krsnadeva Krsnadeva
11 months ago
http://i68.tinypic.com/30j066g.jpg

http://i68.tinypic.com/30j066g.jpg

So far ...
- on 1broker TP/SL should have four digits so for ex. SL=2000 is the "normal" 20 pips for USDJPY pair where we usually would put SL=20 on the alert message.

- The alert crossing down on 0.9 works well during backtest, this way on a 5 min chart the "down leg" of the indicator spike trigger happens on the same bar as the alert trigger, but on realtime it happens on the next candle, so it triggers the alert quite late (as indicated by the blue line on the attached image. That's on TV :)

I believe this issue would be minimized on a 1 min chart, but I cant seem to get any settings working for USDJPY on a 1 min :(

- While my TV chart is set to Heikin Ashi I cant create any alerts, I have to set it to regular candles, create the alert, and set it back to HA, that works.

This is a great tool, and I really want to get this working.

Reply
Krsnadeva Krsnadeva
11 months ago
Oh, regarding the late alert trigger, I tried using .9 crossing UP, greater then .9, those did not trigger the alert. only the crossing DOWN .9 seems to activate the alert.
Reply
CryptoRox PRO Krsnadeva
11 months ago
I like the effort and personal debugging you're doing :)
You have to keep your chart on regular candles in order to get the alerts. Heiken Ashi candles are ported in using the code, so though your chart is on regular candles, your indicators/script are using HA data.
As for the late orders, I'll have to check that out myself, it all usually syncs up.
Reply
Krsnadeva CryptoRox
11 months ago
Thanks KryptoRox!

Mmmm thanks for the tip, but the odd thing is that when I change to regular candles theres a huge difference on the strategy tester results ... for worse :(.

The way I see it, as of line 7 of your code, if I tick isHa it will read the "heikenashi(tickerid)" data no mater what right? So changing the actual chart type should not change anything on the strategy results, but noooo, it does.

When the chart is on HA, ticking or unticking the isHA option does not seem to change much.

I'll keep on it :)
Reply
CryptoRox PRO Krsnadeva
11 months ago
Using the actual Heiken Ashi chart gives misleading numbers as the opens of an HA candle are made up and do not depict actual prices. Almost all strategies look better on HA charts lol.

By turning HA on in the script using a regular candle chart, you get the actual entry and exit prices.
Reply
tickwatch PRO CryptoRox
9 months ago
Maybe I'm doing it wrong, but it seems that I get different strategy results (different trades in "list of trades") simply by changing the view of the candles from HA to regular candles. HA candles is selected in the strategy. It sounds like you're saying above that the script should be generating the same buy/sell alerts regardless of the candle type you are viewing.
Reply
CryptoRox PRO tickwatch
9 months ago
The signals should be the same, but the entry/exit prices will differ. HA candles uses an equation to create the open and closes, so the prices the strategy tester uses on them are not actual prices causing false results.
Reply
tickwatch PRO CryptoRox
9 months ago
Yes, it's great idea to use . Thanks for that tip! Trying to use this script specifically on /ES though it doesn't seem that TP/SL does anything. I adjusted default qty value to 1 from 100. I would think that "TP" of 5 would mean take profit after... 5 points, 5 ticks or something. But I could not find the correlation in actual performance and trades in the log.
Reply
tickwatch PRO tickwatch
9 months ago
great idea to use
Reply
tickwatch PRO tickwatch
9 months ago
The filtering is killing me here. Great idea to look back the as last completed close instead of the bar in progress.
Reply
CryptoRox PRO tickwatch
9 months ago
I am not sure what /ES is, but TP/SL are currently setup for forex markets, dividing your 5 by 10,000. Giving you 0.0005, so depending on the market you're trying, you can either adjust the code, or you may have to use 5,000 / 50,000 as an example. If you are still having some issues, send me a pm, or joing our slack group, someone in there is typically around and can give you a hand.
http://slack.crypto.pink/
Reply
Germaine_Mills Krsnadeva
8 months ago
Is this still valid
Reply
Is there any automating trading for MT4 and also I came across this page because I trying top fix a repainting issue on a strategy. Is there any way I can stop this repeating? Anyone Please! I'm trying to fix this strategy all I need to do now is fix the repainting issue and then I can share it to everyone!
Reply
CryptoRox PRO TradeWithConfidence
8 months ago
Unfortunately the only current integration is OKcoin and 1broker. We have looked into MT4, and though we hope to 1 day, it's a long way off.

Depending on the reason for your strategy repainting, the fix is easy. You can send me a pm and I can walk you through it.
Reply
Thank you so much for this beautiful information.

Sincerely,

Kevin Manrrique
Reply
How about h and l?
Reply
Ideas Scripts Chart
United States
United Kingdom
India
España
Italia
Brasil
Россия
Türkiye
日本
한국
Home Stock Screener Economic Calendar How It Works Chart Features House Rules Moderators For the WEB Widgets Stock Charting Library Priority Support Feature Request Blog & News FAQ Help & Wiki Twitter
Private Messages Chat Ideas Published Followers Following Priority Support Public Profile Profile Settings Billing Sign Out