Let’s consider a robot that trades non-standard candles. In the project, it’s called VolatilityAdaptiveCandlesTrader.
The essence of this robot is that it enters a position when it sees a candle sized at a certain % of the average intraday volatility. It's relevant to test and trade with candle types RangeAdaptive and ReversAdaptive, so the candle size is also adaptive.
This way, you can test and trade impulses tied to the volatility of instruments:
1. Example in the project.
The VolatilityAdaptiveCandlesTrader robot is located within the OsEngine project. Open it and go here:
2. Parameters of the candles.
Tests of this robot need to be conducted on tick data to utilize custom candle types.
For tests, we select such candles:
These are reverse adaptive volatility candles that adjust their height depending on volatility and close after a significant pullback, i.e., sometimes forming very long, uninterrupted candles.
3. Robot parameters.
1. Regime – operating mode.
Off – Disabled.
On – Enabled and will enter both long and short.
OnlyLong – Enabled and will only go long.
OnlyShort – Enabled and will only go short.
OnlyClosePosition – will only close a position without entering.
2. Volume type – volume selection mode.
Contracts – number of contracts of the instrument.
Contract currency – currency of the contract.
Deposit percent – percentage of the deposit.
3. Volume – volume value. What exactly depends on the previous point. In the case of Contracts, the volume of the instrument is specified here. In the case of Contract currency, the number of rubles or dollars to enter is specified here. In the case of Deposit percent, the % of the total deposit to enter the contract is indicated here.
4. Asset in portfolio – here you need to indicate the currency name that will be used for volume calculation if you selected the "Deposit percent" volume type. In the tester, leave “Prime.” In crypto, this is usually “USDT.” In ALOR, it’s “RUB.”
5. Slippage % – slippage for order prices.
6. Height signal candle % – the total height of the candle after which we consider it possible to enter a position.
7. Trail stop % – the size of the trailing stop.
8. Days volatility adaptive – the number of days for which we take average volatility.
9. Height signal candle volatility – what part in % of the average intraday volatility will be the new height of the signal candle after adaptation to volatility.
10. Height trail stop volatility percent – what part in % of the average intraday volatility will be the new value of the trailing stop after adaptation to volatility.
4. Logic for entering and exiting positions.
LONG
Entry if we accumulated a total upward movement over the candle, “Height signal candle %.”
SHORT
Entry if we accumulated a total downward movement over the candle, “Height signal candle %.”
Exit is made by trailing stop, readjusting at the end of each candle, from the close by the amount of Trail stop %.
5. Logic for adapting the dimensions of signal candles to volatility.
The adaptation logic is triggered every morning of the day. In the robot, this method is AdaptSoldiersHeight:
There are three stages:
1. Calculate intraday volatility in percentage over the specified number of days.
2. Average this value.
3. Calculate new values for the height of the signal candle and stop.
6. What about profit?
There is some potential, but it clearly requires more than one day of testing and performing cross-tests afterward to ensure the volatility settings are robust. On Sber, it looks like this:
Good luck with algorithms!