3Commas Bollinger StrategyThis strategy is intended for use as a way of backtesting various parameters available on 3commas.io composite bot using a bollinger band type trading strategy. While it's primary intention is to provide users a way of backtesting bot parameters, it can also be used to trigger a deal start by either using the {{strategy.open.alert_message}} field in your alert and providing the bot details in the configuration screen for the strategy or by including the usual deal start message provided by 3commas. You can find more information about how to do this from help.3commas.io
The primary inputs for the strategy are:
// USER INPUTS
Short MA Window - The length of the Short moving average
Long MA Window - The length of the Long moving average
Upper Band Offset - The offset to use for the upper bollinger offset
Lower Band Offset - The offset to use for the lower bollinger offset
Long Stop Loss % - The stop loss percentage to test
Long Take Profit % - The Take profit percentage to test
Initial SO Deviation % - The price deviation percentage required to place to first safety order
Safety Order Vol Step % - The volume scale to test
3Commas Bot ID - (self explanatory)
Bot Email Token - Found in the deal start message for your bot (see link in previous section for details)
3Commas Bot Trading Pair - The pair to include for composite bot start deals (should match format of 3commas, not TradingView IE. USDT_BTC not BTCUSDT)
Start Date, Month, Year and End Date, Month and Year all apply to the backtesting window. By default it will use as much data as it can given the current period select (there is less historical data available for periods below 1H) back as far as 2016 (there appears to be no historical data on Trading view much before this). If you would like to test a different period of time, just change these values accordingly.
Known Issues
Currently there are a couple of issues with this strategy that you should be aware of. I may fix them at some point in the future but they don't really bug me so this is more for informational purposes than a promise that they may one day be fixed.
Does not test trailing take profit
Number of safety orders and Safety Order Step Scale are currently not user configurable (must edit source code)
Using the user configuration to generate deal start message assumes you are triggering a composite bot, not a simple bot.
Backtest
Combo Backtest 123 Reversal & MASS Index This is combo strategies for get a cumulative signal.
First strategy
This System was created from the Book "How I Tripled My Money In The
Futures Market" by Ulf Jensen, Page 183. This is reverse type of strategies.
The strategy buys at market, if close price is higher than the previous close
during 2 days and the meaning of 9-days Stochastic Slow Oscillator is lower than 50.
The strategy sells at market, if close price is lower than the previous close price
during 2 days and the meaning of 9-days Stochastic Fast Oscillator is higher than 50.
Second strategy
The Mass Index was designed to identify trend reversals by measuring
the narrowing and widening of the range between the high and low prices.
As this range widens, the Mass Index increases; as the range narrows
the Mass Index decreases.
The Mass Index was developed by Donald Dorsey.
WARNING:
- For purpose educate only
- This script to change bars colors.
RSI-VWAP Indicator %█ OVERALL
Simple and effective script that, as you already know, uses vwap as source of the rsi, and with good results as long as the market has no long-term downtrend.
RsiVwap = rsi (vwap (close), Length)
The default settings are for BTC in a 30 minute time frame. For other pairs and time frames you just have to play with the settings.
█ FEATURES
• The option to start trading from a certain date has been added.
• To make the profit more progressive, a percentage of your equity is used for entries and a percentage of your position is used for closings.
• The option to trade in Spot mode has been added, since, for the TradingView backtest, the money is infinite and if you do not limit it somehow,
it would offer you much better profits than the live trading.
QuantityOnLong = Spot ? (EquityPercent / 100) * ((strategy.equity / close) - strategy.position_size) : (EquityPercent / 100) * (strategy.equity / close)
• The option to stop the system when the drawdown exceeds the fixed limit has been added.
Drawdown, as you already know, is a very important measure of risk in trading systems.
The maximum drawdown will tell us what the maximum loss of a trading system has been during a period. This maximum loss is determined by:
strategy.risk.max_drawdown(Risk, strategy.percent_of_equity)
• Leverage plotted on labels added.
█ ALERTS
To enjoy the benefits of automatic trading, TradingView alerts can be used as direct buy-sell orders on spot, or long-close orders with leverage.
Currently there are Chrome extensions that act as a bridge between TradingView and your Exchange or Broker.
This is an example of syntax for this type of extensions. Copy and paste a message like this into the alert window:
{{strategy.order.action}} @ {{strategy.order.price}} | e = {{exchange}} a = account s = {{ticker}} b = {{strategy.order.action}} {{strategy.order.alert_message}}
█ NOTE
Certain Risks of Live Algorithmic Trading You Should Know:
• Backtesting cannot assure actual results.
• The relevant market might fail or behave unexpectedly.
• Your broker may experience failures in its infrastructure, fail to execute your orders in a correct or timely fashion or reject your orders.
• The system you use for generating trading orders, communicating those orders to your broker, and receiving queries and trading results from your broker may fail.
• Time lag at various point in live trading might cause unexpected behavior.
• The systems of third parties in addition to those of the provider from which we obtain various services, your broker, and the applicable securities market may fail or malfunction.
█ THANKS
Thanks to TradingView, its Pine code, its community and especially those Pine wizards who post their ideas that helps us to learn.
If the world is heading toward a equitable new world economic order, let's get rich first ...
Happy trading!
Ultimate Strategy TemplateHello Traders
As most of you know, I'm a member of the PineCoders community and I sometimes take freelance pine coding jobs for TradingView users.
Off the top of my head, users often want to:
- convert an indicator into a strategy, so as to get the backtesting statistics from TradingView
- add alerts to their indicator/strategy
- develop a generic strategy template which can be plugged into (almost) any indicator
My gift for the community today is my Ultimate Strategy Template
Step 1: Create your connector
Adapt your indicator with only 2 lines of code and then connect it to this strategy template.
For doing so:
1) Find in your indicator where are the conditions printing the long/buy and short/sell signals.
2) Create an additional plot as below
I'm giving an example with a Two moving averages cross.
Please replicate the same methodology for your indicator wether it's a MACD, ZigZag, Pivots, higher-highs, lower-lows or whatever indicator with clear buy and sell conditions
//@version=4
study(title='Moving Average Cross', shorttitle='Moving Average Cross', overlay=true, precision=6, max_labels_count=500, max_lines_count=500)
type_ma1 = input(title="MA1 type", defval="SMA", options= )
length_ma1 = input(10, title = " MA1 length", type=input.integer)
type_ma2 = input(title="MA2 type", defval="SMA", options= )
length_ma2 = input(100, title = " MA2 length", type=input.integer)
// MA
f_ma(smoothing, src, length) =>
iff(smoothing == "RMA", rma(src, length),
iff(smoothing == "SMA", sma(src, length),
iff(smoothing == "EMA", ema(src, length), src)))
MA1 = f_ma(type_ma1, close, length_ma1)
MA2 = f_ma(type_ma2, close, length_ma2)
// buy and sell conditions
buy = crossover(MA1, MA2)
sell = crossunder(MA1, MA2)
plot(MA1, color=color_ma1, title="Plot MA1", linewidth=3)
plot(MA2, color=color_ma2, title="Plot MA2", linewidth=3)
plotshape(buy, title='LONG SIGNAL', style=shape.circle, location=location.belowbar, color=color_ma1, size=size.normal)
plotshape(sell, title='SHORT SIGNAL', style=shape.circle, location=location.abovebar, color=color_ma2, size=size.normal)
/////////////////////////// SIGNAL FOR STRATEGY /////////////////////////
Signal = buy ? 1 : sell ? -1 : 0
plot(Signal, title="🔌Connector🔌", transp=100)
Basically, I identified my buy, sell conditions in the code and added this at the bottom of my indicator code
Signal = buy ? 1 : sell ? -1 : 0
plot(Signal, title="🔌Connector🔌", transp=100)
Important Notes
🔥 The Strategy Template expects the value to be exactly 1 for the bullish signal , and -1 for the bearish signal
Now you can connect your indicator to the Strategy Template using the method below or that one
Step 2: Connect the connector
1) Add your updated indicator to a TradingView chart
2) Add the Strategy Template as well to the SAME chart
3) Open the Strategy Template settings and in the Data Source field select your 🔌Connector🔌 (which comes from your indicator)
From then, you should start seeing the signals and plenty of other stuff on your chart
🔥 Note that whenever you'll update your indicator values, the strategy statistics and visual on your chart will update in real-time
Settings
- Color Candles : Color the candles based on the trade state (bullish, bearish, neutral)
- Close positions at market at the end of each session : useful for everything but cryptocurrencies
- Session time ranges : Take the signals from a starting time to an ending time
- Close Direction : Choose to close only the longs, shorts, or both
- Date Filter : Take the signals from a starting date to an ending date
- Set the maximum losing streak length with an input
- Set the maximum winning streak length with an input
- Set the maximum consecutive days with a loss
- Set the maximum drawdown (in % of strategy equity)
- Set the maximum intraday loss in percentage
- Limit the number of trades per day
- Limit the number of trades per week
- Stop-loss: None or Percentage or Trailing Stop Percentage or ATR
- Take-Profit: None or Percentage or ATR
- Risk-Reward based on ATR multiple for the Stop-Loss and Take-Profit
This script is open-source so feel free to use it, and optimize it as you want
Alerts
Maybe you didn't know it but alerts are available on strategy scripts.
I added them in this template - that's cool because:
- if you don't know how to code, now you can connect your indicator and get alerts
- you have now a cool template showing you how to create alerts for strategy scripts
Source: www.tradingview.com
I hope you'll like it, use it, optimize it and most importantly....make some optimizations to your indicators thanks to this Strategy template
Special Thanks
Special thanks to @JosKodify as I borrowed a few risk management snippets from his website: kodify.net
Additional features
I thought of plenty of extra filters that I'll add later on this week on this strategy template
Best
Dave
Combo Backtest 123 Reversal & Line Regression Intercept This is combo strategies for get a cumulative signal.
First strategy
This System was created from the Book "How I Tripled My Money In The
Futures Market" by Ulf Jensen, Page 183. This is reverse type of strategies.
The strategy buys at market, if close price is higher than the previous close
during 2 days and the meaning of 9-days Stochastic Slow Oscillator is lower than 50.
The strategy sells at market, if close price is lower than the previous close price
during 2 days and the meaning of 9-days Stochastic Fast Oscillator is higher than 50.
Second strategy
Linear Regression Intercept is one of the indicators calculated by using the
Linear Regression technique. Linear regression indicates the value of the Y
(generally the price) when the value of X (the time series) is 0. Linear
Regression Intercept is used along with the Linear Regression Slope to create
the Linear Regression Line. The Linear Regression Intercept along with the Slope
creates the Regression line.
WARNING:
- For purpose educate only
- This script to change bars colors.
Combo Backtest 123 Reversal & Laguerre-based RSI This is combo strategies for get a cumulative signal.
First strategy
This System was created from the Book "How I Tripled My Money In The
Futures Market" by Ulf Jensen, Page 183. This is reverse type of strategies.
The strategy buys at market, if close price is higher than the previous close
during 2 days and the meaning of 9-days Stochastic Slow Oscillator is lower than 50.
The strategy sells at market, if close price is lower than the previous close price
during 2 days and the meaning of 9-days Stochastic Fast Oscillator is higher than 50.
Second strategy
This is RSI indicator which is more sesitive to price changes.
It is based upon a modern math tool - Laguerre transform filter.
With help of Laguerre filter one becomes able to create superior
indicators using very short data lengths as well. The use of shorter
data lengths means you can make the indicators more responsive to
changes in the price.
WARNING:
- For purpose educate only
- This script to change bars colors.
MACD With Trend Filter: Visual Backtest Module TemplateSample Strategy: MACD Crossover with trend filter options
MA Filter : Price Close Above MA, Search for Buy, Price Close Below MA, Search for Sell
ADX Filter : Take trade only when ADX is above certain treshold
MACD Signal : MACD Cross above signal line while under 0 line indicate Buy Signal
MACD Cross below signal line while above 0 line indicate Sell Signal
-----------------------------
Using Alert Module:
Enable Alert --> Enable TV's alert and plot signal to chart
Alert Type --> Set to take Buy only, Sell only or Both alert
----------------------------
Using Backtest Module:
Enable Backtest --> Enable Backtest simulation
Backtest Type --> Set to take Buy only, Sell only or Both
SL Type -->
ATR : Set SL in ATR times Multiplier below/above entry price
Fixed : Set SL in fixed point below entry point (in 'Dollar'). e.g. for Stocks -> 0.5 equals to 50cent while for EURUSD currency -> 0.005 equal to 50 pips
HiLo Bar : Set SL at highest/lowest wick of previous bar plus/minus Fixed point. e.g. EURUSD HiLo=3 and Fixed Point = 0.0005, buy trade will place SL 5 Pips below lowest of previous 3 bar
SL ATR Period --> Set Lookback Period used for SL's ATR calculation
SL ATR Multi --> Set ATR Multiplier for SL
SL Fixed --> Set Fixed Level for SL (Use when SL Type is either Fixed or HiLo Bar)
SL Bar --> Set Number of previous bar to check for SL placement
TP RR Ratio --> Set TP based on RR multiplier. e.g. 2 means TP level will be twice further from entry point compared to Entry-SL distance.
Notes: The point is for preliminary testing, so it only supports 1 trade at a time and no Trailing Stop
----------------------------
Disclaimer:
This script main objective is to create my personal indicator template so that i just have to modify the indicator module for preliminary testing in future.
Testing Alert Module so i can re-use it as template in future study/indicator
Testing Visual Backtest Module so i can re-use it as template in future study/indicator
i believe using Strategy function is a better approach for this but the entry/exit level seems to be hit n miss (at least for me, still trying to figure what i did wrong)
also, i rather code the strategy in other platform where i can use the more accurate tick data if i want to validate backtest statistics.
My study scripts was built only to test/visualize an idea to see its viability and if it can be used to optimize existing strategy.
credit: ADX code are originally from "ADX and DI" by @BeikabuOyaji although i re-wrote so i can have cleaner read and use RMA instead of SMA
Combo Backtest 123 Reversal & Volume SMA This is combo strategies for get a cumulative signal.
First strategy
This System was created from the Book "How I Tripled My Money In The
Futures Market" by Ulf Jensen, Page 183. This is reverse type of strategies.
The strategy buys at market, if close price is higher than the previous close
during 2 days and the meaning of 9-days Stochastic Slow Oscillator is lower than 50.
The strategy sells at market, if close price is lower than the previous close price
during 2 days and the meaning of 9-days Stochastic Fast Oscillator is higher than 50.
Second strategy
Volume and SMA
WARNING:
- For purpose educate only
- This script to change bars colors.
Logistic RSI, STOCH, ROC, AO, ... by DGTExperimental attemt of applying Logistic Map Equation for some of widly used indicators.
With this study "Awesome Oscillator (AO)", "Rate of Change (ROC)", "Relative Strength Index (RSI)", "Stochastic (STOCH)" and a custom interpretation of Logistic Map Equation is presented
Calculations with Logistic Map Equation makes sense when the calculated results are iterated many times within the same equation.
Here is the Logistic Map Equation : Xn+1 = r * Xn * (1 - Xn)
Where, the value of r is the key for this equation which changes amazingly the behaviour of the Logistic Map.
The value we have asigned for r is less then 1 and greater than 0 ( 0 < r < 1) and in this case the iterations performed with the maximum number of output series allowed by Pine is quite enough for our purpose and thanks to arrays we can easiliy store them for further processing
What we have as output:
Each iteration result is then plotted (excluding plotting the first iteration), as circles or line based on user preference
Values above and below zero level (0) are coloured differently to emphasis bull and bear power
Finally Standard Deviation of Array's Elements is ploted as line. Users may choose to display this line only
So where it comes the indicators "Awesome Oscillator (AO)", "Rate of Change (ROC)", "Relative Strength Index (RSI)", "Stochastic (STOCH)".
Those are the indicators whose values are assigned to our key varaiable in the Logistic Map equation forulma which is r
Further details regarding Logistic Map can found under the description of “Logistic EMA w/ Signals by DGT” study
Disclaimer:
Trading success is all about following your trading strategy and the indicators should fit within your trading strategy, and not to be traded upon solely
The script is for informational and educational purposes only. Use of the script does not constitute professional and/or financial advice. You alone have the sole responsibility of evaluating the script output and risks associated with the use of the script. In exchange for using the script, you agree not to hold dgtrd TradingView user liable for any possible claim for damages arising from any decision you make based on use of the script
Combo Backtest 123 Reversal & Gann Swing Oscillator This is combo strategies for get a cumulative signal.
First strategy
This System was created from the Book "How I Tripled My Money In The
Futures Market" by Ulf Jensen, Page 183. This is reverse type of strategies.
The strategy buys at market, if close price is higher than the previous close
during 2 days and the meaning of 9-days Stochastic Slow Oscillator is lower than 50.
The strategy sells at market, if close price is lower than the previous close price
during 2 days and the meaning of 9-days Stochastic Fast Oscillator is higher than 50.
Second strategy
The Gann Swing Oscillator has been adapted from Robert Krausz's book,
"A W.D. Gann Treasure Discovered". The Gann Swing Oscillator helps
define market swings.
WARNING:
- For purpose educate only
- This script to change bars colors.
Combo Backtest 123 Reversal & FX Sniper: T3-CCI This is combo strategies for get a cumulative signal.
First strategy
This System was created from the Book "How I Tripled My Money In The
Futures Market" by Ulf Jensen, Page 183. This is reverse type of strategies.
The strategy buys at market, if close price is higher than the previous close
during 2 days and the meaning of 9-days Stochastic Slow Oscillator is lower than 50.
The strategy sells at market, if close price is lower than the previous close price
during 2 days and the meaning of 9-days Stochastic Fast Oscillator is higher than 50.
Second strategy
This simple indicator gives you a lot of useful information - when to enter, when to exit
and how to reduce risks by entering a trade on a double confirmed signal.
You can use in the xPrice any series: Open, High, Low, Close, HL2, HLC3, OHLC4 and ect...
WARNING:
- For purpose educate only
- This script to change bars colors.
Combo Backtest 123 Reversal & Volatility Finite Volume ElementsThis is combo strategies for get a cumulative signal.
First strategy
This System was created from the Book "How I Tripled My Money In The
Futures Market" by Ulf Jensen, Page 183. This is reverse type of strategies.
The strategy buys at market, if close price is higher than the previous close
during 2 days and the meaning of 9-days Stochastic Slow Oscillator is lower than 50.
The strategy sells at market, if close price is lower than the previous close price
during 2 days and the meaning of 9-days Stochastic Fast Oscillator is higher than 50.
Second strategy
This is another version of FVE indicator that we have posted earlier
in this forum.
This version has an important enhancement to the previous one that`s
especially useful with intraday minute charts.
Due to the volatility had not been taken into account to avoid the extra
complication in the formula, the previous formula has some drawbacks:
The main drawback is that the constant cutoff coefficient will overestimate
price changes in minute charts and underestimate corresponding changes in
weekly or monthly charts.
And now the indicator uses adaptive cutoff coefficient which will adjust to
all time frames automatically.
WARNING:
- For purpose educate only
- This script to change bars colors.
Combo Backtest 123 Reversal & FSK (Fast and Slow Kurtosis) This is combo strategies for get a cumulative signal.
First strategy
This System was created from the Book "How I Tripled My Money In The
Futures Market" by Ulf Jensen, Page 183. This is reverse type of strategies.
The strategy buys at market, if close price is higher than the previous close
during 2 days and the meaning of 9-days Stochastic Slow Oscillator is lower than 50.
The strategy sells at market, if close price is lower than the previous close price
during 2 days and the meaning of 9-days Stochastic Fast Oscillator is higher than 50.
Second strategy
This indicator plots the Fast & Slow Kurtosis. The Kurtosis is a market
sentiment indicator. The Kurtosis is constructed from three different parts.
The Kurtosis, the Fast Kurtosis(FK), and the Fast/Slow Kurtosis(FSK).
WARNING:
- For purpose educate only
- This script to change bars colors.
Combo Backtest 123 Reversal & Fractal Chaos Oscillator This is combo strategies for get a cumulative signal.
First strategy
This System was created from the Book "How I Tripled My Money In The
Futures Market" by Ulf Jensen, Page 183. This is reverse type of strategies.
The strategy buys at market, if close price is higher than the previous close
during 2 days and the meaning of 9-days Stochastic Slow Oscillator is lower than 50.
The strategy sells at market, if close price is lower than the previous close price
during 2 days and the meaning of 9-days Stochastic Fast Oscillator is higher than 50.
Second strategy
The value of Fractal Chaos Oscillator is calculated as the difference between
the most subtle movements of the market. In general, its value moves between
-1.000 and 1.000. The higher the value of the Fractal Chaos Oscillator, the
more one can say that it follows a certain trend – an increase in prices trend,
or a decrease in prices trend.
Being an indicator expressed in a numeric value, traders say that this is an
indicator that puts a value on the trendiness of the markets. When the FCO reaches
a high value, they initiate the “buy” operation, contrarily when the FCO reaches a
low value, they signal the “sell” action. This is an excellent indicator to use in
intra-day trading.
WARNING:
- For purpose educate only
- This script to change bars colors.
Simple SMA Strategy Backtest Part 5Simple SMA strategy
In this stream, we will create an intraday trade cap.
WARNING:
- For purpose educate only
- This script to change bars colors
Stream:
www.tradingview.com
Combo Backtest 123 Reversal & Floor Pivot Points This is combo strategies for get a cumulative signal.
First strategy
This System was created from the Book "How I Tripled My Money In The
Futures Market" by Ulf Jensen, Page 183. This is reverse type of strategies.
The strategy buys at market, if close price is higher than the previous close
during 2 days and the meaning of 9-days Stochastic Slow Oscillator is lower than 50.
The strategy sells at market, if close price is lower than the previous close price
during 2 days and the meaning of 9-days Stochastic Fast Oscillator is higher than 50.
Second strategy
The name ‘Floor-Trader Pivot,’ came from the fact that Pivot points can
be calculated quickly, on the fly using price data from the previous day
as an input. Although time-frames of less than a day can be used, Pivots are
commonly plotted on the Daily Chart; using price data from the previous day’s
trading activity.
WARNING:
- For purpose educate only
- This script to change bars colors.
Combo Backtest 123 Reversal & Future Lines of Demarcation This is combo strategies for get a cumulative signal.
First strategy
This System was created from the Book "How I Tripled My Money In The
Futures Market" by Ulf Jensen, Page 183. This is reverse type of strategies.
The strategy buys at market, if close price is higher than the previous close
during 2 days and the meaning of 9-days Stochastic Slow Oscillator is lower than 50.
The strategy sells at market, if close price is lower than the previous close price
during 2 days and the meaning of 9-days Stochastic Fast Oscillator is higher than 50.
Second strategy
An FLD is a line that is plotted on the same scale as the price and is in fact the
price itself displaced to the right (into the future) by (approximately) half the
wavelength of the cycle for which the FLD is plotted. There are three FLD's that can be
plotted for each cycle:
An FLD based on the median price.
An FLD based on the high price.
An FLD based on the low price.
WARNING:
- For purpose educate only
- This script to change bars colors.
Combo Backtest 123 Reversal & Fisher Transform Indicator This is combo strategies for get a cumulative signal.
First strategy
This System was created from the Book "How I Tripled My Money In The
Futures Market" by Ulf Jensen, Page 183. This is reverse type of strategies.
The strategy buys at market, if close price is higher than the previous close
during 2 days and the meaning of 9-days Stochastic Slow Oscillator is lower than 50.
The strategy sells at market, if close price is lower than the previous close price
during 2 days and the meaning of 9-days Stochastic Fast Oscillator is higher than 50.
Second strategy
Market prices do not have a Gaussian probability density function
as many traders think. Their probability curve is not bell-shaped.
But trader can create a nearly Gaussian PDF for prices by normalizing
them or creating a normalized indicator such as the relative strength
index and applying the Fisher transform. Such a transformed output
creates the peak swings as relatively rare events.
Fisher transform formula is: y = 0.5 * ln ((1+x)/(1-x))
The sharp turning points of these peak swings clearly and unambiguously
identify price reversals in a timely manner.
WARNING:
- For purpose educate only
- This script to change bars colors.
Combo Backtest 123 Reversal & Finite Volume Elements (FVE) This is combo strategies for get a cumulative signal.
First strategy
This System was created from the Book "How I Tripled My Money In The
Futures Market" by Ulf Jensen, Page 183. This is reverse type of strategies.
The strategy buys at market, if close price is higher than the previous close
during 2 days and the meaning of 9-days Stochastic Slow Oscillator is lower than 50.
The strategy sells at market, if close price is lower than the previous close price
during 2 days and the meaning of 9-days Stochastic Fast Oscillator is higher than 50.
Second strategy
The FVE is a pure volume indicator. Unlike most of the other indicators
(except OBV), price change doesn?t come into the equation for the FVE (price
is not multiplied by volume), but is only used to determine whether money is
flowing in or out of the stock. This is contrary to the current trend in the
design of modern money flow indicators. The author decided against a price-volume
indicator for the following reasons:
- A pure volume indicator has more power to contradict.
- The number of buyers or sellers (which is assessed by volume) will be the same,
regardless of the price fluctuation.
- Price-volume indicators tend to spike excessively at breakouts or breakdowns.
WARNING:
- For purpose educate only
- This script to change bars colors.
MACD-X, More Than MACD by DGTMoving Average Convergence Divergence – MACD
The most popular indicator used in technical analysis, the moving average convergence divergence (MACD), created by Gerald Appel. MACD is a trend-following momentum indicator, designed to reveal changes in the strength, direction, momentum, and duration of a trend in a financial instrument’s price
Historical evolution of MACD,
- Gerald Appel created the MACD line,
- Thomas Aspray added the histogram feature to MACD
- Giorgos E. Siligardos created a leader of MACD
MACD employs two Moving Averages of varying lengths (which are lagging indicators) to identify trend direction and duration. Then, MACD takes the difference in values between those two Moving Averages (MACD Line) and an EMA of those Moving Averages (Signal Line) and plots that difference between the two lines as a histogram which oscillates above and below a center Zero Line. The histogram is used as a good indication of a security's momentum.
Mathematically expressed as;
macd = ma(source, fast_length) – ma(source, slow_length)
signal = ma(macd, signal_length)
histogram = macd – signal
where exponential moving average (ema) is in common use as a moving average (ma)
fast_length = 12
slow_length = 26
signal_length = 9
The MACD indicator is typically good for identifying three types of basic signals ;
Signal Line Crossovers
A Signal Line Crossover is the most common signal produced by the MACD. On the occasions where the MACD Line crosses above or below the Signal Line, that can signify a potentially strong move. The standard interpretation of such an event is a recommendation to buy if the MACD line crosses up through the Signal Line (a "bullish" crossover), or to sell if it crosses down through the Signal Line (a "bearish" crossover). These events are taken as indications that the trend in the financial instrument is about to accelerate in the direction of the crossover.
Zero Line Crossovers
Zero Line Crossovers occur when the MACD Line crossed the Zero Line and either becomes positive (above 0) or negative (below 0). A change from positive to negative MACD is interpreted as "bearish", and from negative to positive as "bullish". Zero crossovers provide evidence of a change in the direction of a trend but less confirmation of its momentum than a signal line crossover
Divergence
Divergence is another signal created by the MACD. Simply, divergence occurs when the MACD and actual price are not in agreement. A "positive divergence" or "bullish divergence" occurs when the price makes a new low but the MACD does not confirm with a new low of its own. A "negative divergence" or "bearish divergence" occurs when the price makes a new high but the MACD does not confirm with a new high of its own. A divergence with respect to price may occur on the MACD line and/or the MACD Histogram
Moving Average Crossovers , another hidden signal that MACD Indicator identifies
Many traders will watch for a short-term moving average to cross above a longer-term moving average and use this to signal increasing upward momentum. This bullish crossover suggests that the price has recently been rising at a faster rate than it has in the past, so it is a common technical buy sign. Conversely, a short-term moving average crossing below a longer-term average is used to illustrate that the asset's price has been moving downward at a faster rate and that it may be a good time to sell.
Moving Average Crossovers in reality is Zero Line Crossovers, the value of the MACD indicator is equal to zero each time the two moving averages cross over each other. For easy interpretation by trades, Zero Line Crossovers are simply described as positive or negative MACD
False signals
Like any forecasting algorithm, the MACD can generate false signals. A false positive, for example, would be a bullish crossover followed by a sudden decline in a financial instrument. A false negative would be a situation where there is bearish crossover, yet the financial instrument accelerated suddenly upwards
What is “MACD-X” and Why it is “More Than MACD”
In its simples form, MACD-X implements variety of different calculation techniques applied to obtain MACD Line, ability to use of variety of different sources , including Volume related sources, and can be plotted along with MACD in the same window and all those features are available and presented within a single indicator, MACD-X
Different calculation techniques lead to different values for MACD Line, as will further discuss below, and as a consequence the signal line and the histogram values will differentiate accordingly. Mathematical calculation of both signal line and the histogram remain the same.
Main features of MACD-X ;
1- Introduces different proven techniques applied on MACD calculation , such as MACD-Histogram, MACD-Leader and MACD-Source, besides the traditional MACD (MACD-TRADITIONAL)
• MACD-Traditional , by Gerald Appel
It is the MACD that we know, stated as traditional just to avoid confusion with other techniques used with this study
• MACD-Histogram , by Thomas Aspray
The MACD-Histogram measures the distance between MACD and its signal line (the 9-day EMA of MACD). Aspray developed the MACD-Histogram to anticipate signal line crossovers in MACD. Because MACD uses moving averages and moving averages lag price, signal line crossovers can come late and affect the reward-to-risk ratio of a trade. Bullish or bearish divergences in the MACD-Histogram can alert chartists to an imminent signal line crossover in MACD
The MACD-Histogram represents the difference between MACD and its 9-day EMA, the signal line. Mathematically,
macdx = macd - ma(macd, signal_length)
Aspray's contribution served as a way to anticipate (and therefore cut down on lag) possible MACD crossovers which are a fundamental part of the indicator.
Here come a question, what if repeat the same calculations once more (macdh2 = macdh - ma(macdh, signal_length), will it be even better, this question will remain to be tested
• MACD-Leader , by Giorgos E. Siligardos, PhD
MACD Leader has the ability to lead MACD at critical situations. Almost all smoothing methods encounter in technical analysis are based on a relative-weighted sum of past prices, and the Leader is no exception. The concealed weights of MACD Leader are such that more relative weight is used in the more recent prices than the respective weights used by the components of MACD. In effect, the Leader expresses more changes in average price dynamics for the recent price movement than MACD, thus eventually leading MACD, especially when significant trend changes are about to take place.
Siligardos creates two less-laggard moving averages indicators in its formula using the same periods as follows
Indicator1 = ma(source, fast_length) + ma(source - ma(source, fast_length), fast_length)
Indicator2 = ma(source, slow_length) + ma(source - ma(source, slow_length), slow_length)
and then take the difference:
Indicator1 - Indicator2
The result is a new MACD Leader indicator
macdx = macd + ma(source - fast_ma, fast_length) - ma(source - slow_ma, slow_length)
• MACD-Source , a custom experimental interpretation of mine ,
MACD Source, presents an application of MACD that evaluates Source/MA Ratio, relatively with less lag, as a basis for MACD Line, also can be expressed as source convergence/divergence to its moving average. Among the various techniques for removing the lag between price and moving average (MA) of the price, one in particular stands out: the addition to the moving average of a portion of the difference between the price and MA. MACD Source, is based on signal length mean of the difference between Source and average value of shot length and long length moving average of the source (Source/MA Ratio), where the source is actual value and hence no lag and relatively less lag with the average value of moving average of the source . Mathematically expressed as,
macdx = ma(source - avg( ma(source, fast_length), ma(source, slow_length) ), signal_length)
MACD Source provides relatively early crossovers comparing to MACD and better momentum direction indications, assuming the lengths are set to same values
For further details, you are invited to check the following two studies, where the first seeds were sown of the MACD-Source idea
Price Distance to its Moving Averages study, adapts the idea of “Prices high above the moving average (MA) or low below it are likely to be remedied in the future by a reverse price movement", presented in an article by Denis Alajbeg, Zoran Bubas and Dina Vasic published in International Journal of Economics, Commerce and Management
First MACD like interpretation comes with the second study named as “ P-MACD ”, where P stands for price, P-MACD study attempts to display relationship between Price and its 20 and 200-period moving average. Calculations with P-MACD were based on price distance (convergence/divergence) to its 200-period moving average, and moving average convergence/divergence of 20-period moving average to 200-period moving average of price.
Now as explained above, MACD Source is a one adapted with traditional MACD, where Source stands for Price, Volume Indicator etc, any source applicable with MACD concept
2- Allows usage of variety of different sources, including Volume related indicators
The most common usage of Source for MACD calculation is close value of the financial instruments price. As an experimental approach, this study will allow source to be selected as one of the following series;
• Current Close Price (close)
• Average of High, Low, and Close Price (hlc3)
• On Balance Volume (obv)
• Accumulation Distribution (accdist)
• Price Volume Trend (pvt)
Where,
-Current Close Price and Average of High, Low, and Close Price are price actions of the financial instrument
- Accumulation Distribution is a volume based indicator designed to measure underlying supply and demand
- On Balance Volume (OBV) , is a momentum indicator that measures positive and negative volume flow
- Price Volume Trend (PVT) is a momentum based indicator used to measure money flow
3- Can be plotted along with MACD in the same window using the same scaling
Default setting of MACD-X will display MACD-Source with Current Close Price as a source and traditional MACD can be plotted eighter as a companion of MACD-X or can be selected to be plotted alone.
Applying both will add ability to compare, or use as a confirmation of one other
In case, traditional MACD Is plotted along with MACD-X to avoid misinterpreting, the lines plotted, the area between MACD-X Line and Signal-X Line is highlighted automatically, even if the highlight option not selected. Otherwise highlight will be applied only if that option selected
4- 4C Histogram
Histogram is plotted with four colors to emphasize the momentum and direction
5- Customizable
Additional to ability of selecting Calculation Method, Source, plotting along with MACD, there are few other option that allows users to customize the MACD-X indicator
Lengths are configurable, default values are set as 12, 26, 9 respectively for fast, slow and smoothing length. Setting lengths to 8,21,5 respectively Is worth checking, slower length moving averages will lead to less lag and earlier reaction to price actions but yet requires a caution and back testing before applying
Highlight the area between MACD-X Line and Signal-X Line, with colors emphasising the direction
Label can be added to display Calculation Method, Source and Length settings, the aim of this label is to server only as a reminder to trades to be aware of settings while they are occupied with charts, analysis etc.
Here comes another question, which is of more importance having the reminder or having the indicators with multi timeframe feature? Build-in Multi Time Frame features of Pine is not supported when labels and lines introduced in the script, there are other methods but brings complexity. To be studied further, this version will be with labels for time being.
Epilogue
MACD-X is an alternative variant of MACD, the insight/signals provided by MACD are also applicable to MACD-X with early and clear warnings for the changes in the trend.
If MACD is essential to your analysis, then it is my guess that after using the MACD-X for a while and familiarizing yourself with its unique character and personality, you will make it an inseparable companion to other indicators in your charts.
The various signals generated by MACD/MACD-X are easily interpreted and very few indicators in technical analysis have proved to be more reliable than the MACD, and this relatively simple indicator can quickly be incorporated into any short-term trading strategy
Disclaimer : Trading success is all about following your trading strategy and the indicators should fit within your trading strategy, and not to be traded upon solely
The script is for informational and educational purposes only. Use of the script does not constitutes professional and/or financial advice. You alone the sole responsibility of evaluating the script output and risks associated with the use of the script. In exchange for using the script, you agree not to hold dgtrd TradingView user liable for any possible claim for damages arising from any decision you make based on use of the script
Moving Average Displaced Envelope Backtest Moving Average Displaced Envelope. These envelopes are calculated
by multiplying percentage factors with their displaced expotential
moving average (EMA) core.
How To Trade Using:
Adjust the envelopes percentage factors to control the quantity and
quality of the signals. If a previous high goes above the envelope
a sell signal is generated. Conversely, if the previous low goes below
the envelope a buy signal is given.
WARNING:
- For purpose educate only
- This script to change bars colors.
Combo Backtest 123 Reversal & Extracting The Trend This is combo strategies for get a cumulative signal.
First strategy
This System was created from the Book "How I Tripled My Money In The
Futures Market" by Ulf Jensen, Page 183. This is reverse type of strategies.
The strategy buys at market, if close price is higher than the previous close
during 2 days and the meaning of 9-days Stochastic Slow Oscillator is lower than 50.
The strategy sells at market, if close price is lower than the previous close price
during 2 days and the meaning of 9-days Stochastic Fast Oscillator is higher than 50.
Second strategy
Extracting The Trend
The related article is copyrighted material from Stocks & Commodities Mar 2010
WARNING:
- For purpose educate only
- This script to change bars colors.
Combo Backtest 123 Reversal & Ergodic TSI This is combo strategies for get a cumulative signal.
First strategy
This System was created from the Book "How I Tripled My Money In The
Futures Market" by Ulf Jensen, Page 183. This is reverse type of strategies.
The strategy buys at market, if close price is higher than the previous close
during 2 days and the meaning of 9-days Stochastic Slow Oscillator is lower than 50.
The strategy sells at market, if close price is lower than the previous close price
during 2 days and the meaning of 9-days Stochastic Fast Oscillator is higher than 50.
Second strategy
r - Length of first EMA smoothing of 1 day momentum 4
s - Length of second EMA smoothing of 1 day smoothing 8
u- Length of third EMA smoothing of 1 day momentum 6
Length of EMA signal line 3
Source of Ergotic TSI Close
This is one of the techniques described by William Blau in his book "Momentum,
Direction and Divergence" (1995). If you like to learn more, we advise you to
read this book. His book focuses on three key aspects of trading: momentum,
direction and divergence. Blau, who was an electrical engineer before becoming
a trader, thoroughly examines the relationship between price and momentum in
step-by-step examples. From this grounding, he then looks at the deficiencies
in other oscillators and introduces some innovative techniques, including a
fresh twist on Stochastics. On directional issues, he analyzes the intricacies
of ADX and offers a unique approach to help define trending and non-trending periods.
WARNING:
- For purpose educate only
- This script to change bars colors.