OPEN-SOURCE SCRIPT

The Ultimate Buy and Sell Indicator

تم تحديثه
This indicator should be used in conjunction with a solid risk management strategy that does not over-leverage positions and uses stop-losses. You can not rely 100% on the signals provided by this indicator (or any other for that matter).

With that said, this indicator can provide some excellent signals.
It has been designed with a large number of customization options intended for advanced traders, but you do not HAVE to be an advanced user to simply use the indicator. I have tried to make it easy to understand, and this section will provide you with a better understanding of how to use it.
NOTE:
While NOT REQUIRED, I would recommend also finding my indicator called, "Ultimate RSI", which is designed to work together with this indicator (visually). They both contain the same settings and allow you to visualize changes made in this indicator that can not be displayed on the main chart.

This indicator creates it's own candles(bars), so you have to go into your main settings and turn off the "body, border and wick" color settings. Using a dark background is also recommended.

How does it work?
The indicator mainly relies on the RSI indicator with Bollinger Bands for signals. (Though not entirely)

First, there are something that I call "Watch Signals", which are various Bollinger Band crossing events. This could be the price crossing Bollinger Bands or the RSI crossing Bollinger Bands.

There are separate watch signals for buys and sells. Buy watch signals are colored orange to match the BUY signal candle color and Fuchsia (kind of a bright purple) to match SELL signal candles.

In order for most buy or sell signals to be created, there must first be a watch signal. There is a lookback period (or length) for watch signals to be used, and after that many candles (bars) have passed, they will be ignored. You can set a length to look back as well as a time to wait before creating any.

What this means is that if there has previously been (for instance) a sell signal. You can tell it to wait 10 bars before creating any buy watch signals. You can then also tell it that it should look back 10 bars from the current one in order to find any buy watch signals. This means that if you had it set up that way 10 to wait and 10 to validate, it would start allowing buy watch signals 11 bars after a sell, and then once you hit 20 bars, it will start leaving a gap (invisible to you) as the 10 bar lookback period starts moving forward with each new bar. This is useful in order to keep signals more spaced apart as some bad signals come quickly after another one.
Example: You may get a sell signal where the Bollinger bands are tight, then the price easily drops down into the lower band creating a buy watch signal, then you get a "fake" or short pump up and it says buy, but then drops dramatically afterwards. The wait period can ensure that the sell stays in effect longer before a buy is considered by blocking any buy watch signals for a period of time.

After you get a watch signal, the system then looks for various other things to happen to create buy or sell signals. This could be the RSI crossing the (slow) RSI Basis line (from its Bollinger bands), it could be the price crossing its basis line, it could be MACD crosses, it could even be RSI crossing certain levels. All of these are options. If you like the MACD strategy and want it to give you buy and sell signals from just MACD crosses, simply select that option for signals.
It is also able to use the first of any of the options that takes place.

I included an option to force alternating buy and sell signals, rather than showing groups of, or subsequent buy, buy, buy signals, for instance.

Moving on....
You can change the moving average that is used to calculate the RSI. The standard moving average for RSI is the RMA (aka SWMA). Changes to this can dramatically change your signals. You also have the option to change the moving average type used in the Bollinger bands calculation. You can change the length of these as well. The same goes for the Bollinger bands over the Price chart. I added an ATR option for the RSI Bollinger bands to play with, as well. You are able to adjust the standard deviation (multiplier) of the bands as well, which will of course affect the signals.

The ways you can play with signals are nearly infinite, so have fun figuring it out.

The indicator allows for moving averages to be shown as well, with a variety of types to choose from. The standard numbers are 5, 10, 20, 50, 100 and 200, with the addition of a custom moving average of your choice. You can also change the color of this one. You can choose to show them all or any of them you want to show, in any combination, although the TYPE of moving average (SMA, EMA, WMA, etc.) will apply to all of them.
You may also notice the Bollinger Bands over the Price are colored, and become more or less transparent.

The color is derived from the trend of the RSI or the RSI basis (your choice). It looks back at the value however many bars you want and compares the values and that's how it determines if it is trending up or down. Since RSI is a directional momentum indicator, this can be quite useful. If you see the bands are getting darker, this will explain why.

The indicator has a lookback period for determining the widest the bands (which measure volatility) have been over that period of time. This is the baseline. It then will make the bands disappear (by making them more transparent) if the volatility is low. This indicates that a change in volatility is coming and that price isn't really changing much compared to the past (default 500) bars. If they become bright, this is because price has started trending in a direction and volatility is increasing.

