TradingView
sonnyparlin
2021년 10월 29일 오후 10시 53분

OBV MA Strategy 

Ethereum / TetherUSBinance

설명

The On Balance Volume + Moving Average Strategy

Parameters: 1H candles, ETHUSDT on BINANCEUS, commission percent uses Binance's maker/taker fees of 0.075%
Strategy: I create a 30 day moving average of the On Balance Volume "obvSma = ta.sma(ta.obv, 30)." Then I use the following buy conditions:

  • OBV crosses above the OBV moving average
  • The obv drops x% below the OBV moving average (buy a dip)
  • The OBV moving average is rising, the OBV is greater than the OBV moving average and the OBV is rising


The first buy condition is attempting to buy into an uptrend. When the OBV rises above the OBV moving average, people are buying and it's a good time to enter the trade.
The idea behind the second buy condition is to buy a dip so make sure you are careful to not set it too shallow or you'll end up buying the dip before the dip before the dip. :) I recommend 10% or more.
The third buy condition is there in case our trailing stop takes us out of a trade but the trend is still rising, we don't want to miss out on that profit so if the OBV is above the OBV moving average, the average is rising and the OBV is rising, we are likely in the middle of an uptrend and we should buy in.

릴리즈 노트

Changed some default parameters for the chart and also updated a variable name to be more clear.

`takeProfit` is now `activation`

I initially called it takeProfit because I tend to keep my trailing stop loss very tight so that if the candle hits the activation level but then starts to fall, the trailing stop will activate. The downside of this is that you end up missing opportunities, but overall, you see much more profit with a tighter trailing stop. The trick is to set your activation level to where you're happy taking profit. Setting it too low produces less profit, setting it too high wins you less trades. I tend to keep my activation level anywhere between 0.5% and 2% depending on the asset.

릴리즈 노트

Added user configurable moving average length for the OBV moving average.

릴리즈 노트

Removed
코멘트
juiida
Here you are using trail_offset=ticks, which leads to unreal backtest data..
sonnyparlin
@juiida, According to the pinescript manual trail_offset only takes ticks as an argument.
sonnyparlin
from the docs:

trail_offset (float) An optional parameter. Trailing stop price (specified in ticks). The offset in ticks to determine initial price of the trailing stop order: X ticks lower than 'trail_price' or 'trail_points' to exit long position; X ticks higher than 'trail_price' or 'trail_points' to exit short position. The default value is 'NaN'.
juiida
@sonnyparlin, first is that, inside bar you will never know what's was going on, using trail_offset=ticks, you will never know does it repainting or not. so backtest will be unreal
juiida
@sonnyparlin, Second thing, pine docs itself says - Strategies using calc_on_every_tick=true. A strategy with parameter calc_on_every_tick = false may also be prone to repainting, but to a lesser degree. Here you not even declare calc_on_every_tick=true or false, which tends to more false results on trailing stop loss
sonnyparlin
@juiida, good idea, I hadn't thought to set that parameter. I'll look into that. Fyi I've only been writing pine script for like a month or two so I never claimed to be an expert.
sonnyparlin
@juiida, as soon as I get an opportunity to sit back down with this I'll try setting calc_on_every_tick to true and see if that gives more realistic results.
sonnyparlin
@juiida, I tried setting calc_on_every_tick to true and it didn't change the results of the back test, so I'm not really sure what else I can do to get a more realistic backtest.
juiida
@sonnyparlin, Have you test with real money/trade with this code??
sonnyparlin
@juiida, I'm using this strategy currently in dry run mode on Freqtrade with very good results, but it's only been a couple of days. I don't like using tradingview alerts to trigger trades, so I use tradingview to develop strategies then test them with freqtrade.
더보기