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.
AutoView, a Chrome Extension that allows for trade automation using TradingView alerts.
1Broker, used to automate your trades on , stocks, forex, indices and more...
Since: 04/01/2016 05:01:00
Net Profit = 170 pips
Link for tracked statistics here:
//@version=2 strategy("HeikenAshi", 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) c = security(data, res, close) h = security(data, res, low) l = security(data, res, high) long = c > o short = c < o last_long = long ? time : nz(last_long) last_short = short ? time : nz(last_short) 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)
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.
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 :)
Hope that helps and makes sense, apologies for the delayed response.
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!
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.
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.
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.
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.
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 :)