I should also note that the candles are colored based on RSI levels.
If you use the Ultimate Companion indicator, you will be able to see the RSI levels (zones) that the colors are based on. As RSI moves into a new range, the candle color will change.
I have created a yellow zone where the candles turn yellow. This is when RSI is between (default) 45 and 55, indicating there is basically no momentum and price is going sideways. This is a good place to get trapped in bad trades, and there is a Yellow RSI Filter to block signals in this area to keep you from entering bad trades.

Green candles indicate values over 55 (getting brighter as RSI rises) and red candles are RSI values under 45 (getting brighter as RSI values get lower). If you see white, this means RSI is either over 80 or under 20. A sharp reversal is almost always imminent at this stage.

When we talk about Buy and Sell Signals, they draw a green or red triangle and it literally says BUY or SELL. There is an option to color the background for added visibility. These signals do not "repaint", what this means is that they can be late. To account for this, I have included a background color that will flash as a warning that a buy or sell could be imminent, although it may fail to break through and set a buy or sell signal. This is simply an advanced warning. The reason is that sometimes a candle may be very large and you won't be told to buy or sell during the candle until the move is completely over and now you're getting in on the next one. That's not a great feeling, so I made it repaint the background color and not repaint the completed signal. You get the best of both worlds.

This indicator also uses complex logic to handle things.
When there is a buy signal, it enters into a state of having been bought, or a "bought state". The same for sells. If Force alternating signals is off, you could have more than one buy in a bought state, or more than one sell in a sell state. There is an option to color the background green during the full duration of a bought state, or red during the full duration of a sold state.

I have added divergence.
This shows that the lows or highs of RSI and PRICE are different. If RSI is making higher highs but the price is not, then the price is likely to follow this bullish divergence, if the opposite happens, it's bearish. It will draw a line on the chart connecting the highs and lows and call it bearish or bullish. You can adjust this as well.

I have an RSI High/Low filter. If the RSI basis (or average) is very high or low, you can block signal from this area since the price is likely to continue in that direction before actually reversing.

You can change the settings of the MACD if you choose to use it for signals, and if you want to see it, you'll have to run that indicator below the chart and match the settings to see what is going on, just like the RSI.

Going back to Watch Signals. You can also choose to require more than one watch signal if you choose. You can skip watch signals, so it will ignore the first or second one, whatever you want to do. You can color the background to show you where watch signals have been skipped.

Regarding the wait period for creating watch signals after a sell or after a buy, you can also color the background to see where these were blocked by the wait period.

Lastly you can choose which type of watch signals to use, or keep them from being shown on the chart. This allows you to study the history of how the asset you are trading behaves and customize the behavior of signals based on your study of it.

Everything in the settings area has tooltips, which will explain what that thing does to help you along this journey.

I hope this indicator (and perhaps Ultimate RSI alongside this) will help you take your trading to the next level.
ملاحظات الأخبار
- Changed default settings to make it immediately more user friendly
ملاحظات الأخبار
- Removed ATR from band calculation (Not useful enough)
- Code clean-up (Removed unused code, restructured, removed a lot of commenting.)
- Changes to default settings
- Consolidated all watch signals into one group so settings are universal for buy and sell watch signals.
** Watch signal handling logic is still currently under development/improvement**

--- More improvements to come. Signals will be better and more consistent with less tweaking in the future, so keep your eyes open for updates. ---
ملاحظات الأخبار
This version should perform better. I still recommend using other indicators as confirmation as this still has issues with prolonged, steady trends with low volatility. And as always, use stop losses to protect against bag signals that are inevitable.
- Fixed programming issues with arrays and other conditions of the algorithm
- Updated tooltips
- Changed some default settings
ملاحظات الأخبار
- Added another visual cue to the buy and sell signals that displays concentric circles of varying sizes and transparencies with a toggle
- Consolidated buy and sell signals toggle into a single toggle
- Updated the chart image to show the new circles feature and highlight other optional features such as the Bought and Sold colored backgrounds
ملاحظات الأخبار
1.) Added ATR zone with various options
2.) Updated tooltips to help explain features
3.) Consolidated watch signals of each type and removed configuration options
4.) Simplified the wait signal period (Now blocks watch, buy and sell signals after any buy or sell signal for the specified number of bars.)
5.) Rearranged the settings menu for more practical use
6.) Removed more unnecessary features
7.) Added a background coloring option for hours outside of NY session
8.) Changed some settings and parameters
9.) Changed the buy and sell signal background vertical colors to match

