[fareid] Quick Backtest Framework█ OVERVIEW
This Framework allows Pine Coders to quickly code Study() based signal/strategy and validate its viability before proceed to code with more advance/complex customized rules for entry, exit, trailstop, risk management etc..
This is somewhat an upgraded version of my earlier personal template with different strategy used, cleaner code
and additional features.
█ USE CASES
- You have an idea for trade signal and need a quick way to verify its potential before writing lengthy/complicated code
- You found a study script for trading signal in public library and want to validate it profitability with minimum effort before including it in your trading playbook
█ FEATURES
- Alert: Ready to use alert function based on signals from your custom indicator.
- Visual Backtest: Auto-plot entry, stop-loss and take profit for simple strategy performance analysis
- Backtest Statistic: Provide basic key metrics based on backtest strategy
- BTE External Signal Protocol: Ready to use code that will supply required state to PineCoders Backtesting & Trading Engine if you wish to have more advance and sophisticated backtesting engine
Notes: All of the above features have On/Off toggle
█ Description & How To Use
This Framework consist of 5 Modules but you only need to edit the first 2 Modules:
Module1: Indicator
Module2: Framework Input Protocol
Module3: Alert
Module4: Backtest
Module5: Backtest & Trading Engine
Tips: The source-code includes collapsible block by module for easy navigating
Module1: Indicator:
-----------------------------------------------------------------------------------
Main Module. Place custom indicator input parameter/calculation/indicator plotting here
Sample Strategy: Double MACD Crossover
MACD Signal: 1st MACD Cross above signal line indicate Buy Signal
1st MACD Cross below signal line indicate Sell Signal
MACD Filter: 2nd MACD is above 0 line indicate Uptrend
2nd MACD is below 0 line indicate Downtrend
Module2: Framework Input Protocol:
-----------------------------------------------------------------------------------
Use this module to connect main indicator/signal calculated in Module1 to the rest of the framework's module
4 variables needed to be defined here:
1. Uptrend
2. Dntrend
3. BuySignal
4. SellSignal
i'm not sure how to place a code snippet here to show you example so in the source code i already put a comment in Module2 on which part u need to edit. I hope its pretty simple to use.
Module3: Alert Module Description:
-----------------------------------------------------------------------------------
As long as the variables in Module2 properly defined, the alert module is ready to use without any further modification.
Input:
Enable Alert --> Enable TV's alert and plot signal to chart
Alert Type --> Set to take Buy only, Sell only or Both alert
Module4: Backtest Module Description:
-----------------------------------------------------------------------------------
As long as the variables in Module2 properly defined, the backtest module is ready to use without any further modification.
Input:
Backtest Stat --> Enable Backtest Statistic Label
Backtest Visual --> Enable Backtest visual simulation
Backtest Type --> Set to take Buy only or Sell only or both
SL Type -->
ATR : Set SL in ATR times Multiplier below 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 Multi --> Set Lookback Period used for SL's ATR calculation
SL ATR Multi --> Set ATR Multiplier for SL
SL Fixed --> Set Fixed Level for SL
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
Module5: Backtest & Trading Engine Description:
-----------------------------------------------------------------------------------
As long as the variables in Module2 properly defined, the Pinecoders BTE module is ready to use without any further modification.
Input:
External Signal Protocol --> Set ESP State to send to "Backtesting & Trading Engine "
Signal With Filter --> Use this to send entry signal that already filtered by this study indicator (without stoploss level)
Signal Without Filter --> Use this to send raw entry signal that are NOT YET FILTERED by this study indicator (without stoploss level)
Signal and Stop With Filter --> Use this to send entry signal WITH StopLoss that already filtered by this study indicator (with stoploss level)
Signal and Stop Without Filter --> Use this to send raw entry signal WITH StopLoss that are NOT YET FILTERED by this study indicator (with stoploss level)
Notes: Backtesting & Trading Engine already have built-in Filter, Entries and Stop Level. e.g. Unselect all their filter state if only want to use custom filter and make sure send Signal with Filter (with or without SL level)
█ DISCLAIMER:
This framework main objective is to create my personal indicator template so that i just have to modify the indicator module for preliminary testing in future.
The sample strategy included are for educational purpose only. Use at your own risk
credit: LucF/PineCoders for a lot of his scripts that i use as a guide to complete this
Currency
Mean Reversion Channel - (fareid's MRI Variant)Description :
Mean Reversion Channel objective, based on Mean Reversion theory ( everything has a tendency to revert back to its mean), is to help visualizing:
Inner Channel -> Dynamic Support and Resistance
Outer Channel -> Overbought/Oversold Zone which may signal consolidation phase or potential reversal due to unsustainable move
Details on some of the filtering type used for mean calculation can be read in Ehlers Technical Papers: "Swiss Army Knife Indicator" and/or his book "Cybernetics Analysis for Stock and Futures"
Disclaimer:
These study scripts was built only to test/visualize an idea to see its viability and if it can be used to optimize existing strategy.
Any ideas to further improve this indicator are welcome :)
Currency Group Stochastic (Dual Timeframe)
This is a stochastic for an entire currency group (majors and crosses). So if you are wondering whether the entire group will reverse this might help. For example, if you are think the USD group will roll over you can see an amalgamated stochastic of AUDUSD, NZDUSD, USDJPY, USDCHF, EURUSD, GBPUSD, USDCAD (average stochastic of all of them). The concept is that it might give help to identify 2 opposing currencies - an overbought currency verses an oversold currency.
Also, if your 'classic' instrument specific stochastic is showing an entry, does the the entire currency group agree?
There's more! You can also see the stochastic of the timeframe above on the current timeframe. You're current period stochastic tells you you've an entry and the stochastic from the timeframe above can indicate there is momentum in your direction. (There is a classic stochastic version of this on my profile)
There is a limit to how much I can fit into a single indicator so if you want to see the current and timeframe above together (recommended) you need to overlap the indicator on itself. See below
You can create a dashboard combined with 'currency relative strengths' (that indicator is on my profile) as per below. You now have an idea of the currency strengths, which currencies are correlating and potential turning point to help you decide which currencies to focus on...
Example...
gbp group COULD be ready to buy
chf group COULD be ready to sell
gbpchf - wait for the 3 min chart to roll over and an its not a bad call (considering it took 60 secs to review the market and choose an entry with the possible backing of the entire currency groups :o) )
REMEMBER, YOU CAN'T THIS TRADE FROM THIS INDICATOR. LOOK AT IT TO UNDERSTAND WHAT THE MARKET MIGHT BE DOING AND FOCUS YOUR DETAILED ATTENTION BASED ON YOUR CONCLUSION.
Good luck
S&P 500 Sector Strength IndexHi traders , this is lonelygrass again 😄, and I am going to show what you don't often see out there and share it with you.
This indicator is called "s&p 500 sector strength index"😎 , which allows you to distinguish strengths and weaknesses between different sectors in s&p500, and to create meaningful trading frameworks around it.
Similar to the RSI indicator , it also has overbought and oversold levels , you can clearly figure out the degree of crowd behaviors in various sectors' stocks .
For me 🤣, I will use it to "BUY LOW⬇️ , SELL HIGH⬆️". When a sector is oversold at the moment, I will try to buy those stocks when I find price actions and chart patterns in comply with the analysis by this indicator , the opposite for shortselling.
Also, for sake of being more user-friendly 👍, I added a function which enables you to only select the sector(s) you want to look at in order to make it less messy.
If you can't help to know what I will share with you coming up, then FOLLOW my account 😙 . Also , your likes and shares are really important 🎊. I will get more motivated to bring you new thing every day!!! ✍
Canadian Dollar Currency IndexCanadian Dollar Currency Index updates in real time and doesn't close like tradingview.com's currency indexes. Based off of the Bank of Canada's CEER methodology and tracks it quite closely, although not perfectly. It seems to be higher than the Bank of Canada's index by 2 points. This could be due to using different data for the currencies and as I am not proficient in PineScript, I don't think I was able to replicate the formula exactly...? Regardless ,it works well and is more than close enough to suit one's purpose of tracking the Canadian dollar against a basket of currencies that are weighted according to the Bank of Canada's total weights (The total weight of a country j in year t is a weighted average of the their import, export and third-market competition weights). For more information on the actual Bank of Canada's index: www.bankofcanada.ca
CSI - Currency strength indicator RSI 10This Indicator shows you the strength of the Currency in comparison for all other Main Currencys at the timeframe you choose.
The Currencys in this Indicator is: EUR, USD, GBP, CHF, AUD, CAD, JPY
The Base is the RSI (relative strength Indicator) with the following Currency pairs:
eurusd, eurgbp, euraud, eurjpy, eurcad, eurchf
usdeur, usdgbp, usdaud, usdjpy, usdcad, usdchf
gbpeur, gbpusd, gbpaud, gbpjpy, gbpcad, gbpchf
audeur, audusd, audgbp, audjpy, audcad, audchf
jpyeur, jpyusd, jpyaud, jpygbp, jpycad, jpychf
cadeur, cadusd, cadaud, cadgbp, cadjpy, cadchf
chfeur, chfusd, chfaud, chfgbp, chfjpy, chfcad
The letters in the LineChart:
EUR = E
USD = U
GBP = G
CHF = C
AUD = A
CAD = C
JPY = J
The CSI can help to see, if your trading pair have the potential to breakout on the support and resistance or if it more likely go back.
Some people say that the banks use this indicator.
NZD is missing there because Tradingview only support 6 variables.
If you have a solution for than, please let me know.
Thanks
Currency StrengthRepublished: The original script violated house rules by including an external link to Backtest Rookies.
Background
The currency strength indicator takes up to 4 forex pairs and calculates the average strength across all pairs. The indicator uses the pair's daily percentage change to calculate the overall strength. For flexibility, it can accept any instrument as an input. This means you can use multiple instances to track various currency strengths. It was designed with the major pairs in mind but there is no reason why it cannot be used for other FX pairs.
Note: The indicator defaults to GBP. When setting it up for other currencies, be sure to flag whether the currency is a counter currency or not.
The code is provided free and open source. Please modify it as you see fit.
Screenshots
Defaults with Annotation
Yen strength beating pound strength
Opposing Trends
Ichimoku Cloud Score v1.0This script calculates a simple Ichimoku Score based on the signals documented here , with a few additions. Each of the score components can be individually weighted via the script inputs . The output is a plot of the normalized Ichimoku score, in the range of -100 to 100.
This script has been heavily modified from 'Ichimoku Cloud Signal Score v2.0.0 '. Credit to user 'dashed' for the initial implementation.
This has been modified with several refinements:
Clean/Organized Code
Simplified Inputs
Improved Style
Scores normalized to a range (-100, 100)
Bugfixes and Improvements
Script Inputs: i.imgur.com
Convert Yuan value symbols to USDIGNORE PREVIOUS SCRIPT/POST (titled: "yuan normiz")
If you like to look add symbols that are valued in China's Yuan and want to convert them to USD accurately then this is the perfect script for you.
"I'm not sure if this script is for me. Does my setup apply here?"
If either of these resemble your chart setup then this is for you:
Example 1: You have COINBASE:BTCUSD on your main chart often add to compare Bitstamp:btcusd and Okcoin:btccny.
Example 2: You have SPY or SPX (or DJIA etc) as your main chart but like to add other composites to compare like SSE(Shanghai Stock Exchange index) to your main chart.
This takes the symbol of your choice (default is BTCCHINA:BTCCNY) that is expressed in Yuan and divides it by the corresponding value of IDC's USDCNH ticker. Not the last value of USDCNH, but the respective tick mark----BTCCNY's close 3 months ago is divided by USDCNH's close 3 months ago.
yuan normizapply to symbols expressed/valued in Chinese Yuan to automatically divide the symbol by FX:USDCNH. For example, I like to apply OKCOIN:BTCCNY to my main BTCUSD chart to compare, but I'd like to have the value for BTCCNY converted to USD for each tick---whether USDCNY was 6.30 or 6.80.
This is a very narrow use script designed to be applied on top of of symbols (press the 'apply indicator' + sign button)
Currency Strength IndicatorSimple but effective don't pay $300 for an MT4 indicator when you can use this for free. Feel free to make it your own!
[RS]Multiple Majors Currency Basket Power Oscillator V0Power oscillator to discern what currency's are stronger/weaker.
Currency Index Indicator The currency index represents the change in one currency by reference to all other
foreign currencies. The index is calculated by taking the average of the variations
in one currency by reference to the others. Represented in graphical form, it allows
for easy visualization of the individual trends in each currency.
The index of the currencies is a simple arithmetic average of the variation in each pair.
For each index, to have fixed the value 100 on 1 January 2000.