Day Trading SPYThis script can be used to see a potential trend change, ride a trend and to scalp following the current trend.
Indicators:
- ATR (bright green/maroon) – is a longer term trend ATR line
- MA (green/red) - is a shorter term MA, where the fast MA is dotted and the long MA is a line
- Support and Resistance (white bold line) – long-term support and resistance areas
- Scalping signals (red/green) – small triangles above/below the candles bouncing off fast MA
- Black candles - oversized huge candles, which must be addressed carefully, especially when these candles change the trend per ATR, as with such huge candle – it is hard to determine where to place the stop-loss (if it is above/below the candle, since the candle is so big - it becomes a big risk). Also such candles may point to an unusual market moves. The size can be adjusted from 0.1 and up, it’s set to 1.4 by default, but it can be changed as needed. With such candles, it is best to wait and see what market does. If the black candle is following the ATR trend or changing the trend per ATR – wait for next 1-3 candles or so, usually those re-bounce in the opposite direction of the ATR trend, which allows you to open the position with a tighter stop-loss.
- Olive and Maroon candles – overbought and oversold candles per RSI (80/15 default) levels. At this levels just watch out for a potential soon reversal. Keep in mind, price may continue going oversold/overbought for a while, so look for additional confirmations.
1) ATR (long-term trend): The flag “Buy” and “Sell” signals (can set Alerts), which happens when the price is crossing through ATR line, marking a potential trend change. If ATR matches MA and ideally there is a breakout - open position in the direction of the signal and use the ATR line as your initial hard stop-loss until you reach the first price target / take first profit. It is best to use the most recent high/low pivot or a Fibonacci extension for the first price target. Once you take it – move SL to entry to secure the profits. If the trend continues and you take the next price target, you can use the fastMA (dotted line) as your dynamic stop-loss to ride the trend. Use the bold white line (long-term support and resistance) where price may certainly reverse where you can close your position completely if you day-trading Options.
2) MA (scalping): The small green and red triangles below/above the bars (can set Alerts), which appear when the price “touches” the fast MA (dotted line) and re-bounces from it with the candle matching the direction (bullish/bearish). Make sure ATR and MA are both going in the same direction for best results. This can be used to scalp for small profits or to jump into the trend. To minimize the risk, since you are jumping into the trend, I suggest placing your stop-loss slightly above/below the candle (the one which bounced off the fast MA). Price targets are similar – most recent high/low pivot or a Fibonacci extension. Same way, once you take the first profit/reach the first price target, move SL to entry and on the next price target – use the fast MA as your dynamic stop-loss.
If you don’t know how to divide up your position - here is an example on how I take profits between the price targets:
- Open position with buying a multiple of x4 contracts
- Sell ½ of the position at first price target and move my SL to entry
- Sell ½ of the remaining position at a second price target
- Sell the rest of the position at the third price target or sell ½ of it and use the fast MA as my dynamic stop-loss for the remaining of the position
Also, keep an eye on the breakouts, especially if they go along the ATR and MA trend and keep an eye on the volume, which may help confirming the direction of the price.
Cari dalam skrip untuk "spy"
Relative Strength (IBD Style)This script is meant to give you a Relative Strength indication of the stock. The goal is to use a similar calculation as used by IBD.
It calculates the performance of the current stock for the last year (most recent quarter is weighted double) and compares it to the performance of a reference index or ticker (default is "SPY").
IBD would give you a value between 0 and 100 because this value is the percentile within all stocks. This is not possible with Pine Script at the moment.
So here you get a Relative Strength value that is >0 if the stock is stronger than the index and <0 if it is weaker than the index.
You can still compare the Relative Strength values between stocks (bigger is better) but you won't know which percentile it is right off the bat.
Relative StrengthPowerful tool to calculate and display the strength of a security compared to another security.
Some Main purposes are:
- finding new leadership in a market correction
- comparing a market leader with a top competitor
- tracking rotation in the market
.. and so much more!
This tool is highly configurable, you can especially change:
- The reference symbol (SPY, QQQ, BTCUSD, ...)
- The time span to indicate a new High or Low in a certain time-frame
- Factorize your RS-Chart to make it fit to the original chart. (Moves the chart up or down)
- Option to repaint your candles / bars when a new RS High occurs in the given timeframe.
Enjoy and have a great day!
Powerful_Trading
Sector PerformanceThis indicator shows real-time current day performance for 11 ETFs that divide the S&P 500 into eleven sector index funds. The list of different sector ETFs this indicator tracks is as follows -
1. SPY - S&P 500 Index
2. XLC - Communication Services
3. XLY - Consumer Discretionary
4. XLP - Consumer Staples
5. XLE - Energy
6. XLF - Financials
7. XLV - Health Care
8. XLI - Industrials
9. XLB - Materials
10. XLRE - Real Estate
11. XLF - Technology
12. XLU - Utilities
Acknowledgment - This indicator is adapted using the source code from another excellent performance indicator (). Thanks to BeeHolder (www.tradingview.com) for generously sharing the source code.
MarketLeadersSomeone asked me to script this for them and I was surprised at how well it worked
The idea is to check if the top 22 largest cap companies are above or below their MA
By default, the system uses a 20 MA, but you can set it how you want
It checks if the companies including, QQQ (NASDAQ) and SPY are above their MA's and updates the histogram
I've drawn in simple green price break lines to highlight areas of interest
I like this system because it's SO SIMPLE and it uses more data than just look at one stock, it reads the underlying market for the heavy movers.
If the big stocks are doing well, then the market should be doing well too, unless small caps are heavily stalling.
I've also created a strategy based around this and will be posting it soon
Relative Strength ComparisonThis indicator compares the difference in percentage change between two symbols
over a user-specified number of bars.
Default settings will show the difference between the current symbol and the
S&P 500 ETF (SPY) over 10 bars. It can be used to determine if the stock is
showing relative strength or weakness compared to the overall market.
Vix Jump for Selling Puts or Buying CallsThis script aims to identify optimal times when to write Puts for premium, for example using the SPX Weeklies model or simply buying Calls. Not perfect but provides some additional confidence when playing Puts on SPX or the Wheel on SPY.
What it does:
We compare current VIX with a lookback VIX for X% delta. If there is a jump of say 20% over a defined period then that would indicate an opportunity to sell Puts, run a straddle or buy Calls. We use VVIX as a check to stop to many false positives ie VVIX falls of faster than VIX.
You can also use this loosely as a bottom finder.
VixFix Bridge BandsThis is an implementation of the Bridge Bands applied to the VixFix . Idea would be that when VixFix is above trend you'd want to be risk off, below trend you'd want to be risk on.
I just threw it together real quickly, but at first glance it appears to be a nice complement to the Bridge Bands.
On SPY and AAPL it handles the September drawdown quite nicely. (February as well for AAPL)
SPX Options Days Drop By DeltaSimple script that uses the percentage drop for a particular options delta and DTE to show how often you would be assigned on selling cash secured Puts (or naked Puts). Calculate the estimated percentage drop by finding your desired delta in the options chain and divide that price by the current price. For example a Delta of 10% could be $4055 with a current price of $4161 on a given day. The price differential is 2.5%. We test for how many times a 2.5% drop is encountered for our days to expiry (DTE) as this will be the number of times you would be assigned for that position. The lower the Delta the more the price has to drop ie a Delta of 7% would require a 4% drop etc. Objective is to NEVER be "assigned" and make "fee money" selling premium ie Puts.
SPX options expire 3 times a week as do SPY options
SPX options use the European model
SPX options settle in cash ie you are not assigned
NOTE: If you change your DTE you change your Delta and therefore your percentage differential.
Spread AnalyzerThis script plots the relative performance of the viewed security with respect to a selected benchmark. It can be used to identify assets higher than market average potential.
- The plot above is the relative volume.
- The plot below is the relative performance.
Computation is done by applying stochastic to the spread of the asset's current price/obv value to the benchmark defined by the Part1, 2 and 3.
The benchmark can be a portfolio as well:
Part1 = 4*SPY+2*QQQ
Part2 = XAUUSD+EURUSD
-PS: Each part may contain up to 10 symbols.
- The spread is calculated with the following formula
close / (Part1 + Part2 + Part3)
- Color code is based on the stochastic of macd of the spread.
The inputs:
length : lookback length for the stochastic
lenk : Smoothing factor(K) for stochastic
lend : EMA length(D)
MACD Fast / Slow / Smooth : MACD parameters used to determine the color code
MS CRB/SPYThis indicator tracks the GSCI Commodity Index over the course of the S&P 500. This is used for the fundamental evaluation of ratios of asset classes to each other. The thesis is based on Ray Dalio's quadrant theory: in periods without inflation and with good growth, stock prices rise and commodity prices fall. Conversely, in periods of good growth in an inflationary environment, commodities rise and the rise in equities slows. In particular, there is a change of favorites towards companies that produce cash (i.e. away from growth fantasies). This indicator shows the change in valuations between asset classes and thus allows conclusions to be drawn. This still goes far beyond what has been written, I recommend reading Ray Dalio's works on this.
Max GainThis indicator is meant to be used for coming up with price targets based on past performances of rallies/selloffs.
It shows how much a trade could have made over a 30-day period (or other length of time) in terms of percentage gain.
It also show how much could have been lost in terms of percentage loss
The green plot shows percentage gain from current high to the low of the previous 30 days.
The red plot shows adjusted percentage loss from current low to the high of the previous 30 days.
The 30 can be adjusted and the chart can be used on any time interval.
Note on max loss adjustment:
Max loss percentage is adjusted to be higher to account for the fact that a percentage loss corresponds to a percentage
gain of a greater amount. For instance, a loss of 25% can only be recovered with a percentage gain of 33%.
A 25% loss looking at the chart from left to right would be a 33% gain looking at the same price
action from right to left. In order to compare apples to apples visually and performance wise, max loss percent needs to be adjusted.
The actual max loss percent is calculated and plottable but is not plotted by default because it is less useful and adds clutter.
There is not a great difference between actual max loss and adjusted max loss under everyday market conditions, but
major selloffs (SPY 2020), short squeezes (GME 2021), or other unusually directional moves will display percentage losses
that, in absolute terms, should be considered to be fairly incorrect. The adjusted percentages are good indicators of
relative performance when comparing the magnitudes to the magnitudes of the max gain percentages and
are more visually meaningful than the actual max loss percentages in every situation, so they are plotted despite having incorrect values.
Note on bear markets:
This indicator was designed for bull markets but should it be used in bear markets the indicators that are and aren't
plotted should be swapped using the plot check boxes in the settings dialogue if there is interest in using the loss percentages
for actual loss amount calculations while maintaining visual/performance adjustment
As can been seen in the example chart a gain of 16.3% to 17.1% appears to be a resistance level. This level was recently broken through and the next resistance is 24.5%.
The target is a 24.5% gain from the anticipated 30-day low at the time when the price can be expected to reach a 25.4% gain at the gain rate observed in recent rallies.
Previous rallies are shown for reference with their 30-day periods and corresponding gain percentages which are plotted below.
A selloff is shown in red for reference as well. It was drawn backward to trick the tool into thinking it was a gain, so as to demonstrate logic behind the adjustment.
In reality, this was closer to a 9.5% loss, not 10.55%.
I am still experimenting with this indicator to see how to best use it. Ultimately, it helps me do what I was already doing with the percentage gain tools
but now I can do those analyses in a more systematic manner and with charting. Please feel free to ask questions.
Volatility barometerIt is the indicator that analyzes the behaviour of VIX against CBOE volaility indices (VIX3M, VIX6M and VIX1Y) and VIX futures (next contract to the front one - VX!2). Because VIX is a derivate of SPX, the indicator shall be used on the SPX chart (or equivalent like SPY).
When the readings get above 90 / below 10, it means the market is overbought / oversold in terms of implied volatility. However, it does not mean it will reverse - if the price go higher along with the indicator readings then everything is fine. There is an alarming situation when the SPX is diverging - e.g. the price go higher, the readings lower. It means the SPX does not play in the same team as IVOL anymore and might reverse.
You can use it in conjunction with other implied volatility indicators for stronger signals: the Correlation overlay ( - the indicator that measures the correlation between VVIX and VIX) and VVIX/VIX ratio (it generates a signal the ratio makes 50wk high).
Relative Strength 52 WeeksRelative strength plot that compare strength to SPY (changeable to whatever you want)-
Small orange suns marks the 52 week high on the strength line
Color coded EMA 22 line shows the overall trend of the strength
Momentum Rotation Indicator [CC]I have developed this custom indicator very loosely based on the Sector Rotation Model (Giorgos E. Siligardos. Technical Analysis of Stocks & Commodities, August 2012) and I called it the MRI because this is essentially a brain scan of any particular stock. This will not only tell you when a stock is breaking out over the market at large but also how the stock is doing compared to its own history. Buy when the line turns green and sell when the line turns red.
Let me know if there are any other indicators you would like to see me publish!
VIX Implied Move Bands for ES/Emini futuresThis script uses the close of the VIX on a daily resolution to provide the 'implied move' for the E-mini SP500 futures. While it can be applied to any equity index, it's crucial to know that the VIX is calculated using SPX options, and may not reflect the implied volatility of other indices. The user can adjust the length of the moving average used to calculate the bands, the window of days used to calculate the implied move, and the multiplier that effects the width of the bands.
Coefficient of Variation - EMA and SMA StDevYet another way to try and measure volatility. An alternative to using ATR is Standard Deviation, it can be used to measure volatility or what is also known as risk. SD measures how dispersed or far away the data is from the mean. It's commonly seen in risk management formulas or portfolio diversification formulas. The problem however is that the numbers that ATR and SD give off from one equity might not be relative to others or its own past. For example, SPY can give a large number despite not being as volatile as other equities while others being compared to can have smaller volatility numbers and still be more volatile looking.
A solution I thought of is to use percentages that are relatable to different equities. I found out another name for this idea comes from statistics and is known as coefficient of variation, also known as relative standard deviation. This helps see the volatility as a percentage and not just a number that only relates to what is being seen at the moment. I put in a border line on the zero level to see where zero is at but also to edit in case there is such a thing as a percentage number that can be too high or too low for volatility to be looked at if needed. The average and standard deviation formulas can use either simple moving average or exponential moving average.
MRS | Mansfield Relative Strength - 4CR CUPThere are many investors referring to Relative Strength (RS) indicator published by Investor’s Business Daily (IBD) for their analysis. Since the RS published by IBD is a proprietary indicator, no exact formulation is published on it.
Many discussion suggested that an alternative to the IBD RS is the Mansfield Relative Strength .
There are 2 parameters for Mansfield Relative Strength setting, namely the market index and the lookback period, n. the default setting of Mansfield Relative Strength adopted by Stan Weinstein was “SPY” and “52” in weekly chart and “200” in daily chart .
Stan Weinstein used the Mansfield Relative Strength indicator on weekly charts. He suggested the breakouts out of a base had to go together with rising relative strength . The Mansfield RS needs to be rising and close to or above 0.
This version of Mansfield Relative Strength relaxes these input parameters for your own choice.
The market index can be set to other market index, e.g. NDX, DJI, NI255, MOEX , TAIEX , HSI , etc. and the lookback period is relaxed to integral input, e.g. 60, 90, 150, etc.
Mansfield Relative Strength
The Relative Strength indicator adopted by Stan Weinstein in his book: “Secrets For Profiting in Bull and Bear Markets” is formulated as Mansfield Relative Strength ( MRS ).
The formula of this indicator is based on the regular Dorsey RS (DRS):
DRS = Price_stock / Price_index
MRS = 100 * (DRS_today / sma (DRS, n)) - 1)
Where:
DRS = Dorsey Relative Strength
SMA = Simple moving average over n days.
The Mansfield Relative Strength formulates as the change of ratio of DRS to its own n-day moving average, this means:
MRS equals to 0 if the DRS is exactly equal to its n day moving average.
MRS is negative if the DRS is below its n day moving average.
MRS is positive if the DRS is above its n day moving average.
Using Mansfield Relative Strength
The MRS tells the relative price movement of the stock to the market index in a period of time concern. As with the Dorsey RS , you can use Mansfield RS to examine if a stock performs better than the market.
This indicator has the advantage over the Dorsey RS that in Dorsey RS only trend matters while for Mansfield RS the values whether below or above the 0 also matters. This allows us to screen for stocks with a MRS value above 0. When we see that the MRS is far above 0 and has been above 0 for some time, we have found a stock that outperforms the market heavily. We can buy this kinds of stock when dips occur.
Technical checklistNo one indicator is perfect. People always have their favorite indicators and maintain a bias on weighing them purely on psychological reasons other than mathematical. This technical checklist indicator collected 20 common indicators and custom ones to address the issue of a bias weighted decision.
Here, I apply machine learning using a simple sigmoid neuron network with one hidden layer and a single node to avoid artifacts. For the ease of data collection, the indicator matrix is first shown as a heatmap. Once an uptrend signal window is selected manually, an indicator matrix can be recorded in a binary format (i.e., 1 0 0 1 1 0, etc.).
For example, the following indicator matrix was retrieved from the MRNA chart (deciscion: first 5 rows, buying; last 5 rows, no buying):
1 1 0 0 0 1 1 1 1 1 0 1 0 0 1 1 0 1 1 1
1 1 0 0 1 1 1 0 0 0 1 0 1 1 0 1 0 1 1 1
0 0 1 1 0 1 0 0 0 1 1 1 0 0 1 0 0 1 0 0
1 1 0 0 0 1 1 1 1 1 1 0 1 0 0 1 0 1 0 0
0 0 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 0 0
1 1 0 0 1 0 1 0 0 0 0 1 0 0 0 1 0 0 1 1
1 1 0 0 0 0 1 0 0 0 0 1 0 0 1 1 0 1 1 1
0 0 0 0 1 0 1 0 0 1 1 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 1 0 0 0 1 0 0 1 0 0 0 1 1 1
0 0 0 0 1 0 1 0 0 0 1 0 1 0 0 0 0 1 1 1
This matrix is then used as an input to train the machine learning network. With a correlated buying decision matrix as an output:
1
1
1
1
1
0
0
0
0
0
After training, the corrected weight matrix can be applied back to the indicator. And the display mode can be changed from a heatmap into a histogram to reveal buying signals visually.
Usage:
python stock_ml.py mrna_input.txt output.txt
Weight matrix output:
1.37639407
1.67969656
1.0162141
1.3184323
-1.88888442
8.32928588
-5.35777295
3.08739916
3.06464844
0.82986227
-0.53092333
-1.95045383
4.14441698
2.99179435
-0.08379438
1.70379704
0.4173048
-1.51870972
-2.14284707
-2.08513252
Corresponding indicators to the weight matrix:
1. Breakout
2. Reversal
3. Crossover of ema20 and ema60
4. Crossover of ema20 and ema120
5. MACD golden cross
6. Long cycle (MACD crossover 0)
7. RSI not overbought
8. KD not overbought and crossover
9. OBV uptrend
10. Bullish gap
11. High volume
12. Breakout up fractal
13. Rebounce of down fractal
14. Convergence
15. Turbulence reversal
16. Low resistance
17. Bullish trend (blue zone)
18. Bearish trend (red zone)
19. VIX close above ema20
20. SPY close below ema20
PS. It is recommended not to use default settings but to train your weight matrix based on underlying and timeframe.
Yield CurveThis script tracks the U.S. 2Yr/10Yr Spread and uses inversions of the curve to predict recessions. Whenever a red arrow appear on the yield curve, expect a recession to begin within the next 2 years. Use this signal to either exit the market, or hedge current positions. Whenever a green arrow appears on the yield curve, expect a recession to have nearly ended. Use this signal to enter the market, or cut current hedges against a recession. (I may update this script in the future to better incorporate the effective federal funds rate into exit points, but for now I am satisfied with the results).
Convert from ETF to FutureI use this for translating an ETF's levels to its matching futures contract. Like converting SPY to ES... or QQQ to NQ... or GLD to GC.
Q Average CostCalculated the average cost of the shares in the market. If close > indicator, means the market average share cost is below the close, this is a bullish sign. Otherwise, the market average share cost is above the close, which is a bearish sign.
Currently not feasible for index ETF (eg. SPY) or leveraged ETF (eg. TQQQ).
Will update code in later versions.
Equity Index Overnight FakeoutThis script highlights when price violates the highest high or lowest low within the user's selected lookback period, with the caveat that it occurs during the GLOBEX session. The script is designed to work exclusively with the trading hours for CME and CBOT Equity Index futures. I'm planning to make a more customizable version down the line.
My reasoning behind this very simple script is that the low liquidity and participation of the overnight session creates a tendency for moves at extremes to mean revert. Let me know what you think.