TNTrader5159
Active member
Is <fold> the function to use to calculate how many bars back the first fulfillment of a condition occurred? I want to make sure price dropped below a certain value more recently than it rose above another certain value. For instance...
Def A = Highest(High, BarsEngulfed)[1];
Def B = Lowest(Low, BarsEngulfed)[1];
I want to calculate the number of bars eclipsed by the current bar (if any) on both high and low ends with a minimum of 3 and a maximum of 55.
For a short trade, I must make sure the price broke below the lowest price of all bars eclipsed back to where both the highest and lowest points of all bars eclipsed occurred more recently than it broke above the highest price of all bars eclipsed back to where both the highest and lowest points of all bars eclipsed occurred. Here is some code I wrote:
SHORT
Declare lower;
### Variable: BarsEngulfed = 3 to 55 recursive. The current bar must engulf any number of bars from and including 3 to 55 on both ends to satisfy this first requirement for a complete ABCD pattern. The pattern completes upon the first trade at or below the lowest price in the previous <BarsEngulfed> bars. The result defines how many bars are thereby engulfed from a minimum of 3 to a maximum of 55. ###
Def A = Highest(High, BarsEngulfed)[1];
Def B = Lowest(Low, BarsEngulfed)[1];
Def C = High;
Def D = B;
Def Cond1S = If Open > B then 1 else 0;
### Open must be higher than the lowest price of the previous <BarsEngulfed> bars ###
Def Cond2S = If High > A then 1 else 0;
### High must be higher than the highest price of the previous <BarsEngulfed> bars ###
Def Cond3S = If Low <= B then 1 else 0;
### Low must be less than or equal to the lowest price of the previous <BarsEngulfed> bars (this is the trigger point) ###
Def Cond4S = If Close < A then 1 else 0;
### Close must be lower than the highest prices of the previous <BarsEngulfed> bars ###
Def Cond5S = If High <= A + (A – B) then 1 else 0;
### High must be no higher than itself plus the difference between the highest price of the previous <BarsEngulfed> bars minus the lowest price of the previous <BarsEngulfed> bars ###
Def Cond6S = Fold CountEm = 3 to 55…?
### The most recent occurrence of a price prior to <BarsEngulfed> bars that is lower than the lowest price of the previous <BarsEngulfed> bars minus the distance from the current high to the lowest price of the previous <BarsEngulfed> bars must occur more recently than did any price higher than the highest price of the previous <BarsEngulfed> bars. This assures there has been upward movement in the price before the Short setup pattern develops. ###
Def ShortPattern = If Cond1s + Cond2S + Cond3S + Cond4S + Cond5S + Cond6S + Copnd7S == 7 then <PrelimSignal> else 0;
Please help with Cond6S. Thanks in advance!
Def A = Highest(High, BarsEngulfed)[1];
Def B = Lowest(Low, BarsEngulfed)[1];
I want to calculate the number of bars eclipsed by the current bar (if any) on both high and low ends with a minimum of 3 and a maximum of 55.
For a short trade, I must make sure the price broke below the lowest price of all bars eclipsed back to where both the highest and lowest points of all bars eclipsed occurred more recently than it broke above the highest price of all bars eclipsed back to where both the highest and lowest points of all bars eclipsed occurred. Here is some code I wrote:
ABCD Pattern Specifications
SHORT
Declare lower;
### Variable: BarsEngulfed = 3 to 55 recursive. The current bar must engulf any number of bars from and including 3 to 55 on both ends to satisfy this first requirement for a complete ABCD pattern. The pattern completes upon the first trade at or below the lowest price in the previous <BarsEngulfed> bars. The result defines how many bars are thereby engulfed from a minimum of 3 to a maximum of 55. ###
Def A = Highest(High, BarsEngulfed)[1];
Def B = Lowest(Low, BarsEngulfed)[1];
Def C = High;
Def D = B;
Def Cond1S = If Open > B then 1 else 0;
### Open must be higher than the lowest price of the previous <BarsEngulfed> bars ###
Def Cond2S = If High > A then 1 else 0;
### High must be higher than the highest price of the previous <BarsEngulfed> bars ###
Def Cond3S = If Low <= B then 1 else 0;
### Low must be less than or equal to the lowest price of the previous <BarsEngulfed> bars (this is the trigger point) ###
Def Cond4S = If Close < A then 1 else 0;
### Close must be lower than the highest prices of the previous <BarsEngulfed> bars ###
Def Cond5S = If High <= A + (A – B) then 1 else 0;
### High must be no higher than itself plus the difference between the highest price of the previous <BarsEngulfed> bars minus the lowest price of the previous <BarsEngulfed> bars ###
Def Cond6S = Fold CountEm = 3 to 55…?
### The most recent occurrence of a price prior to <BarsEngulfed> bars that is lower than the lowest price of the previous <BarsEngulfed> bars minus the distance from the current high to the lowest price of the previous <BarsEngulfed> bars must occur more recently than did any price higher than the highest price of the previous <BarsEngulfed> bars. This assures there has been upward movement in the price before the Short setup pattern develops. ###
Def ShortPattern = If Cond1s + Cond2S + Cond3S + Cond4S + Cond5S + Cond6S + Copnd7S == 7 then <PrelimSignal> else 0;
Please help with Cond6S. Thanks in advance!