SIMPLE CANDLESTICK PATTERN ALGO BACKTESTING - TESLA 4HMany traders spend a lot of time to create algorithms full of unrealistic and far from reality indicators and market conditions. With this script I want to help traders understand the advantage of the Pine language. Using indicators with no statistical foundation and creating algorithms with technical indicators and thousands of conditions is not always the right way to create an efficient tool.
With this script that we have called "SimpleBarPattern_LongOnly" we analyse the market through a simple condition, using bars or candles.
How it works
The condition is constructed as follows. You go long with 100% of the established capital and 0.03% commission. The first condition is that the minimum of the period under analysis falls below the opening level. The second condition is that the low of the period is below the low of the previous period. The third condition is that the close of the period is above the opening level. The final condition wants the current close to be higher than the previous open and higher than the previous close. We used a statistical approach in the creation of this script, some candlestick patterns that reflect these conditions are: Bullish Engulfing, Bullish Hammer and Morning Star .
This strategy aims to help traders make more accurate decisions while using candlesticks for their trading and scientifically demonstrates that candlesticks are valid statistical tools for financial analysis.
"SimpleBarPattern_LongOnly" is a very lightweight script created with Pine v5. We developed a user interface that can adjust the analysis period from a few days to several years.
The initial capital set is €1,000 (You can change this from the "Properties" section of the user interface).
Each individual trade uses 100% of the set capital, in this case €1,000.
The default commission per trade is 0.03% (You can change this in the "Properties" section of the user interface).
User Interface
1) General backtest time settings: Set the history period to be analysed
StartDate: backtest start date
StartMonth: backtest start month
StartYear: backtest start year
EndDate: backtest end day
EndMonth: backtest end month
EndYear: backtest end year
3) Stop Loss
4) Take Profit
Please do not hesitate to contact us for any questions or information.
Disclaimer
Be careful, the past is not a guarantee of future performance, so remember to use the script as a pure analysis tool. The developer takes no responsibility for any use other than research and analysis and can in no way be held liable for damages resulting from wrong use of this code.
Scripts
Cumulative RSI StrategyI suppose nothing drives a point home like a 10+ year backtest! A couple of weeks ago I published a custom indicator called the Cumulative RSI. This indicator was straight out of chapter 9 of "Short Term Trading Strategies That Work." Today I am publishing a basic sample strategy in that uses the Cumulative RSI as its only entry and exit signals on a Nasdaq 100 leveraged index ETF (TQQQ). In this example, the indicator is being used as a longer term strategy with just 10% leverage over the account equity and a $25k start balance.
If I had it 10 years ago I would probably be retired! I'm sharing because I've found that it can provide an edge when determining exit/take profit points for trades. Many traders wait for a price reversal / trailing-stop to exit a trade when it starts losing. I've found that, using tools like the Cumulative RSI, you can achieve better exit points over the long term. Disclaimer: Even though this example significantly beats buy and hold, I wouldn't advise using it as a stand-alone strategy without significant additions/modifications to strategy and risk management functions.
Keltner Channels times 4!Have you always wanted the ultimate MOMO buying script? Well here you go, KC stacked on top of one another.
As Trump would say,
ENJOY!
RedK_Directional Index / K xDMIHere's a modern take on the famous DMI/ADX. i first wrote this on another platform few years ago, so i'm happy to be able to share it on TradingView
quick refresher: what does DMI/ADX tell us:
------------------------------------------------------
in simple terms, at the core of this indicator, there are 3 main calculations / lines: the Plus Directional Index ( +DI ) which represents how much the bulls are able to push the high of a bar compared to previous one, the Minus Directional Index ( -DI ), showing how much the bears are able to push the low of a bar from previous one, then the Average Directional index ( ADX ) line, which creates an oscillator of the +DI and -DI to represent the strength of a trend -- usually the lines will be colored accordingly (bulls = green, bears = red, and any different color for the ADX )
Similar to my version of the RSI , we take a classic concept, then use the computing and visualization "super powers" available to us today, to extend and improve on what those masters created in the past. I guess they sort of expected us to do exactly that :)
this "extended" version of DMI/ADX provides couple of highly needed features (in my opinion) -- let's explore:
trying as much as possible to avoid jargon - pls forgive me if i failed in some places.
-------------------------------------------------------------------------------------------------
1 - the big change: the ability to visualize the ADX in a way that makes some more sense.
- the original calculation restricted the ADX to oscillate below zero - i'm sure they had a good reason to build it that way in the past - but to me, it becomes super hard to interpret what the ADX line means, especially when a negative trend (the bears) take over. by removing that restriction and allowing the ADX to oscillate up or down (and we're free to do that, so the indicator shows *us* what *we need* to see), we end up with an improved representation of the trend and the trend strength.
- also the original calculation applies a moving average (default 14 bars) of a moving average (another 14 of the Directional Indexes, which represent the strength of bulls vs bears) to calculate the ADX - that makes the ADX very "removed" from the base price values - i change that, and just smooth the initial +Di / -Di then calculate the ADX from there. again, this shows me the outcome of the (relatively) immediate moves.
2 - i use weighted average WMA () in all my averaging calculations .. i believe this type of average is the best to express the importance of recent days / bars vs the ones further in the past, compared to other averaging techniques
3 - ability to make the DMI volume-weighted .. but contrary to my RSI , this is not set by default.
4 - couple of options to view the unrestricted ADX (as an area or as histogram/columns .. which i call Vertical Bars) for improved visualization
other stuff:
5 - a "step" option for the ADX .. you can set the step option to an increment of, say 5 or 10. this is in case you prefer to see the trend more in "quality" terms - so the equivalent of weak, medium, strong, v. strong...etc -- since in reality, a number like 47.7683 doesn't really mean anything specific
6 - optional "strong trend" adjustable level
Settings & usage suggestion:
-----------------------------------
i prefer to use the defaults (length = 7, smoothing = 3, ..etc) -- i believe these are more suitable to the much faster trading that we have now. you can review the comparison chart and see if this works for you, and adjust as you need.
from a "signal" standpoint, you can use the xDMI as you use the classic DMI/ADX, bulls (or bears) are in control when the corresponding DI line crosses the other going up, *AND* moving above the "strong trend" level that you can set as an extra filter (usually a value between 20 to 30), while ADX will show the quality/strength of the trend.
i suggest you also utilize this indicator with other trend / momentum confirmation methods, and additional analysis and not in isolation - as well as inspecting the prevailing / longer time frame to ensure you're acting in the direction of the broader move / trend.
the above chart includes a side-by-side comparison between our new xDMI with the classic DMI/ADX using the same settings - then we add at the bottom panel also the xDMI, but with my default (faster) settings and showing other visualization options that can be utilized - the Moving Averages on the top / price panel is just to help put the price movement into perspective in terms of trend and trend strength.
The code is open and commented - please feel free to use, share, comment & provide feedback. if you're a DMI fan, and you find this useful in your trading, i would be more than happy to hear about it
Good luck!
SimpleCrossOver_BotThis is a simple example of how you can compile your own strategy
This script contains the code for alerts and for backtesting.
In order to use the backtester, comment out the sections to be used for signals, and comment in the sections to be used on the back tester, and visa versa for using the script for alerts in order to automate your own bot.
Heffae Resolution Commander (RAW)This is a script to call resolutions with some math on top of your base resolution.
Using the modulo operator to quantize integer values, it works by converting the modified resolution integer to a 4 digit string value.
Use the function within your own scripts to call funny resolutions otherwise difficult to calculate.
You cannot add series expressions to the resolution value since pine does not allow "series" as a resolution for a security call
However, you could easily stack a crapload of these together and use an expression to switch the referenced security function for your purposes.
This is the raw timeframe output as integer, not string.
To go back to string outputs (for use in security calls etc) unslash line 52 //resvalue
For those interested in the verbose version of the timeframe mod function, showing all the steps, here is a pastebin:
pastebin.com
Cheers! Drop a line / comment if you enjoy or have any questions on how to integrate this into your script@!
The Modulo operator is so much fun!
Heffae Resolution CommanderThis is a script to call resolutions with some math on top of your base resolution.
THIS IS NOT AN INDICATOR TO USE ON A CHART!!! The resolution call function is really useful for your own scripting ideas!
Using the modulo operator to quantize integer values, it works by converting the modified resolution integer to a 4 digit string value.
The function within this script is what is valuable, use it within your own scripts to call funny resolutions otherwise difficult to calculate.
You cannot add series expressions to the resolution value since pine does not allow "series " as a resolution for a security call
However, you could easily stack a crapload of these together and use
an expression to switch the referenced security function for your purposes.
The SMA and plot overlay are just there to show a visual example of how the function works.
You can view the raw timeframe output integer by getting rid of tostring(x) and // out the security calls,
plotting the raw function outputs.
For those interested in the verbose version of the timeframe mod function, showing all the steps, here is a pastebin:
pastebin.com
Cheers! Drop a line / comment if you enjoy or have any questions on how to integrate this into your script@!
The Modulo operator is so much fun!
Fibonacci Exponential Moving Averages ( EMA )Here you can have 4 EMA on one indicator. The inputs are for 8, 13, 21 and 55 previous open&close which are from Fibonacci sequence.
How to : To use the script, click on "Add to Favourite Scripts", then load the script from Indicators on the Chart.
Currency Relative Strengths [GM] - Data IndicatorI created this tool for the purpose of determining strongest and weakest currencies over different periods of time. Each major currency is compared to the field of other majors and its average change is measured over a predetermined period of time. The result is displayed as a percentage. I use it for trend following but it can also be used to fade exhaustion.
Instructions
Add indicator to chart
Select a time frame under settings
Place cursor over period of interest
Click "Data Window" on right hand side bar
View % change avg values for each currency
UPdate Intraday TS ,BB + Buy/Sell +Squeeze Mom.+ adx-dmiUpdate version with legend on data window and new colors on the squeeze mom idicator
Intraday TS ,BB + Buy/Sell +Squeeze Mom.+ adx-dmiIntraday 5+ min indicator/strategy. Mix of indicator as BB, Ema , Roc , adx/dmi with buy and TP/SL point. All in 1 indicator easy to use . Just look the color chnge and the shape add the the bars
MACD, backtest 2015+ only, cut in half and doubledThis is only a slight modification to the existing "MACD Strategy" strategy plugin!
found the default MACD strategy to be lacking, although impressive for its simplicity. I added "year>2014" to the IF buy/sell conditions so it will only backtest from 2015 and beyond ** .
I also had a problem with the standard MACD trading late, per se. To that end I modified the inputs for fast/slow/signal to double. Example: my defaults are 10, 21, 10 so I put 20, 42, 20 in. This has the effect of making a 30min interval the same as 1 hour at 10,21,10. So if you want to backtest at 4hr, you would set your time interval to 2hr on the main chart. This is a handy way to make shorter time periods more useful even regardless of strategy/testing, since you can view 15min with alot less noise but a better response.
Used on BTCCNY OKcoin, with the chart set at 45 min (so really 90min in the strategy) this gave me a percent profitable of 42% and a profit factor of 1.998 on 189 trades.
Personally, I like to set the length/signals to 30,63,30. Meaning you need to triple the time, it allows for much better use of shorter time periods and the backtests are remarkably profitable. (i.e. 15min chart view = 45min on script, 30min= 1.5hr on script)
** If you want more specific time periods you need to try plugging in different bar values: replace "year" with "n" and "2014" with "5500". The bars are based on unix time I believe so you will need to play around with the number for n, with n being the numbers of bars.
No Volume SVAPO [LazyBear]This is a no-volume version of Vervoort's SVAPO. The original version is @
Since it doesn't include volume in its calculations, you can use this on FX.
More info on SVAPO:
More info:
stocata.org
stocata.org
BTW, this is my 150th script. Plenty more to come, my to-publish queue is still full of new stuff :)
For a complete list of my other indicators, do check out the links below:
- GDoc: docs.google.com
- Chart:
Indicator: Weis Wave Volume [LazyBear]This indicator takes market volume and organizes it into wave charts, clearly highlighting inflection points and regions of supply/demand.
Try tuning this for your instrument (Forex not supported) by adjusting the "Trend Detection Length". This "clubs together" minor waves. If you like an oscillator-kind-of display, enable "ShowDistributionBelowZero" option.
Note: This indicator is a port of a clone of WeisVolumePlugin available for another platform. I don't know how close this is to the original Weis, if any has access to it, do let me know how this compares. Thanks.
More info:
weisonwyckoff.com
Complete list of my indicators:
RSI Bands, RSI %B and RSI BandwidthRSI bands provide an intuitive way of visualizing how the price movement causes RSI to move with in its range (0-100). Upper/Lower bands signify overbought and oversold levels respectively (Default: 70/30, you can customize them via options page). These bands closely match what Constance Brown explains in her book "Technical Analysis for the Trading Professional".
I have also coded up 2 scripts to visualize %B and Bandwidth, just as in BollingerBands. As you can see %B is equivalent to the actual RSI. Along with RSI_Bandwidth and %B, the bands convey a lot of information.
Another tip is to render Bollinger Bands along with RSIBands...endless possibilities :)
I have included all 3 scripts in the same chart, as they are all related. Since TradingView doesn't allow sharing more than one script in the same chart, you can only "Add script" RSI Bands.
If you want to use RSI %B and Bandwidth, follow this guide to "Make mine" this chart and get access to the source:
drive.google.com
For the complete list of my indicators, check this post:
Indicator: Premier Stochastic OscillatorThe PSO, developed by Lee Leibfarth, is a rewired version of a short-period stochastic. This provides a quick response to changes in market direction. This highly sensitive indicator allows for early anticipation of price turns and can be used to establish definitive trading zones that identify potential trading opportunities.
Rules as suggested by Mr.Lee:
For long trades:
(1) Premier stochastic crosses below 0.90
(2) premier stochastic crosses below 0.20
For short trades:
(1) Premier stochastic crosses above -0.90
(2) premier stochastic crosses above -0.20
More info on the trading zones and other nuances:
www.investopedia.com