Let me know what you think in the comments :)
ملاحظات الأخبار
- Added ATR color and transparency inputs
- Change a few default settings again
- Probably a few other adjustments I forgot
ملاحظات الأخبار
UPDATES:
- Changed some default settings and did some code cleanup
- I made the watch signals that have to do with Price crossing Bollinger Bands optional as I find they create too many buy and sell signals that can be done without in most cases (Option can now be found under the Price Bollinger Band settings.) ATR based watch signals were previously made optional if you choose to use ATR for signals.
(I am aware of an issue with the ATR band lines and the toggle and will address it soon)
ملاحظات الأخبار
UPDATE:
- Corrected behavior of ATR fill and band lines so that:
If both lines and fill are turned off, neither should be visible.
If only the lines are on, only the lines should be visible.
If only the fill is on, only the fill should be visible.
If both are on, both should be visible.
ملاحظات الأخبار
- Added various color and transparency outputs (as requested) ;)
- I tried to add them for the moving averages, but I've run out of "outputs" that I'm allowed to use (It considers a color input an output, somehow)
ملاحظات الأخبار
UPDATE:
- Background color for NY Market hours
From 8am EST (UTC-5) to 5pm EST, the background is colored gray. This should now in theory work correctly for anyone in any timezone. It didn't seem to be working correctly before. It should automatically adjust for DST (Daylight Savings Time. If you see any issues with it please let me know.
ملاحظات الأخبار
UPDATE AGAIN (sorry)
- I just removed it all together. It doesn't work correctly, and I think I could use those outputs for something more useful. Just look at your clock and set an alarm if you care about that, or use one of the other indicators that does this :D I'll add something more interesting now that I have more outputs to work with with this gone.
ملاحظات الأخبار
UPDATES:
1.) If you are using this indicator, you should also be using "Ultimate RSI", since many of the settings you will change can only be visualized in the second indicator (they share the same settings where applicable). Here is a link:
Ultimate RSI

2.) I have deprecated the coloring of the Bollinger Bands using the RSI or RSI Basis trend and have changed it to match Ultimate RSI, where now the Upper Bollinger Band is colored based on the DPO Ribbon I created. The Lower Bollinger Band is colored based on Rate of Change of the price.
3.) I removed some features that were just complicating things to simplify the indicator.
4.) I have added a new buy/sell signal option. You are now able to set an RSI moving average that is NOT the Bollinger Band basis line. This allows you to use a shorter moving average for RSI crosses, without affecting the shape of the bands, which affects watch signals.
5.) I have changed a lot of the default values. One major change was to change the RSI BB MA to WMA (from SMA) for better signals. This is my opinion, results may vary. That's why I have so many options, you can customize it to your liking.
6.) I had to add Rate of Change and DPO in order to color the bands, so they are now options at the bottom of the settings menu. I have also added the ability to filter signals based on the color of the bands at the time of the signal method you are using. So if you turn DPO filtering on, the color must be the bullish color in order to product a buy signal, bearish color for a sell. Same goes for ROC filtering.
7.) I removed "force alternating buy and sells" because it just causes issues and isn't actually useful, it was experimental.
8.) I removed ATR signals since they don't seem to work all that well. You can still create watch signals via candles crossing the lines, but there are no longer buy and sell signals directly from ATR.
NOTES:
1.) If both Bollinger Bands are green, and you get a buy signal, there is a high probability that the trade will be a good one. Same goes for sells and both bands being red. You can tune this to your liking. This indicator is designed to be customized to how you trade. That could be scalping or holding longer periods of time. It's all possible here.
2.) I still have issues filtering bad buy signals in a prolonged, low-volatility decline in price and bad sells in when the price is going up. I have found ways to do it, but they sacrifice the good signals, so this is still something I'm working on.
Risk management is your job as a trader.
ملاحظات الأخبار
Update:
- Added an option (default is on) for alerts to happen one candle ahead of a Buy or Sell signal plot. When turned on, it uses the vertical background color as the trigger (This trigger is repainting). This can alert you to a potential buy or sell condition earlier. To turn this off, it's at the very end of the settings.
- Added an option to convert the ATR bands into ATR Bollinger Bands for a new twist on ATR
- Added an option to toggle RSI Bollinger Band crosses for Watch signals (You can now choose any combination of RSI, Price and ATR generated watch signals)
- Added a new candle coloring where the candles turn blue when the lower RSI Bollinger Band is over the Yellow RSI High (Default 55) or if the upper RSI Band is below the Yellow RSI Low (Default 45) the candles will turn purple. In most cases, this is a point where price will soon reverse. It can help you avoid entering trades that may not last very long or enter trades that will.
- Made a few default settings changes
ملاحظات الأخبار
UPDATE:
- Added divergence alerts
- Just providing some clarification on "ATR" (with a slight change to the calculation)
- It is not possible to create an actual ATR zone as ATR values are very small and do not correlate with the price. This section is not truly ATR, what I have in fact done is create bands around the moving average selected in that part of the settings. It then uses ATR to adjust the bands slightly. If it weren't so useful for creating watch signals for scalping, then I would just remove it altogether since it isn't truly ATR, and I can't think of anything better to call it, but since it uses ATR in the calculation, I'm just going to leave it as is until I come up with a better idea.
- You can now use the "ATR" bands or current price Bollinger Bands to affect transparency of the Bollinger Bands. Each has a slightly different effect. To recap, the bands become more transparent when volatility is low, meaning if the price does not have much range for a while, and the longer this takes place, the less you will see them, since you don't really NEED to see them. This indicates you should really just wait until you start seeing some volatility until taking trades since the market has yet to choose a new direction. You could likely figure out the direction by studying a higher timeframe of RSI values, if you understand the patterns as well (future goal to teach that), but if not, you can just wait for them to reappear before taking trades. Signals without bands could easily reverse on you due to the way signals are created in this algorithm.
ملاحظات الأخبار
FIX:
Corrected the divergence alerts. Thanks to user "smarm" for pointing out the error.
CHANGE:
I made it so you can use only the "repainting" vertical background color for buy/sell signals. The setting is now independent of whether or not buy and sell signals are toggled on or off. That now only affects Buy and Sell signal shapes/text as well as circles.
I also shortened the text from saying "BUY" and "SELL" to simple "B" and "S" to clear up some clutter.
ملاحظات الأخبار
Default settings changed for trading XAU/USD (Gold/USD) on the 1 hour chart.
ملاحظات الأخبار
Update 05/30/2024: (Example chart shows DPO candle coloring with buy and sell signals)

