TradingView
conflixx95493
29 mar 2021 15:46

Bollinger Bands Trending Reverse Strategy 

SOL / TetherUSBinance

Descrizione

Welcome to yet another script. This script was a lot easier since I was stuck for so long on the Donchian Channels one and learned so much from that one that I could use in this one.
This code should be a lot cleaner compared to the Donchian Channels, but we'll leave that up to the pro's.

This strategy has two entry signals, long = when price hits lower band, while above EMA, previous candle was bearish and current candle is bullish.
Short = when price hits upper band, while below EMA, previous candle was bullish and current candle is bearish.
Take profits are the opposite side's band(lower band for long signals, upper band for short signals). This means our take profit price will change per bar.
Our stop loss doesn't change, it's the difference between entry price and the take profit target divided by the input risk reward.

Note di rilascio

Didn't adjust the math behind the stop loss in the long entry position whereas I did in the short position. Basically halving the risk reward ratio to 0.75%, that was not intended and is fixed now.
Commenti
zorak2d
Does the stop loss change when the target changes on each candle? Or is the calculation only with the initial target?
conflixx95493
@zorak2d, hey I'm sorry I never replied! I got super distracted on real life stuff.
Looking back at the code, I did make a comment that the take profit would trail, but that's certainly not the case. For example; the stopLong variable is inside the if statement. That means when the condition is true, it adjust the variable stopLong based on current values for as long as the condition is true. Though our if statement doesn't need to be true all the time for us to be in the position but it will stop adjusting the value once our condition is false. Also the stopLong variable is filled with close of current candle.
That said, I'm also not certain how the stop / limit functionally works in a strategy.entry command. My guess would be that it sets a limit and a stop order at a set value but I'd have to test that to really know for sure.

It's been such a long time, I'm sorry I can't be of more help.
Altro