TradingView
JustUncleL
Jun 3, 2018 11:37 AM

[Autoview][BackTest]Dual MA Ribbons R0.12 by JustUncleL 

Ethereum / BitcoinBinance

描述

This is an implementation of a strategy based on two MA Ribbons, a Fast Ribbon and a Slow Ribbon. This strategy can be used on Normal candlestick charts or Renko charts (if you are familiar with them).

The strategy revolves around a pair of scripts: One to generate alerts signals for Autoview and one for Backtesting, to tune your settings.

The risk management options are performed within the script to set SL(StopLoss), TP(TargetProfit), TSL(Trailing Stop Loss) and TTP (Trailing Target Profit). The only requirement for Autoview is to Buy and Sell as directed by this script, no complicated syntax is required.

The Dual Ribbons are designed to capture the inferred behavior of traders and investors by using two groups of averages:
> Traders MA Ribbon: Lower MA and Upper MA (Aqua=Uptrend, Blue=downtrend, Gray=Neutral), with center line Avg MA (Orange dotted line).
> Investors MAs Ribbon: Lower MA and Upper MA (Green=Uptrend, Red=downtrend, Gray=Neutral), with center line Avg MA (Fuchsia dotted line).
> Anchor time frame (0=current). This is the time frame that the MAs are calculated for. This way 60m MA Ribbons can be viewed on a 15 min chart to establish tighter Stop Loss conditions.

Trade Management options:
  • Option to specify Backtest start and end time.
  • Trailing Stop, with Activate Level (as % of price) and Trailing Stop (as % of price)
  • Target Profit Level, (as % of price)
  • Stop Loss Level, (as % of price)
  • BUY green triangles and SELL dark red triangles
  • Trade Order closed colour coded Label:
  • >> Dark Red = Stop Loss Hit
  • >> Green = Target Profit Hit
  • >> Purple = Trailing Stop Hit
  • >> Orange = Opposite (Sell) Order Close


Trade Management Indication:
  • Trailing Stop Activate Price = Blue dotted line
  • Trailing Stop Price = Fuschia solid stepping line
  • Target Profit Price = Lime '+' line
  • Stop Loss Price = Red '+' line


Dealing With Renko Charts:
  • If you choose to use Renko charts, make sure you have enabled the "IS This a RENKO Chart" option, (I have not so far found a way to Detect the type of chart that is running).
  • If you want non-repainting Renko charts you MUST use TRADITIONAL Renko Bricks. This type of brick is fixed and will not change size.
  • Also use Renko bricks with WICKS DISABLED. Wicks are not part of Renko, the whole idea of using Renko bricks is not to see the wick noise.
  • Set you chart Time Frame to the lowest possible one that will build enough bricks to give a reasonable history, start at 1min TimeFrame. Renko bricks are not dependent on time, they represent a movement in price. But the chart candlestick data is used to create the bricks, so lower TF gives more accurate Brick creation.
  • You want to size your bricks to 2/1000 of the pair price, so for ETHBTC the price is say 0.0805 then your Renko Brick size should be about 2*0.0805/1000 = 0.0002 (round up).
  • You may find there is some slippage in value, but this can be accounted for in the Backtest by setting your commission a bit higher, for Binance for example I use 0.2%

    Special thanks goes to @CryptoRox for providing the initial Risk management Framework in his "How to automate this strategy for free using a chrome extension" example.

版本注释

Resolve some Issues
  • Resolve issue with Orange Close alerts not showing up in the TradingView alarm notifications when using Candlestick Charts.
  • Resolve issue with multiple Long/Short signals before Close by better use of the "tradeState" engine to keep control. This also made some of the Risk Management Code simpler.

版本注释

Update Docs, Redesigned TSL for easier reading

Trade Management options:

  • Option to specify a Strategy start and end time [BackTest] script only.
  • Trailing Stop Level, TSL (as % of price), activated on open trade
  • Target Profit Level, TP (as % of price)
  • Trailing Profit Level, TTP (as % of price below/above TP), activated on price passing TP Level
  • Stop Loss Level, SL (as % of price)
  • LONG green triangles and SHORT dark red triangles

Trade Order closed colour coded Labels:
> Dark Red = Stop Loss Hit
> Green = Target Profit Hit
> Purple = Trailing Stop Hit
> Orange = Opposite (Sell) Order Close

