Update - Build 150
This build is intended to reduce the script compile time and thereby prevent timeout errors when applied to the chart. To accomplish this goal the script code was heavily refactored and some lessor used features were removed. Specifically, the following features are removed from this build:
– Volume Indicator
– Report Debt Reset
– Caution Lackluster Trades
As much as possible I tried to keep core functionality relevant to range trading. The intent of this tool is to experiment with different range trading configurations. The backtest can be setup to use DCA and variable leverage ratios to provide you with an overall picture of what to expect from your selected input parameters. I decided to keep the Sharpe Ratio and Rate of Return reports since those features are an important metric to fund managers and portfolio investors.
This script contains approximately 1800 lines of Pine 4 code which consists mostly of math calculations with very little plotting. Even with the feature purge and streamlining of the code the script still requires 1 minute and 50 seconds to initially load on the chart. TradingView does an excellent job of caching compiled Pine scripts so you will typically only incur the full compile the first time it is applied to the chart. Please wait for the hovering dots to disappear before clicking on the setting dialog icon.
New Inputs
Build 150 contains five new inputs which attempt to remedy problems reported during the ongoing beta test.
– Minimum Maturation
– Anti-chop Mode
– Follow Snap Direction
– Preserve Indebted Trades
– Mark Symbol Debt Sequence
Minimum Maturation
The “Minimum Long/Short Maturation” input supplies a value to the “Preserve Long/Short Maturation” checkbox. The two fields form an anti-cutoff mechanism effective only in “Ping Pong” mode. The longevity of the open position must exceed at least the number of bars designated by the minimum maturation value. “Ping Pong” mode will ignore position reversal signals until either the trade has exceeded the time specified or an outlier condition occurs.
Anti-chop Mode
The “Long/Short Anti-Chop” checkbox is intended to reduce position reversals after extreme price moves. Internally the scripts goes into a tug-of-war after the price has moved continuously in one direction. Since this is a range trading program, the natural tendency is for it to buy on weakness and sell on strength. However, the loss prevention logic of the script changes the trading bias according to price pressure. When enabled the “Anti-chop Mode” forces the script to counter trade exaggerated moves. During this time “Ping Pong” mode will ignore position reversal signals until the price has recovered. Please be advised that this feature may cause the backtest to sustain losses for the duration of a bull or bear run.
Follow Snap Direction
The “Follow Long/Short Snap Direction” checkbox is intended to reduce position reversals by adhering to the directional bias established by the most recent snap candle. When enabled new positions can only be created in the snap candle direction. The user can control the frequency of reversal by adjusting the snap candle magnitude. A larger snap candle may increase the accuracy of the backtest by sacrificing the total number of trades. In this case, the gain of the backtest may also be reduced.