Strategy TemplateTrying to include few basic things which is needed for strategy which can be used as template.
Few important components
Strategy parameters
Few important parameters include - initial_capital, default_qty_type, default_qty_value, commission_type, pyramiding and commission_value. All my strategies will have similar settings with initial captial set to 20000 to 100000. 100% of equity per trade with no pyramiding (set to 1) and minimal commission.
margin_long and margin_short can be used for leveraged trading. But, since we are not using pyramiding, it will make no effect.
Trade Limiting parameters
Two types of limiting is available in the scripts
Limiting trading direction : this is done through method strategy.risk.allow_entry_in and input parameter tradeDirection
Limiting trades to particular time window : This is achieved through adding start time and end time parameters of type input.time and check whether time is within this window
Custom Methods
customized security method to get higher timeframe data
customized moving average method to get moving average of any type
Custom Parameters
Moving average Type option list which I use quite often. Any strategy where there is need to use moving average, I try to scan through different moving average types and lengths to see which one is more appropriate for the given strategy. Hence, keeping this parameter in template to make it readily available when I start with new strategy
waitForCloseBeforeExit - this is used if trailing stop need to activated as soon as price hits the stop or only on close price. This is again something I switch quite often based on strategy. Hence, keeping this as part of the template.
Entry and Exit statements for long and short
These statements from line (57 to 62) can remain as is even with new strategy. Only thing to be set are variables - buyCondition, sellCondition, closeBuyCondition and closeSellCondition
Last but not the least
In pinescript, a long and short position cannot coexist in a strategy at any point of time. Any short positions created will automatically stop long positions and vice versa. Hence, it is important make short and long trades mutually exclusive. In this example, I have used 200 weekly moving average as trend bias. No short positions are taken when price is trading above 200 weekly moving average low/close and no long positions are taken when price is less than 200 weekly moving average high/close. Any rule built on top of this (In this case a simple supertrend rules) ensures that there are no conflicting signals and hence avoids confusing trades on the stratgy.
Template
Martingale TemplateA template example on how to apply the famous Martingale gambling strategy. When your strategy gets an exit signal for your long position that leaves you without profit, you re-enter on the next entry long condition with double the capital of the previous amount entered with. You keep doubling the amount of capital entered with until you finally exit with a profit. If the strategy isn't sound enough then it could take several attempts and it can take only as much as a dozen tries to eat away at all your capital as the capital required to double on the next entry increases greatly over time by consecutive products of 2.
The strategy used is just a simple moving average crossover, above the moving average is going long, below the moving average is going short. It can be replaced with whatever strategy that you want. The colored vertical bars show long and short positions and exits. The default option on the tick box under the settings show the number of attempts at entering before finally exiting with a profit, the other option shows the amount of capital it took starting from 1.
Ultimate Screener TemplateHello Traders
With the Ultimate Strategy Template , I shared a template to connect any indicator to this template and get backtesting results in less than a few minutes
Now sharing another template ... many traders ask me to develop for them a screener/scanner based on a custom indicator on TradingView.
The current TradingView screeners are great but don't allow for much customization; as we can only select pre-defined filters
I don't know when we'll be able to natively screen among hundreds of assets with a custom indicator... then.... I created this template for the time being.... which should
A whole new world
The Ultimate Screener Template screens over 38 securities.
What's very cool is that you'll only need to create 1 alert to scan over 38 securities: Explanation with this image here
I totally understand that not all TradingView accounts have a lot of alarms; with this template, you can multiply the number of custom alerts you're initially allowed to.
What if I need to set alerts on more than 38 securities?
Pretty straightforward... you can create alerts only if the indicator is added to your chart first.
So if you need let's say 100 securities, add this indicator 3 times on your chart (38*3 > 100) and then... edit the securities for your 3 indicators
How to update your Screener settings
Alert mode
As per Pinescript reference , this template allows setting the alert frequency
Possible values are:
- alert.freq_all (all function calls trigger the alert)
- alert.freq_once_per_bar (the first function call during the bar triggers the alert)
- alert.freq_once_per_bar_close (the function call triggers the alert only when it occurs during the last script iteration of the real-time bar when it closes).
All-time-high and All-time-low
This template shows how to capture ATH and ATL alerts across many securities
I used the functions from Quantnomad:
Whenever a new ATH or ATL is made, the screener will send a personalized alarm with a personalized text based on the security triggering this alarm
The code is pretty straightforward and shows you the part you'll need to update to transform your favorite custom indicator into a powerful screener.
If anything is unclear in the code, please leave a comment and I'll respond as soon as possible
All the best
Dave
Risk Reduction Ultimate TemplateThis is a template not actually meant for trading. I picked two random oscillators. This is a template meant to turn into a live trading strategy, however.
It's literally just a specialized take profit/stop loss system. It is to ensure your bot doesn't make any bad moves that you wouldn't have manually. The code should be pretty well annotated. Putting this into my scripts has made them much better. I will work on a Multiple Trigger template next.
Realtime All-Time High and All-Time Low Tracker [WIP]This is a study intended to port the work of /u/QuantNomad's "Kozlod - All-time high/low alerts" to pine version 4 without giving any alerts. It is intended to capture the most extreme points on any given price chart in real time, the absolute high and absolute low points. Ideally, the plotted lines would strictly diverge from one another in opposite directions and widen with new highs or lows on a hypothetical "all-time" resolution.
Most of the original code was replaced and I'm trying to resolve a bug where the script fails to register new highs or lows while at the same time making sure that earlier data is plotted correctly. If applied to an asset that has not yet recovered , is just too new, or has not achieved a lower low than its opening price, this indicator ceases to function correctly. This would not be an issue if pine script was more general purpose and had something similar to Python's max(list) function.
Any and all suggestions are welcome. This is simply to serve as a springboard for any programmers trying to design algorithms or strategies that use these variables on any price chart.
Happy Hunting!
- Patch Hemlock
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
Strategy Template[Benson]A strategy template with following user inputs:
1. backtest start date
2. tp% and stop loss%
3. trail stop price and trail stop offset
The long and short condition is ma crossover and corssunder by default.
You can change the logic with your own.
[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
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
Line & Label RGB Color Editor [DW]This script is a template designed to provide developers with UI color customization for v4 lines and labels.
The color pallete used within this script is a full spectrum "web safe" format with 216 colors to choose from.
Colors are easily modified via the RGB inputs. The designated color selector function takes in the RGB values and returns the corresponding hex color.
Transparency can be modified as well. However, the color.new function only supports constant integers for transparency value, so it has to be manually adjusted within the code.
On line 42, you'll see a variable within the color selector function named trans. This is the transparency value, which can be set to any integer from 0 to 100. I have it set to 0 by default.
I included a sample label to demonstrate how the color editor works. It also displays the hex codes for the current label and text colors for some additional reference.
Implementing this in your own script is pretty straightforward.
All you need to do is copy the color selector function and inputs (feel free to name them whatever you want) into your desired script. Then, you can use them to declare your color variables.
NAND PerceptronExperimental NAND Perceptron based upon Python template that aims to predict NAND Gate Outputs. A Perceptron is one of the foundational building blocks of nearly all advanced Neural Network layers and models for Algo trading and Machine Learning.
The goal behind this script was threefold:
To prove and demonstrate that an ACTUAL working neural net can be implemented in Pine, even if incomplete.
To pave the way for other traders and coders to iterate on this script and push the boundaries of Tradingview strategies and indicators.
To see if a self-contained neural network component for parameter optimization within Pinescript was hypothetically possible.
NOTE: This is a highly experimental proof of concept - this is NOT a ready-made template to include or integrate into existing strategies and indicators, yet (emphasis YET - neural networks have a lot of potential utility and potential when utilized and implemented properly).
Hardcoded NAND Gate outputs with Bias column (X0):
// NAND Gate + X0 Bias and Y-true
// X0 // X1 // X2 // Y
// 1 // 0 // 0 // 1
// 1 // 0 // 1 // 1
// 1 // 1 // 0 // 1
// 1 // 1 // 1 // 0
Column X0 is bias feature/input
Column X1 and X2 are the NAND Gate
Column Y is the y-true values for the NAND gate
yhat is the prediction at that timestep
F0,F1,F2,F3 are the Dot products of the Weights (W0,W1,W2) and the input features (X0,X1,X2)
Learning rate and activation function threshold are enabled by default as input parameters
Uncomment sections for more training iterations/epochs:
Loop optimizations would be amazing to have for a selectable length for training iterations/epochs but I'm not sure if it's possible in Pine with how this script is structured.
Error metrics and loss have not been implemented due to difficulty with script length and iterations vs epochs - I haven't been able to configure the input parameters to successfully predict the right values for all four y-true values for the NAND gate (only been able to get 3/4; If you're able to get all four predictions to be correct, let me know, please).
// //---- REFERENCE for final output
// A3 := 1, y0 true
// B3 := 1, y1 true
// C3 := 1, y2 true
// D3 := 0, y3 true
PLEASE READ: Source article/template and main code reference:
towardsdatascience.com
towardsdatascience.com
towardsdatascience.com
Hybrid Convolution FilterIntroduction
Today i propose an hybrid filter that use a classical FIR architecture while using recursion. The proposed method aim to reduce the lag generated by fir filters. This particular filter is a sine weighted moving average, but you can change it since the indicator is built with the custom filter template (1). Even if it use recursion it still is a FIR filter since the impulse response is finite.
The Indicator
In red the hybrid swma and in blue the classic swma of both the same period. The difference can be seen.
The switch between the input price and the past values of the previous convolution values is made by using exponential averaging, the window function is the same as f(x) in the code.
Any filter can use this architecture, the indicator is built around the custom fir template, see (1)
Conclusion
I presented a FIR filter using recursion in its calculation, the integration is made with respect to the proposed template, therefore any user can simply modify f(x) to have different filter without the need to make any change. However curious users might want to change the window function of the exponential averager, in order to do so change sgn = f(i/length) in line 11 for sgn = fun(i/length) where fun is your custom function, make sure to add it at the start of the script where all the other functions declarations are.
Thanks for reading !
(1)
Template For Custom FIR Filters - Make Your Moving AverageIntroduction
FIR filters (finite impulse response) are widely used in technical analysis, there is the simple or arithmetic moving average, the triangular, the weighted, the least squares...etc. A FIR filter is characterized by the fact that its impulse response (the output of a filter using an impulse as input) is finite, this mean that the impulse response won't have infinite outputs unlike IIR filters.
They are extremely simple to design to, even without the Fourier transform, this is why i post this template that will let you create custom filters from step responses. Don't hesitate to post your results.
How It Works
Originally you create your filters from the frequency response you want your filter to have, this is because the inverse Fourier transform of the frequency response is the filter impulse response.
After that step you use convolution (convolution is the sum of the product between the signal and the impulse response) and you will have your filter. But we don't have Fourier transforms in pine so how can we possibly make FIR filters from convolution ? Well here the thing, the impulse response is the derivative of the step response and the step response is the sum of the impulse response, this mean we can create filters from step responses.
Step response of a moving average.
Step responses are easy to design, you just need a function that start at 0 and end up at 1.
How To Use The Template
All the work is done for you, the only thing you need to do is to enter your function at line 5 :
f(x)=> your function
For example if you want your filter to have a step response equal to sqrt(x) just enter :
f(x)=> sqrt(x)
This will give the following filter output :
You can create custom step responses from online graphing tools like fooplot or wolfram alpha, i recommend fooplot.
You can also design your filter step response from the line 14/15/16, b will be your filter step response, just use a , for example b = pow(a,2) , then replace output in plot by b and use overlay false, you can also plot step , if you like your step response copy the content of b and paste after f(x) => .
Filter Characteristics
The impulse response determine how many of a certain signal you want in your filter, this is also called weighting, you can think of filter design as cooking where your ingredients are the the signal at different periods and the impulse response determine how many of an ingredient you must include in the recipe. The step response can also tell you about your filter characteristics, for example :
This one converge faster to the step function, this mean that the filter will have less lag.
However this one converge slower to the step function, this mean the filter might have more lag but could be smoother.
Be aware that you must find a good weighting balance, else you can have output equals to the signal or just a delayed version of the signal without smoothing.
Real Case
Lets design a sine weighted moving average (swma), this FIR filter use the first 180 degrees of a sine wave function as impulse response.
Impulse response of the swma.
We can design it from the step response without much problems, remember that the impulse response is the derivative of the step response, therefore the derivative of the step response is equal to the first 180 degrees of a sine wave, the derivative of the cosine function is a sine function, therefore :
f(x)=> .5*(1 - cos(x*pi))
And voila.
Designing A BandPass Filter
The bandpass filter like a low-pass and high pass filter, you can think of it as a smooth oscillator.
To design a bandpass filter your step response must be bell shaped, or starting at 0 and ending at 0, for example :
f(x)=>sin(x*pi) give :
Conclusion
Just use fooplot and experiment, you could get nice filters, i will try to post some using this template but it would be really nice to have other people use it. If you need further help pm me.
Thanks for reading !
[Autoview][BackTest] Blank R0.13BThis is a fork of JustUncleL's
Dual MA Ribbons R0.13
It is now a blank template for making new strategies / alerts for autoview
The changes are as follows:
Removed actual algo
Establish functions for long Signal, long Close Signal and short Signal, short Close Signal to minimize the places code must be edited to update / replace algos
Make allow Long and allow short and invert trade directions independent options
Added support for alternate candle types
Added autoset backtest period feature, and optional coloring
Moved strategy calls in to functions so they can all be commented out or activated / disabled in a single block at the top of the script
[Autoview][Alerts]Blank R0.13BThis is a fork of JustUncleL's
Dual MA Ribbons R0.13
It is now a blank template for making new strategies / alerts for autoview
The changes are as follows:
Removed actual algo
Establish functions for long Signal, long Close Signal and short Signal, short Close Signal to minimize the places code must be edited to update / replace algos
Make allow Long and allow short and invert trade directions independent options
Added support for alternate candle types
Added autoset backtest period feature, and optional coloring
Moved strategy calls in to functions so they can all be commented out or activated / disabled in a single block at the top of the script
Default Strategy Inputs (Forex / Crypto)The code in this post contains a set of default strategy inputs I use in new projects / backtests in Tradingview.
Full code commentary is available on the Backtest-Rookies website. To comply with house rules, I cannot post the direct link here.
Features
Trade Direction: So that you can limit the strategy for long only, short only or trade in both directions. It is important to note that when you select “Long Only”, you will still see Short signals on the chart. However, they are only used to close a position rather than reverse it. This is the default behaviour for strategies. The same applies to “Short Only”.
Date Ranges: So that you can isolate backtesting to specific periods of interest such as bull or bear markets.
Sessions: So you can easily get an idea of the expected results during your own session. You may also notice that performance of the strategy varies depending on which session it is deployed in.
Some example stop losses: It is not an exhaustive list but it should be enough to provide some inspiration for different types of stops that you can experiment with.
Happy Scripting. I hope the community finds it useful.