The dual thrust trading algorithm. It is a breakout strategy developed by Michael Chalek that is commonly used in futures, forex, and equity markets. The dual thrust algorithm uses the historical price to construct and update the look-back period, which makes it more adaptable to changing market conditions.

The dual thrust algorithm calculates a trading range’s upper and lower rails based on the opening price and the previous N days’ price action. The algorithm generates a long signal if the price breaks above the upper rail. The algorithm generates a short signal if the price breaks below the lower rail.

The dual thrust algorithm is a reversal system, so if the trader is already in a position, the algorithm will generate a signal to close the position and reverse the direction.

Here is a step-by-step overview of the dual thrust trading algorithm:

- Calculate the upper and lower rails of the trading range:
- Upper rail = opening price + (trigger value * previous N days’ range)
- Lower rail = opening price – (trigger value * previous N days’ range)
- Trigger value is typically set between 2% and 5%

- Monitor the price action for breakouts:
- If the price breaks above the upper rail, generate a long signal.
- If the price breaks below the lower rail, generate a short signal.

- Enter and exit positions:
- If a long signal is generated, enter a long position.
- If a short signal is generated, enter a short position.
- If the trader is already in a position and a reversal signal is generated, close the position and reverse the direction.

It is important to note that the dual thrust trading algorithm is just a starting point. Traders should optimize the algorithm’s parameters for their trading style and risk tolerance. Additionally, traders should always use stop-loss orders to protect their capital.

Here are some of the key benefits and drawbacks of the dual thrust trading algorithm:

**Benefits:**

- Simple and easy to understand
- It can be used in a variety of markets
- Adaptable to changing market conditions
- Can generate both long and short signals

**Drawbacks:**

- Can be susceptible to false signals in choppy markets
- Requires traders to have a good understanding of risk management
- It can be time-consuming to monitor multiple markets

Overall, the dual thrust trading algorithm is a versatile and effective way to trade breakouts. However, using it in conjunction with other risk management techniques is important.

## The Maths

The maths behind the dual thrust trading algorithm is relatively straightforward.

**Step 1: Calculate the previous N days’ range**

The first step is to calculate the previous N days’ range, which is the difference between the highest and lowest prices over that period. This can be calculated using the following formula:

`Previous N days' range = Highest price - Lowest price`

**Step 2: Calculate the trigger value**

The trigger value is a percentage of the previous N days’ range used to determine the upper and lower rails of the trading range. The trigger value is typically set between 2% and 5%, but it can be adjusted depending on the trader’s risk tolerance and the market conditions.

**Step 3: Calculate the upper and lower rails**

The upper and lower rails of the trading range are calculated using the following formulas:

```
Upper rail = Opening price + (Trigger value * Previous N days' range)
Lower rail = Opening price - (Trigger value * Previous N days' range)
```

**Step 4: Generate trading signals**

A long signal is generated if the price breaks above the upper rail. A short signal is generated if the price breaks below the lower rail.

**Step 5: Enter and exit positions**

If a long signal is generated, the trader enters a long position. If a short signal is generated, the trader enters a short position. If the trader is already in a position and a reversal signal is generated, the trader closes the position and reverses the direction.

**Example**

Let’s say we are trading the S&P 500 futures contract with a look-back period of 20 days and a trigger value of 2%. The current opening price is 4000.00.

First, we need to calculate the previous 20 days’ range:

`Previous 20 days' range = 4100.00 - 3900.00 = 200.00`

Next, we calculate the upper and lower rails:

```
Upper rail = 4000.00 + (0.02 * 200.00) = 4040.00
Lower rail = 4000.00 - (0.02 * 200.00) = 3960.00
```

If the price breaks above 4040.00, a long signal will be generated. If the price breaks below 3960.00, a short signal will be generated.

The trader can then enter and exit positions according to the signals generated by the algorithm.

#### Python code

