Number of Signals since Jan 2019

I am trying to count how many down swings with at least 15 days there were in the last 2 years.  I am using the ACC function but its counting the same swing multiple times and I can not figure out how to code it to only count each swing one time.
Can you help?  Thank you!



S0 = PERCENTSWING();
S0Length = SWINGSTAT(S0, SWINGS=1, TYPE=Down, DEFAULT=Bars);   

// Number of down swing signals at least 15 days since Jan 2nd 2019 //
LengthCondition =  S0Length > 14;
ACCSINCESIGNAL(LengthCondition,Bardate()==43467);

Hi Michael,

The “Turns” operators are better and the ACC function includes a lookback period which you can set to 2 years.

All the best

Mathew

S0 = PERCENTSWING();

C1 = S0 TurnsDown;
c2 = S0 TurnsUp and TIMESINCESIGNAL(c1, UNIT=Days) > 14;

ACC(c2, RANGE=Look Back Period, BACKTYPE=Years, BARS=2)

Hi, I am trying to count the number of times an equity crosses below the 50 day moving average after a swing down. The issue with the below script is the ACCSinceSignal function is not resetting when the Switch goes to “0”. It appears to only reset each time the Switch goes to “1”. Thus the ACCSinceSignal function is capturing not only crosses below 50 when the Switch is on but also crosses when the switch is off (until it hits 1 again). Is that the way the function should work? Thank you!

// Calc Swing Gain
S0End= SWINGEND(PERCENTSWING(PERCENT=15.0, CALCUSINGTOOL=Close));
S0Start = SWINGSTART(PERCENTSWING(PERCENT=15.0, CALCUSINGTOOL=Close));
S0Gain = S0End-S0Start;
S0GainPercent = S0Gain/S0Start;

// Switch function to determine when Count is reset
Percent1on= S0GainPercent < -.15;
Percent2off= S0GainPercent > -.14;
Switch2 = Switch(Percent1on, Percent2off);

// Low crosses below 50 Day- No repeat 20 days
CrossBelow50DayDaily = LOW() CrossesBelow MA(BARS=50, STYLE=Simple);
S9CrossNoRepeat = NOREPEAT(CrossBelow50DayDaily, BARS=30);

// Count of number times cross below 50 day since signal
Hit_50day_SinceBase_PercentDecline = ACCSINCESIGNAL(S9CrossNoRepeat, Switch2);
Hit_50day_SinceBase_PercentDecline;

Hi,

The ACC function is working as expected, it only restarts the count once the signal occurs again. You can achieve the result you are after by adding a condition that the count only occurs when the Swing is down.

Here is a quick example using a Gann Swing setup:

//Set Base Swing
V1 = GANNSWING(SWINGCOUNT=3);
//Set MA
V2 = MA(BARS=50) ;
//Find where the Swing Turns Down
V3 = V1 TurnsDown ;
//Find where the Close Crosses Below the 50SMA when the swing is down
V4 = CLOSE() CrossesBelow V2 and V1 IsDown;
//Count the signals
V5 = ACCSINCESIGNAL(V4,V3);
//Only include signals found while the swing is down
IF(V1 IsDown,V5,0)

On the chart it looks like this:

Ex1

The green shaded zone is when the swing is down, the red shaded zones are when the close crosses below the 50SMA. The Show View at the bottom (gold) counts only the crosses that occur when the swing is down.