- Candles can now be colored in TWO different ways (RSI and DPO):

NOTE: In order for these to be visible, you have to go into the main settings (not the indicator settings) and turn off the built-in candle colors for the body, border and wick.

Option #1: RSI Levels (old feature, but explained again)
Description:
I define the Yellow RSI zone as price having no real momentum in either direction. The default is 45 to 55 on the RSI scale, although this can be adjusted.
If RSI is in the Yellow area, the candles will be yellow.
If RSI is above 55, the candles turn green and will get increasingly brighter as the RSI increases. Once above 80, they turn white.
If RSI is below 45, the candles will turn red and get brighter as RSI decreases.
Once below 20, they turn white.

This allows you to visualize RSI through the color of the candles alone.

Option 2: DPO Ribbon (with volatility dimming)
If the DPO ribbon (my own creation) is bullish or bearish, then the candles will be colored the same as the upper Bollinger Band. This means you can change the bullish and bearish candle colors by going to the Bollinger Band section in the settings menu. This allows you to visualize the DPO trend without displaying the Bollinger Bands (reduces clutter).
And just as the Bollinger Bands will darken as the bands narrow (low volatility), this feature is also included in the candle coloring.
This means that as volatility decreases, the candles become darker, and when volatility increases, they become brighter.

I have also changed the color of the buy and sell signals to match the circles and background coloring for better consistency and readability. (In my opinion)

To recap:
If RSI candle coloring is on - candles are colored based on RSI levels
If DIP candle coloring is on - candles are colored based on DPO being bullish or bearish
If Buy and Sell signals are on - buy and sell signals will be colored orange for buy and fuchsia for sell.

NOTE:
You can also turn the candles off completely if you want (maybe you want to use candle colors from another indicator), and you can also turn buy and sell signals off if you want.

Side note: I also removed one type of candle coloring that was interesting, but inconsistent. It had to do with something too complicated to explain.
Bands and ChannelsCandlestick analysisCycles

نص برمجي مفتوح المصدر

قام مؤلف هذا النص البرمجي بنشره وجعله مفتوح المصدر، بحيث يمكن للمتداولين فهمه والتحقق منه، وهو الأمر الذي يدخل ضمن قيم TradingView. تحياتنا للمؤلف! يمكنك استخدامه مجانًا، ولكن إعادة استخدام هذا الرمز في المنشور يخضع لقواعد‎‎قوانين الموقع. يمكنك جعله مفضلاً لاستخدامه على الرسم البياني.

هل تريد استخدام هذا النص البرمجي على الرسم البياني؟


يعمل أيضًا:

إخلاء المسؤولية