```
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
class DualThrustTradingAlgo:
def __init__(self, data, window_size=10, min_thrust=0.05):
self.data = data
self.window_size = window_size
self.min_thrust = min_thrust
self.calculate_indicators()
def calculate_indicators(self):
self.data["up_thrust"] = np.where(self.data["close"] > self.data["open"], self.data["close"] - self.data["open"], 0)
self.data["down_thrust"] = np.where(self.data["close"] < self.data["open"], self.data["open"] - self.data["close"], 0)
self.data["avg_up_thrust"] = self.data["up_thrust"].rolling(window=self.window_size).mean()
self.data["avg_down_thrust"] = self.data["down_thrust"].rolling(window=self.window_size).mean()
def generate_signals(self):
signals = []
for i in range(len(self.data)):
if self.data.loc[i, "avg_up_thrust"] > self.min_thrust and self.data.loc[i, "avg_down_thrust"] < self.min_thrust:
signals.append("BUY")
elif self.data.loc[i, "avg_up_thrust"] < self.min_thrust and self.data.loc[i, "avg_down_thrust"] > self.min_thrust:
signals.append("SELL")
else:
signals.append("HOLD")
return signals
def plot_data(data, signals):
plt.plot(data["close"], label="Close")
plt.plot(data["avg_up_thrust"], label="Average Up Thrust")
plt.plot(data["avg_down_thrust"], label="Average Down Thrust")
for i in range(len(data)):
if signals[i] == "BUY":
plt.scatter(i, data.loc[i, "close"], marker="^", color="green")
elif signals[i] == "SELL":
plt.scatter(i, data.loc[i, "close"], marker="v", color="red")
plt.legend()
plt.show()
def run_algo(data, window_size=10, min_thrust=0.05):
algo = DualThrustTradingAlgo(data, window_size, min_thrust)
signals = algo.generate_signals()
return signals
# Unit tests
def test_dual_thrust_trading_algo():
# Generate some test data
data = pd.DataFrame({
"close": np.random.randn(100)
})
# Create a DualThrustTradingAlgo object
algo = DualThrustTradingAlgo(data)
# Generate signals
signals = algo.generate_signals()
# Assert that the signals are valid
assert all(signal in ["BUY", "SELL", "HOLD"] for signal in signals)
if __name__ == "__main__":
# Load the data
data = pd.read_csv("data.csv", index_col="Date")
# Run the algorithm
signals = run_algo(data)
# Plot the data
plot_data(data, signals)
```

To run the code and tests, simply save it as a Python file (e.g. `dual_thrust_trading_algo.py`

) and run the following commands:

```
python dual_thrust_trading_algo.py
python -m unittest dual_thrust_trading_algo
```

## Summary

The Dual Thrust Trading Algorithm is a momentum-based trading strategy that uses the average up and down security thrust to generate buy and sell signals. The algorithm is designed to identify securities breaking out of their recent trading range and moving in a trending direction.

To use the Dual Thrust Trading Algorithm, traders must first select a lookback period and a minimum thrust threshold. The lookback period is the number of days the algorithm will use to calculate the average up thrust and average down thrust. The minimum thrust threshold is the percentage change a security must experience for the algorithm to generate a buy or sell signal.

Once the lookback period and minimum thrust threshold have been selected, traders can apply the algorithm to their chosen security. The algorithm will calculate the security’s average up and down thrust over the lookback period. The algorithm will generate a buy signal if the average up thrust is greater than the minimum thrust threshold. The algorithm will generate a sell signal if the average down thrust is greater than the minimum thrust threshold.

The Dual Thrust Trading Algorithm can be used to trade various securities, including stocks, futures, and forex. The algorithm is particularly well-suited for trading trending markets. However, it is important to note that the algorithm can generate false signals in range-bound markets.

Here is a summary of the Dual Thrust Trading Algorithm for use in an article:

**Dual Thrust Trading Algorithm**

**Type:**Momentum-based trading strategy**Markets:**Stocks, futures, forex**Timeframe:**Intraday, daily, weekly**Key inputs:**Lookback period, minimum thrust threshold**Key outputs:**Buy and sell signals

**How the algorithm works:**

- Calculates the security’s average up and down thrust over the lookback period.
- Generates a buy signal if the average up thrust exceeds the minimum thrust threshold.
- Generates a sell signal if the average down thrust exceeds the minimum thrust threshold.

**Benefits of the algorithm:**

- Simple to implement
- It can be used to trade a variety of securities
- Well-suited for trading trending markets

**Drawbacks of the algorithm:**

- Can generate false signals in range-bound markets
- Requires careful optimization of input parameters

The Dual Thrust Trading Algorithm is a simple and effective momentum-based trading strategy. It is well-suited for traders who want to identify securities breaking out of their recent trading range and moving in a trending direction.

inFinance## Dual Thrust Trading Algorithm

byAli Kayani