write me this code as explained here, and convers it to a v5 strategy for tradingview, will give the "Heikin Ashi RSI Oscillator" By JayRogers code at the bottom,
This strategy is credited to the "Heikin Ashi RSI Oscillator" By JayRogers.
The core of this strategy is "Heikin Ashi RSI Oscillator (HARSI)" By JayRogers, with multiple confirmation indicators. The buy signal is generated by HARSI when there is green HA, and there is a positive stochastic cross under the line OB line.
To confirm the buys signal, you can use one or all of the following:
EMA: the buy confirmation is positive if the candle closes above the EMA.
Volume Oscillator: the buy confirmation is positive if the volume value is above the zero line.
ADX: the buy confirmation is positive if the D+ is above the D- and the D+ is above the threshold level.
Vortex: the buy confirmation is positive if VI+ is above VI-.
You can enable the take profit, trailing stop loss (TSL), and stop lose (SL), if not, then the strategy will give a sell signal by itself when there is a negative stochastic cross above OB Extreme line.
Note, that the TSL arming value should be lower than the TSL %.
The strategy can give a different result based on your selection. However, the best timeframe is 4 hours without TP.
Apr 22, 2022
Release Notes
Added sell options.
With V1 better to use the built-in indicators for confirmation.
Apr 22, 2022
Release Notes
Minor typo change. The added option is for buying.
Added BUY options.
With V1 better to use the built-in indicators for confirmation.
Apr 23, 2022
Release Notes
Added more options to "Volume Oscillator". You can select the threshold level and the operation (above, under, crossover, crossunder).
Apr 23, 2022
Release Notes
Added new buy option. The buy signal is positive if HA closed under the OB level.
Apr 24, 2022
Release Notes
Minor bug fix.
Apr 25, 2022
Release Notes
Added Relative Volatility Index (RVI). You can activate the RVI as an additional confirmation based on the RVI directional ( bigger, small, crossover, crossunder) to the threshold level.
Apr 28, 2022
Release Notes
Added monthly & yearly profit/loss. Credit to levieux (Monthly Returns in Strategies with Market Benchmark).
Minor changes.
Apr 30, 2022
Release Notes
Added custom alert messages to be used for 3Commas and other bot platforms. Add your buy & sell message for the bot in the strategy, and when you create the alert just type {{startegy.order.alert_message}}
May 4, 2022
Release Notes
Added MACD and Supertrend.
May 6, 2022
Release Notes
Updated inputs name.
May 7, 2022
Release Notes
Add Ichimoku Cloud. There is three conditions to filter the buy signal.
May 7, 2022
Release Notes
The strategy is based on TSL, thus with this release the "After order is filled" enabled by default. This will allow to collect the profit as soon as possible.
Assistant
Enhanced the buy options.
Added EMA cross, which give positive buy signal if the fast EMA is above the slow EMA.
May 7, 2022
Release Notes
Fixed a typo in strategy syntax.
May 8, 2022
Release Notes
Added BTC price trend indicator. With this indicator you can disable/enable trading based on the BTC price movement, this will help to filter the signals while the market in downtrend since all the altcoins following the BTC.
May 12, 2022
Release Notes
Added new buy signal #4. The signal can be controlled more by OB, OS and HA smoothed factor.
Added two strategy exit methods.
May 25, 2022
Release Notes
Fixed a bug with buy signal #4
The table result option, by default, is set to false, ensure to make false when adding the alert, the table may cause CPU/memory error.
Jul 25, 2022
Release Notes
New: V5 Buys when stochK > sotchD on an uptrend with a look back one green candle.
New: V6 Same as V2 but will buy with more caution.
New: V7 Buys when the candle is green and under OB.
New: V8 Buys when stochK > sotchD and green candle has no low wick.
New: V9 Buys when stochK > sotchD and two green candles have no low wick.
NEW: SSL confluence - The signal is positive only if the "SSL up" is above "SSL down"
New: REX by vitelot with an option to calculate it with HA - The signal is positive only REX line is above the signal line, with a threshold option.
New: VWAP - The signal is positive only if the close is above VWAP
New: New exit options
New: Stop loss based on HA ATR will look back
New: Strategy statics table - useful on mobile version
New: Exit methods, TSL, TP, Strategy - Add take profit only
New: Awesome Oscillator - The signal is positive if the Awesome Oscillator candle is green.
New: Chande Momentum Oscillator - The signal is posivtive only of the Chande is above the zero line.
New: ZLSMA - The signal is positive only if the ZLSMA is under the over-bought zone.
New: VWMA - The signal is positive if the selected condition is above VWMA.
Updated: V1 Buys when StochK crossover StochD with more restricted confirmation conditions.
Updated: V2 Buys when StochK > StochD with less confirmation conditions.
Updated: V3 Buys when a red candle closes under OB or OBX and the next candle is green with other confirmation.
Updated: V4 Buys based on HA,OB, and OS level.
Updated: Option to calculate EMA with HA
Updated: Option to calculate Vortex with HA
Updated: Option to calculate ADX with HA
Updated: Option to calculate RVI with HA
Updated: Updated Ichimoku with multiple buy options including based on HA
Updated: SuperTrend by KivancOzbilgic with the option to calculate it with HA
Updated: Option to calculate MACD with HA
Updated: Buy Signal 3
Updated: BTC Trend confluence, will not repaint
Updated: Exit comments, now each exit shows exit type
Jul 25, 2022
Release Notes
Updating the strategy test result, the strategy is using 30% of the capital 1000.
If you have a premium plan, it is recommended to activate the "Use bar magnifier".
The option "recalculate ordered if filled" is disabled now due to signal frequency, which you can enable manually.
Dec 15, 2022
Release Notes
// - added RSI
// - added MFI
// - added Ultimate Oscillator
// - added Volume Flow by LazyBear
// - added MavilimW by KIVANÇ ÖZBİLGİÇ - for more information visit https://www.tradingview.com/script/IAssyObN-MavilimW/
Dec 23, 2022
Release Notes
Added Time Segmented Volume (TSV)
Added Trend Magic - By KivancOzbilgic
Added Dziwne Trend By Dziwne
Note: Not recommended to use multiple trend confluences together, the same thing for the volume confluences, use one trend confluence, and one volume confluence.
Jan 9, 2023
Release Notes
Bug fix with MFI confluence.
here is the "Heikin Ashi RSI Oscillator" By JayRogers:
// This source code is free to use, copy, and alter in any way you choose.
// ...but credit is always nice :)
////////////////////////////////////////////////////////////////////////////////
// //
// ====== ABOUT THIS INDICATOR //
// //
// - RSI based Heikin Ashi candle oscillator //
// //
// ====== ARTICLES and FURTHER READING //
// //
// - https://www.investopedia.com/terms/h/heikinashi.asp //
// //
// "Heikin-Ashi is a candlestick pattern technique that aims to reduce //
// some of the market noise, creating a chart that highlights trend //
// direction better than typical candlestick charts" //
// //
// ====== REASON FOR STUDY //
// //
// - Mostly experimental. I wanted to see if I could translate RSI into a //
// Heikin Ashi function and retain it's oscillating nature. That goal //
// was met more easily than I anticipated with quite delightful results. //
// //
// ====== DISCLAIMER //
// //
// Any trade decisions you make are entirely your own responsibility. //
// I've made an effort to squash all the bugs, but you never know! //
// //
////////////////////////////////////////////////////////////////////////////////
string TT_HARSI = "Period for the RSI calculations used to generate the" +
"candles. This seperate from the RSI plot/histogram length."
string TT_PBIAS = "Smoothing feature for the OPEN of the HARSI candles." +
"\n\nIncreases bias toward the prior open value which can" +
" help provide better visualisation of trend strength." +
"\n\n** By changing the Open values, High and Low can also" +
" be distorted - however Close will remain unchanged."
string TT_SMRSI = "This option smoothes the RSI in a manner similar to HA" +
" open, but uses the realtime rsi rather than the prior" +
" close value."
string TT_STOCH = "Uses the RSI generated by the above settings, and as such" +
" will be affected by the smoothing option."
string TT_STFIT = "Adjusts the vertical scaling of the stochastic, can help" +
" to prevent distortion of other data in the channel." +
"\n\nHas no impact cross conditions."
// mode selectable rsi function for standard, or smoothed output
f_rsi( _source, _length, _mode ) =>
code
// get base rsi
float _zrsi = f_zrsi( _source, _length )
// smoothing in a manner similar to HA open, but rather using the realtime
// rsi in place of the prior close value.
var float _smoothed = na
_smoothed := na( _smoothed[1] ) ? _zrsi : ( _smoothed[1] + _zrsi ) / 2
// return the requested mode
_mode ? _smoothed : _zrsi
// RSI Heikin-Ashi generation function
f_rsiHeikinAshi( _length ) =>
code
// get close rsi
float _closeRSI = f_zrsi( close, _length )
// emulate "open" simply by taking the previous close rsi value
float _openRSI = nz( _closeRSI[1], _closeRSI )
// the high and low are tricky, because unlike "high" and "low" by
// themselves, the RSI results can overlap each other. So first we just go
// ahead and get the raw results for high and low, and then..
float _highRSI_raw = f_zrsi( high, _length )
float _lowRSI_raw = f_zrsi( low, _length )
// ..make sure we use the highest for high, and lowest for low
float _highRSI = max( _highRSI_raw, _lowRSI_raw )
float _lowRSI = min( _highRSI_raw, _lowRSI_raw )
// ha calculation for close
float _close = ( _openRSI + _highRSI + _lowRSI + _closeRSI ) / 4
// ha calculation for open, standard, and smoothed/lagged
var float _open = na
_open := na( _open[ i_smoothing ] ) ? ( _openRSI + _closeRSI ) / 2 :
( ( _open[1] * i_smoothing ) + _close[1] ) / ( i_smoothing + 1 )
// ha high and low min-max selections
float _high = max( _highRSI, max( _open, _close ) )
float _low = min( _lowRSI, min( _open, _close ) )
// return the OHLC values
[ _open, _high, _low, _close ]
// channel fill
fill( upper, upperx, color.new( color.red, 90 ), title = "Background Fill OB" )
fill( upper, lower, color.new( color.blue, 90 ), title = "Background Channel" )
fill( lower, lowerx, color.new( color.green, 90 ), title = "Background Fill OS" )
// histogram first, so it is on the bottom of the plot/candle draw stack
plot( i_showHist ? RSI : na, "RSI Histogram", color.new( color.silver, 80 ), 1, plot.style_histogram )
// make our HA rsi candles
plotcandle( O, H, L, C, "HARSI", bodyColour, wickColour, bordercolor = bodyColour )
Strategy Definition: The script begins by defining a TradingView strategy named "Heikin Ashi RSI Oscillator Strategy v5". It sets up basic parameters like the percentage of equity to use per trade, initial capital, and commission settings.
Inputs Configuration:
HARSI Parameters: Controls the length and smoothing for the Heikin Ashi RSI Oscillator.
Stochastic Parameters: Configures the stochastic oscillator settings including lengths and overbought/oversold levels.
Confirmation Indicators: Options to include or exclude various confirmation indicators like EMA, Volume Oscillator, ADX, and Vortex, along with their respective parameters.
Exit Parameters: Allows enabling/disabling of take profit, stop loss, and trailing stop loss with customizable percentages.
HARSI Calculation:
Computes a zero-median RSI by subtracting 50 from the standard RSI.
Calculates the Heikin Ashi (HA) RSI Oscillator components: open, high, low, and close based on the smoothed RSI values.
Determines if the current HA candle is green (i.e., if the HA close is greater than the HA open).
Stochastic Oscillator Calculation:
Calculates the %K and %D lines of the stochastic oscillator based on the HARSI values.
Sets up overbought and oversold levels for generating trade signals.
Confirmation Indicators:
EMA: Checks if the current price is above the EMA.
Volume Oscillator: Calculates the difference between fast and slow EMAs of volume to determine bullish or bearish volume trends.
ADX: Uses the Average Directional Index to confirm the strength of the trend.
Vortex: Confirms trend direction based on the Vortex Indicator's positive and negative values.
Trade Conditions:
Buy Signal: Triggered when the HARSI indicates a green candle and the stochastic %K crosses under the overbought level, combined with all active confirmations.
Sell Signal: Activated when the stochastic %K crosses above the extreme overbought level.
Strategy Actions:
Entry: Executes a long position when the buy conditions are met.
Customization & Usage
Enabling/Disabling Confirmations: You can toggle each confirmation indicator on or off based on your trading preference by adjusting the respective input settings.
Adjusting Levels: Modify the overbought and oversold levels of the stochastic oscillator to better fit the asset or timeframe you are trading.
Exit Strategies: Fine-tune take profit, stop loss, and trailing stop percentages to align with your risk management strategy.
Timeframe Recommendation: As per the original strategy recommendation, a 4-hour timeframe is suggested for optimal performance without take profit settings.
Important Notes
Backtesting: Always backtest the strategy on historical data to understand its performance and adjust parameters accordingly before deploying it in a live trading environment.
Market Conditions: The effectiveness of this strategy can vary based on market conditions. It's recommended to use it in trending markets where confirmation indicators can effectively validate the trend.
Risk Management: Ensure that the risk management settings (take profit, stop loss, trailing stops) are appropriate for your risk tolerance and trading goals.
Acknowledgements
This strategy is built upon the "Heikin Ashi RSI Oscillator" by JayRogers and incorporates multiple confirmation indicators to enhance trade signal reliability. Proper credit is given to the original author for the foundational indicator.
Not yet included in a published release.
Exit: Defines exit strategies based on take profit, stop loss, trailing stop loss, and the sell condition. The strategy.exit function manages exits using these parameters.
Plots (Optional):
EMA Plot: Visualizes the EMA if it's being used as a confirmation.
HARSI Candles: Plots the Heikin Ashi RSI Oscillator candles on the chart for better visualization.
Stochastic Lines: Draws horizontal lines for overbought, oversold, and extreme overbought levels, along with plotting the %K and %D lines.