Trade Management Indication:
  • TSL = Fuschia solid stepping line
  • TP = Lime '+' line
  • TTP = Black solid stepping Line.
  • SL = Red '+' line

Dealing With Renko Charts:
  • If you choose to use Renko charts, make sure you have enabled the "IS This a RENKO Chart" option, (I have not so far found a way to Detect the type of chart is running).
  • If you want non-repainting Renko charts you MUST use TRADITIONAL Renko Bricks. This type of brick is fixed and will not change size.
  • Also use Renko bricks with WICKS DISABLED. Wicks are not part of Renko, the whole idea of using Renko bricks is not to see the wick noise.
  • Set you chart Time Frame to the lowest possible one that will build enough bricks to give a reasonable history, start at 1min TimeFrame. Renko bricks are not dependent on time, they represent a movement in price. But the chart candlestick data is used to create the bricks, so lower TF gives more accurate Brick creation.
  • You want to size your bricks to divide the pair price by 500, so for ETHBTC the price is say 0.0805 then your Renko Brick size should be about 0.0805/500 = 0.0002 (round up).
  • You may find there is some slippage in value, but this can be accounted for in the Backtest by setting your commission a bit higher, for example I use 0.2 or 0.3 for Binance.


NOTE: Most of my testing was conducted on Renko Charts, I do not have any optimized settings for normal Candlestick charts, I have left that for fellow Traders to discover.
评论
vinims
Thanks for all your work.
Btw, does this script repaint @JustUncleL ?
PonziTycoon
This doesn't work, you can no longer create alerts (which are needed for autoview to make trades) on renko charts. You almost got me though.
JustUncleL
@TelecomTycoon, It's up to the trader whether to use my any of my freely available scripts. However, this is the BackTest "strategy" version of the script and you cannot create alarms with it, you need to use the sister "study" version of the script to create alerts tradingview.com/script/byHd2CqX-Autoview-Alerts-Dual-MA-Ribbons-R0-12-by-JustUncleL/
maooam
select "use opposite trade as a close signal" stoploss function does not seem to work. Is this the intended function?

I'm learning so many things from your code.
Thank you always



p.s [hidden] I did not know if use " [] "message was hidden.
even know how to delete a comment. Sorry.
JustUncleL
@maooam, That should really be renamed to "Use Fast Exit to close Order". The intention was to close the trade when the median MA of the fast ribbon crosses the median MA of the slow ribbon, also this will also be set automatically to true if no SL condition is set as a fail safe.
maooam
I think "Use Fast Exit to close Order" it is more advantageous to use it, but the problem is high loss rate.
If I apply this option with stoploss, it will pass the real stop-loss section.
What parts need to be fixed to stop the actual stop loss or change to the opposite position ?
I think not enough explanation., so I attach a picture.

Please understand my ignorance.

<img src="cfile215.uf.daum.net/attach/99DEA6465BC16E320E6D50">
<img src="cfile211.uf.daum.net/attach/990A32465BC16E3A0B0813">
maooam
select the [use opposite trade as a close signal] the stoploss function does not seem to work.
Is this the intended function?

I'm learning so many things from your code.
Thank you always
ZAnanas
Hello JustUncleL,
Thanks again for sharing your great script !

I'm having trouble with renko strategy: if we have a signal, but the next candle goes in the opposite direction, the entry of our trade is drawn in at the Open of the new candle instead of the Close of the previous candle, which is where we would enter the trade.
For exemple a short strategy simply based on direction change between two following Renko bars :
condition=open[1] < close[1] and open > close
strategy.entry(id = "Short", long = false, when = condition)
strategy.close(id = "Short", when = close>open)

Here's a snapshot for illustration :

On renko #1 we notice a open < close, and on renko #2 a open > close, so entry condition is triggered as soon as renko #2 is closed.
The issue remain here : opening position price is the open of renko #3 (ie 1.30812) instead of closing of renko #2 (ie 1.30680).
Hence strategy tester rely on false price entry.

Unfortunately TV support ain't really helping on this issue so far. How would you advise to manage this error ?

Thanks for your help
JustUncleL
@ZAnanas, Unfortunately, that is the nature of Renko bricks on Trading view and most other platforms. I don't see any way around it other than waiting for at least two bricks to say there is a change in direction.
ZAnanas
@JustUncleL, I think problem remain the same, even waiting for a second brick : if this second is followed by new one in the opposite direction, the entry of the trade would still be wrong.
更多