Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Wikipedia.org/ Average directional movement index
This strategy based on ADX and DI technical indicators has been presented by J. Welles Wilder in his “New Concepts in Technical Trading Systems” book published in 1978. Wilder thinks that growing and high values of ADX show strong trend in the market and falling and low values indicate no trend at all.
We will try to build the strategy offered in Wikipedia.
For long positions
Buy if +DI > -DI and ADX is growing.
Close a position if +DI < -DI and ADX is falling down.
For short positions:
Open a short positon if +DI < -DI anf ADX is growing.
Close a short position if +DI > -DI and ADX is falling down.
The strategy is quite simple if we understand what is to grow and what is to fall down. If we have a look at the indicator chart, we can say that the indicator is growing here and here it’s values are falling down. But we can see it only using offline data and we don’t know what to expect in future. There can be several ways how to detect that the indicator is growing. For example, if the previous value of the ADX indicator is less than the current one, it obviously means that the indicator value has increased and it’s growing.We can write it down as ADX[i-1] < ADX. Or, for example, ADX[i-5]<ADX means that the current value is bigger than 5 bars ago and the indicator value has become bigger. But it doesn’t mean that three bars ago the indicator value was less than the current value. So our formula can look like this - ADX[i-5]<ADX[i-4] && ADX[i-4]<ADX[i-3] && ADX[i-3]<ADX[i-2] && ADX[i-2]<ADX[i-1] && ADX[i-1]<ADX. We see consequent growth in each and every bar of five. It doesn’t happen too often. Here we need to see if this condition can mean the end of growth. So in any case we should whether optimize the constant ADX > ADX[i-Constant] or just define by eye that the indicator value is growing. We can use an average ADX value to define the status of the indicator. SMAadx < ADX. There are many other ways as well, for example ADX > ADX[i-speed].
It means I use an indicator instead of a fixed bar. But there’s something to pay attention to here. In “Formula” and “Boolean Formula” blocks there’s a parameter “Start with”. We should set a bigger value here in this parameter than a possible value of the indicator. For example, if we optimize our strategy we can select a wide range of values for a constant, from 1 to 1000, and in “Formula” block we need to choose 1001 as a parameter value. Probably we need to smooth DI before we create a position opening condition or, as Wilder said, we need to consider an ADX value… if the indicator value is small, we cannot expect any trend in the market… there can be many other variants as well.
This strategy is just an example for TSLab learners. Good luck!
ADX.tscript Download the file. Click Lab in TSLab main menu, then choose Script manager. Click the Load from file button.
The relative strength index (RSI) — is a technical indicator used in the analysis of financial markets. It is intended to chart the current and historical strength or weakness of a stock or market based on the closing prices of a recent trading period. The indicator should not be confused with .
How exactly is RSI calculated in the program? It is easy to make sure that it is calculated exactly as described in wiki.
Finding positive (U) and negative (D) price changes.
Calculating the relative strength RS.
Based on the RS, the Relative Strength Index RSI is calculated.
The market is changing very quickly now. When the Author created the indicator, the market changes were slower and the author of the indicator used a two-week period.
To be closer to the author's calculations, it is enough to simply set a longer period on a one-minute chart, but, for the convenience of the calculation, you can use ready-made daily candles in the program by using the Compress block.
For a more detailed study of the RSI indicator calculation, you can download the demo algorithm
Download the file. In the program, open Lab | Scripts. Click the Load from file button.
Open the script for editing.
Thus, you can create algorithms for calculating indicators in the program.
The attached algorithm presents the calculation of the indicator and for comparison, the calculation of the indicator built into the program (RSIintegrated Block) is displayed on the chart. You can save your own calculation into a Self-made script.
To do this, click on the New indicator button in the Scripts window.
Please note!
The value of the created indicator is always output through the Return value block.
You can output only one value from one indicator.
There can be as many inputs as you want. They are performed using the Source Blocks.
The input to the indicator can be a number, like mine, and the indicator in the script can be used for any number.
You can also use a data source as an input. In this case, a specific bar value must be used in the indicator.
After closing the window with the indicator, the program will automatically create a self-made indicator.
The Custom folder will appear in the Script Editor Toolbar, and if there are no errors in the indicator, it will be available in this folder.
The Custom indicator can be used in any scripts you create.
In previous articles, examples were given of how you can switch from one calculation to another using an ordinary constant.
In this example, you can apply the same method. You can calculate several different averages for the indicator.
The wiki describes several signals for the indicator. Be sure to check them out if you are not already familiar with them.
For all signals, the following is true: if the indicator is high, then you should not buy, if the indicator is low, then you should not sell.
With short profit and stop loss, the price of which is calculated by trail stop in relative values.
Perhaps the momentum indicator should be added to the strategy, for entry points signals.
Parameter optimization was not carried out.
Please note! Demo materials and example scripts are intended only for learning TSLab.
(Download the file. In the TSLab program, open "Lab" -> "Script Manager" → Click the "Load from file" button).
(ES Chicago mini snp500)
These prices do not show typical distribution. But we are not interested in mathematical justification, we are interested in possible profit we can get. If we have a look at this picture showing typical distribution of random values, we can see that only 0.2 % of values are beyond these three deviations.
Probably we can see good points for entering a position. The zero is the place where our position can be closed, as it is where random values happen to be found more often. It means that probability that the next random value will be beyond these three deviations is only 0,2 %. I showed profit standard deviation of futures mini snp 500 based on offline data.
How can we forecast deviation? It’s not easier than to predict market trends. If deviation has increased significantly and reached 80% in relative values, most likely it will decrease soon. Deviation may have its trends as well. Deviation, exactly like market itself, may be analyzed with the help of technical analysis or SMA, EMA, JMA indicators. Deviation may have resistance, support and so on. I built SMA based on bar closing prices and then I built three standard deviation lines.
Let us get back to normal distribution. When a random value is beyond these three deviations, there is high probability that the next random value will be within three deviations and most likely will tend to zero in the distribution chart. In other words, when price is beyond three deviations, there is high probability, that it will start moving to its SMA. And if price is within three deviations it will most likely stay there. So I built a trading strategy. When it touches three standard deviation lines, a limit order is fulfilled, and I put take-profit SMA.
Pay attention, that the strategy gives positive results on various timeframes. Here are the results based on 5 and 10 minute timeframes including the broker commission.
So when you select a timeframe for calculating standard deviation, do it considering your trading idea. The robot will take decisions faster if we take a small timeframe to calculate deviation. If we use the number of deviations and SMA to optimize the strategy, we can get better results, but the idea itself gets lost, as my idea cannot be considered and the result will be based only on offline data. Here is a 5 minute chart example:
Download the file. Click Lab in TSLab main menu, then choose Script manager. Click the Load from file button.
As an example, ready-made blocks from the script were copied to the created indicator.
The ready-made indicator can be downloaded from the link:
In some scripts it is necessary to use one calculation, for example EMA, and in some another. In the formula, a small number will eliminate division by 0.
In the example, the following strategy is implemented: if the indicator is high, then we sell, if the indicator is low, we buy.
The second strategy : sell and close long if the indicator is high, and buy and close short if the indicator is low.
These parameter values result in placing orders on bar extreme values and they won’t ever be executed. Deviation can be significant when the market is in crisis. Most likely we need to take into consideration SMA in such strategies and we should not forget about stop-losses. This trading strategy is just an example helping you to study TSLab. Good luck!
Demonstration algorithm for calculating RSI
Self-made RSI indicator
Indicator with a built-in switching of averaging EMA, SMA or AMA
Strategy example
Strategy example
DISCLAIMER
Data, information, and material (“content”) is provided for informational and educational purposes only. This material neither is, nor should be construed as an offer, solicitation, or recommendation to buy or sell any securities. Any investment decisions made by the user through the use of such content is solely based on the users independent analysis taking into consideration your financial circumstances, investment objectives, and risk tolerance. Neither www.tslab.pro nor any of its content providers shall be liable for any errors or for any actions taken in reliance thereon.
This article presents examples of the implementation of algorithms and indicators using the TSLab visual script editor.
In order to run the example, you need:
Download a sample script to your computer.
Launch TSLab program.
Select the menu item Lab - Scripts
In the Scripts window click the Load from file button.
Go to the directory with the downloaded script. Select the required script and click on the Open button.
In the list of available scripts, select the loaded script and double-click on it with the mouse.
The examples of trading strategies written in the block programming visual editor.
For long positions:
Buy if +DI > -DI and ADX rises.
Exit position if +DI < -DI or ADX falls.
For short positions:
To enter a short position if +DI < -DI and ADX rises.
To close a short position if +DI > -DI or ADX falls.
Useful links
Download
If AroonUp is greater than AroonDown - enter the Long position and close the Short position; If AroonUp is lower than AroonDown - enter the Short position and close the Long position; If AroonUp and AroonDown approximately equal - this is a period of consolidation.
The consolidation filter for entering a position is based on the difference between two indicators, the Constant is used as the filter level
Useful links
Download
Buy when CCI rises above 100. Sell when the CCI falls below 100.
Sell (short) when CCI falls below -100. Close a short position when the CCI rises above -100.
Useful links
Download
Buy (open a long position, close a short position) when the Index of the commodity channel rises above zero.
Sell (close a long position, open a short position) when the CCI falls below zero.
Useful links
Download
The comparison of indicators:
CCI built-in the TSLab program
CCI indicator from wiki
Modified CCI indicator
Useful links
Download
If the price has significantly changed, the market is probably trending. If the bar is large and the price moved up, then buy, if the bar is small, then exit the position.
Correspondingly, use bars with a downward direction to enter a short position.
Useful links
Download
The strategy is based on the RSI indicator, if the indicator is high - sell; if the indicator is low - buy.
With a short profit and stop loss, the price of which is calculated by the trail stop in relative values.
Useful links
Download
Sell and close long if the indicator is high.
Buy and close the short if the indicator is low.
Useful links
Download
Illustrates the operation of the Compress block and the daily ranges of the indicator.
Useful links
Download
The upper limit of the channel 3*Standard deviations
The lower border of the channel is -3*Standard deviations from SMA
To enter the Short position, a limit order is placed at the level of the upper border of the channel.
Exit the positions with limit orders on the average SMA.
Useful links
Download
The system is based on the breakdown of the maximum and minimum price levels for the period.
When the current price breaks up the upper line of the channel Maximum For, enter the Long position
When the current price breaks down the lower border of the channel, enter the Short position.
Exit from a position is performed by using the OSMA indicator. The simultaneous existence of opposite positions is prohibited.
Useful links
Download
With a limited set of the maximum number of lots.
The example of using formula blocks and the EMA indicator. The example of using the "Change By" blocks.
Download
An example of a trading strategy.
This strategy is described in an article written by Yury Chebotarev and Sergey Yashin. This trading strategy is based on an idea that price makes a certain number of steps in a certain timeframe. If price has changed significantly, it means that this instrument is trending. If a bar is long, we buy, if a bar is short, we close our position. So we use downtrend bars to enter a short position. Realizing the strategy with a parameter could look very simple if we should only analyze bar size and then apply a very simple condition like bar size is being bigger or smaller than a constant.
The authors offer an interesting approach and the strategy is remarkable for its approach to parameter values. If an average value of the bar (H+L)/2 is lower than a certain value of Delta (L+∆), this bar has low market volatility and doesn’t deserve any trying to gain profit. If an average value of the bar (H+L)/2 is higher than Delta (L+∆), this bar has high market volatility, and we could try to enter a position to gain a short term profit.
If (H+L)/2 > L+∆, this is a signal to open a long position. This condition is also a condition for being in long positions for all bars. If (H+L)/2 ≤ L+∆, this is a signal not to open a long positions. The next picture shows when we should enter a short positions.
Let’s define a secondary factor for long positions: k=(close - open)/(high - low). And for short positions k=(open-close)/(high-low). The k factor varies from 0 to 1. If K=0, we can say that volatility is low. If k=1 the instrument is trending.According to this idea, if k=0, then ∆ should be big so that market entry condition couldn’t be executed. If k=1, then ∆ should tend to zero. Hence here is the formula ∆ = (high-low)*(1-k). So delta values are unique for each bar and shouldn’t be optimized. The authors think that parameter that should to be optimized are the biggest drawback of this trading startegy. As a rule the strategy gives good results for a certain period of time after it has been optimized, and then we need to search for new parameter values again. So it’s for sure better for a trader to build trading strategies where no parameter values are used or they do not influence a trading idea much and there is no need to optimize historical data. Most likely the authors did not take into consideration the Time parameter, the period of time when we watch the price changing, I mean the timeframe the bars are built on.
This is just an example of trading strategy for TSLab learners.
Good luck!
Strategy without parameters.tscript Download the file. Click Lab in TSLab main menu, then choose Script manager. Click the Load from file button.
Wikipedia Commodity channel index
Commodity Index indicator is very simple in fact, though it has such a fancy name. Indicators in TSLab are based on C#. For those who have programming skills we provide API and indicator code samples at our Forum. CCI is available in TSLab as other indicators as well, but I would like to demonstrate a self-made one built according to wiki formulas. It is very easy to build new indicators by means of TSLab. CCI consists of Typical Price and Simple Moving Average. TSLab already has all to create CCI, but I showed in the indicator how to create Typical Price and Simple Moving Average. I urge you to study indicators. Making changes to indicators, you get a chance to create a better one.
Here is a customized CCI indicator. I applied adaptive moving average instead of simple moving average. And I applied exponential average instead of typical price. The chart in the middle shows the original CCI and the self-made one. As you may see, their values are identical, as CCI in TSLab is done as it is described in wiki.
The lowest chart shows the customized indicator. It has clearly seen divergences.
Though it is not so unstable as the original one, it seems to be more flat. Wiki offers 2 types of strategies, saying that there are different points of view on this indicator. To build these strategies, I am going to use my customized indicator instead of the original one. Some people think that in case with long positions we should buy, when CCI is higher than 100 and sell, when it is lower than 100. And for short positions – Sell when CCI is lower than -100 and close a short position, when CCI is higher than -100. For example, this strategy doesn’t seem to be profitable with bitcoin at all.
Other people recommend using zero value as a signal calling this strategy Zero CCI. It means - buy (open a long position or close a short position), when Commodity Index is higher than zero or sell (close a long position, open a short position), when CCI is below zero.
Let’s build a script which comprises both variants and resolve the dispute by means of optimization. If we think a bit we can see that there is one more strategy besides these two, this is to use average of CCI instead of signal lines. And we can at least combine all three strategies together. For example, we can enter a position at about zero point. And close long positions when CCI crosses its average, when the indicator is higher than 100 and lower than -100 for short positions. My customized indicator won’t do for this strategy because of divergences. The original one won’t do either as it is not stable and there can be many false signals. Try to create an indicator as flat as mine or even better but with fewer divergences.
Good luck to everyone!
This is just an example of trading strategy for TSLab learners.
CCI_wiki.tscript CCI_custom.tscript CCI_wiki_custom_simile.tscript CCI_100.tscript CCI_Zero.tscript
Download the file. Click Lab in TSLab main menu, then choose Script manager. Click the Load from file button.
This indicator has been designed by Tushar Chande in 1995.
The gray line indicates the AroonUp, the red line indicates the AroonDown. The AroonUp shows the number of bars since a new maximum price value has been reached. (N the number of bars – H the number of bars after a new maximum) / N the number of bars) * 100%. N is a value of the indicator period, Н is the number of bars after a new maximum price value has been reached in the selected period. After the price has reached a new maximum value, the AroonUp is equal to 100% again. The AroonDown shows the number of bars since a new minimum price value has been reached. (The number of bars – the number of bars after a new minimum price value / the number of bars) * 100. Let’s have a look. If AroonUp is higher than the AroonDown we have a bull signal.
If the AroonUp is under the AroonDown – it is a bear signal. If the AroonUp and the AroonDown are almost equal, we can call it a consolidation period
The consolidation filter is based on the difference of two indicators. The higher the parameter value is, the stronger is the expected indicator signal to enter a position. Let’s exit our position using the feedback signals.
We can use the consolidation filter to exit our position. I used it in an additional formula, you can also add this condition to exit a position. Optimization done on the Tesla instrument showed a value of 300 for the Aroon (their parameters are bound) and 62% for consolidation. Optimization shows that if the difference between the values of the indicators is beyond 62% range, the strategy shows the best profitability.
This strategy is just an example and has been built for TSLab beginners.
Good luck!
Download the file. Click Lab in TSLab main menu, then choose Script manager. Click the Load from file button.
If an average value of the bar is higher than H-∆, (H+L)/2≥H-∆ this bar has low volatility. If (H+L)/2<H-∆, this is a signal to open a short position and at the same time it is a condition for being in a short position for all bars. ∆ means a certain critical price value here. If this value gets higher, the market begins forward movement. It can be seen in the bar itself.