Consecutive Ups LE#
This strategy captures uptrends by counting consecutive up bars. When the number of consecutive advancing bars meets a configurable threshold, it enters a long 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), ConsecutiveBarsUp(3);
If Price > Price[1] Then
Value1 = Value1 + 1
Else
Value1 = 0;
If Value1 >= ConsecutiveBarsUp Then
Buy ("ConsUpLE") 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), ConsecutiveBarsUp(3);
|
Price: The price series used for comparison; defaults to the closing price.ConsecutiveBarsUp: The required number of consecutive up bars before a long 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 advanced, the counter Value1 increments by 1. If not, the counter resets to 0.
1
2
| If Value1 >= ConsecutiveBarsUp Then
Buy ("ConsUpLE") next bar at market;
|
Once the counter reaches or exceeds ConsecutiveBarsUp, a market buy order is submitted for the next bar’s open.