CryptoRox

[AutoView] Trailing Stop Back Testing and alerts + TP and TS

1595 9 85
The number one request since the creation of autoview was to have alerts triggered for Take Profit, Stop Loss and Trailing Stops. Finally, we've figured it out, and as an additional bonus, this allows us to back test trailing stops in the strategy tester.

YouTube Video about this script and setup: http://bit.ly/1S48a7z

This script contains 2 things people have been asking for, multiple time frames and of course, a trailing stop that can be both back tested and setup for alerts.

This strategy itself seems to perform better without the use of the Trailing Stop, so play around and monitor it before actually trying to trade it live.
View all the trades being tracked in a Google             Sheets here: http://bit.ly/1nI65Bj

To learn more about back testing strategies, automation and AutoView join our free slack group via http://slack.crypto.pink/


Referral Tax:
This requires 4 alerts, so you are going to have to upgrade to PRO. It'd be greatly appreciated if you signed up using our referral link.
http://bit.ly/1ZXbBS1

1Broker
http://bit.ly/1XvAV0c

okcoin
http://bit.ly/1OU13x2
Remove from Favorite Scripts Add to Favorite Scripts
//@version=2
strategy("Public TS - FX", shorttitle="Strategy", overlay=false, default_qty_value=100)

ts = input(5, "Trailing Stop") / 10000

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

data = isHA ? heikenashi(tickerid) : tickerid

r1 = input("3", "Resolution", resolution)
r2 = input("5", "Resolution", resolution)
r3 = input("15", "Resolution", resolution)
r4 = input("30", "Resolution", resolution)

o1 = security(data, r1, open[1])
c1= security(data, r1, close[1])
o2 = security(data, r2, open[1])
c2 = security(data, r2, close[1])
o3 = security(data, r3, open[1])
c3 = security(data, r3, close[1])
o4 = security(data, r4, open[1])
c4 = security(data, r4, close[1])

long = o4 < c4 and o3 < c3 and o2 < c2 and o1 < c1
short = o4 > c4 and o3 > c3 and o2 > c2 and o1 > c1

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

in_long = last_long > last_short
in_short = last_short > last_long

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

last_open_long = long ? open : nz(last_open_long[1])
last_open_short = short ? open : nz(last_open_short[1])

last_high = not in_long ? na : in_long and (na(last_high[1]) or high > nz(last_high[1])) ? high : nz(last_high[1])
last_low = not in_short ? na : in_short and (na(last_low[1]) or low < nz(last_low[1])) ? low : nz(last_low[1])

long_ts = not na(last_high) and close <= (last_high - ts)
short_ts = not na(last_low) and close >= (last_low + ts)

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

strategy.close("Long", when=long_ts)
strategy.close("Short", when=short_ts)

price  = close[1]
noleverage = price / 100
leverage = 10 // noleverage * 4

TP = input(0) * leverage
SL = input(42, maxval=200) * leverage
TS = input(0) * leverage
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)
zelibobla
3 months ago
This strategy rely on future data (repaints) and can not be used in real life. Please vote up for fixing this issue: https://getsatisfaction.com/tradingview/topics/strategies-and-indicators-are-repainting
Reply
CryptoRox PRO zelibobla
3 months ago
This strategy does not repaint... Please learn the language and things that cause repainting before you go around spamming charts.

It relies on higher time frame candles yes, but it uses the LAST candle, therefore not relying on future data.
Reply
CryptoRox PRO CryptoRox
3 months ago
Don't get me wrong, I appreciate the attention you're bringing to this issue. But you really should understand the issue AND the work around hacks before posting on other peoples published charts.
Reply
zelibobla CryptoRox
3 months ago
Heikin Ashi you used in your example are the source of repaint in your case.

Here is the description: «yes its Heikin Ashi Close price which is calculatet by OHLC/4 of current bar. TradingView recalculate this price at close of the 180mn Heikin Ashi bar. Thats why its repainting».
Heikin-Ashi Strategy V1 by breizh29


Please pinpoint what language and thing should I learn more.
Reply
CryptoRox PRO zelibobla
3 months ago
Pine.
In line 18 - 25, when I call the Heiken Ashi candle, I call the previous candle that has already completed.

I am going to load this chart and run it while I'm at work, as it's been awhile since I've written anything with HA. But I'm pretty sure that this uses the previous HA candle avoiding all repainting.
Reply
zelibobla CryptoRox
3 months ago
And what about 42 - 46 line where you get current HA candle high, low and close formula of which contains current close, which is exactly data from future, mentioned in post I linked previously?
Reply
CryptoRox PRO zelibobla
3 months ago
This is NOT on a Heiken Ashi chart. Lines 42-46 are pulling in the high/low from regular candles.
Reply
zelibobla CryptoRox
3 months ago
You're right man. I am sorry
+1 Reply
CryptoRox PRO zelibobla
3 months ago
I respect you for both what you're doing by spreading the word about repainting, and being able to acknowledge your misunderstanding here.
Keep doing what you're doing.
+1 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