Consecutive Downs SE#
This strategy captures downtrends by counting consecutive down bars. When the number of consecutive declining bars meets a configurable threshold, it enters a short position at the market open of the following bar.
Source Code#
1
2
3
4
5
6
7
8
9
10
| [IntrabarOrderGeneration = false]
Inputs: Price(Close), ConsecutiveBarsDown(3);
If Price < Price[1] Then
Value1 = Value1 + 1
Else
Value1 = 0;
If Value1 >= ConsecutiveBarsDown Then
Sell Short ("ConsDnSE") next bar at market;
|
Code Walkthrough#
1
| [IntrabarOrderGeneration = false]
|
Ensures that only one order is generated per bar; orders are placed only when the bar is complete.
1
| Inputs: Price(Close), ConsecutiveBarsDown(3);
|
Price: The price series used for comparison; defaults to the closing price.ConsecutiveBarsDown: The required number of consecutive down bars before a short entry is triggered; defaults to 3.
1
2
3
4
| If Price < Price[1] Then
Value1 = Value1 + 1
Else
Value1 = 0;
|
Compares the current bar’s price to the previous bar’s price. If the price declined, the counter Value1 increments by 1. If not, the counter resets to 0.
1
2
| If Value1 >= ConsecutiveBarsDown Then
Sell Short ("ConsDnSE") next bar at market;
|
Once the counter reaches or exceeds ConsecutiveBarsDown, a market short sell order is submitted for the next bar’s open.