+1 888 340 6572

# Confluence

Article/Author: Origin: Gary Fritz`s site. Originally provided by dlegan@flash.net

File Includes:
Function - Confluence
Function - Derivativema
Indicator - Confluence
Strategy - Confluence

Category: Function > Confluence

Description:

Function:
Returns a value from -9 to +9.
-9 to -1: bearish
-0.9 to +0.9: "yellow"
1 to 9: bullish

Inputs:
Price -
Harmonic -

EasyLanguage Code:
```INPUT: PRICE(NUMERIC),HARMONIC(NUMERIC);

VARS: STL(0),ITL(0),LTL(0),HOFF(0),SOFF(0),IOFF(0),LTOFF(0),PHASE(1);
VARS: MTL(0),MOMSIG(0),MOM(0),HT(0),HTA(0);
VARS: ST(0),STA(0),IT(0),ITA(0),SUM(0),ERR(0),ERRSUM(0),ERRSIG(0),TC(0),TCSIG(0);
VARS: ERRNUM(0),MOMNUM(0),TCNUM(0);
VARS: HAVG(0), SAVG(0), IAVG(0), LAVG(0);

{CALCULATE LENGTHS}
IF (BARNUMBER = 1) THEN BEGIN
MTL=HARMONIC/2;
STL= INTPORTION((HARMONIC*2)-1);  {11}
ITL= INTPORTION((STL*2)-1);             {21}
LTL= INTPORTION((ITL*2)-1);              {41}

HOFF=INTPORTION(HARMONIC/2);     {3}
SOFF=INTPORTION(STL/2);               {5}
IOFF=INTPORTION(ITL/2);                 {10}
LTOFF=INTPORTION(LTL/2);             {20}
END;

{ AVERAGES }

HAVG = AVERAGE(PRICE, HARMONIC);
SAVG = AVERAGE(PRICE, STL);
IAVG = AVERAGE(PRICE, ITL);
LAVG = AVERAGE(PRICE, LTL);

{CYCLE MOMENTUM}

VALUE2 = SAVG - HAVG[HOFF];
VALUE3 = IAVG - SAVG[SOFF];
VALUE12 = LAVG - IAVG[IOFF];

MOMSIG = VALUE2 + VALUE3 + VALUE12;  {MOMENTUM SIGNAL LINE}

VALUE5= ((SUMMATION(PRICE,HARMONIC-1) + DERIVATIVEMA(PRICE,HARMONIC))/HARMONIC);
VALUE6= ((SUMMATION(PRICE,STL-1) + DERIVATIVEMA(PRICE,STL))/STL);
VALUE7= ((SUMMATION(PRICE,ITL-1) + DERIVATIVEMA(PRICE,ITL))/ITL);
VALUE13=((SUMMATION(AVGPRICE,LTL-1) + DERIVATIVEMA(PRICE,LTL))/LTL);

VALUE9 = VALUE6 - VALUE5[HOFF];
VALUE10=VALUE7 - VALUE6[SOFF];
VALUE14=VALUE13 - VALUE7[IOFF];
MOM = VALUE9 + VALUE10 + VALUE14;

{ HARMONIC =6 WAS 5 MAY USE HARMONIC -1 }
{
HT= SINE((SUMMATION(PRICE,(HARMONIC-1))+DERIVATIVEMA(PRICE,HARMONIC))/HARMONIC) + COSINE((SUMMATION(PRICE,(HARMONIC-1))+DERIVATIVEMA(PRICE,HARMONIC))/HARMONIC);
}
HT = SINE(VALUE5) + COSINE(VALUE5);
HTA= SINE(HAVG) + COSINE(HAVG);

{
ST=  SINE((SUMMATION(PRICE,(STL-1))+DERIVATIVEMA(PRICE,STL))/ STL) + COSINE((SUMMATION(PRICE,(STL-1))+DERIVATIVEMA(PRICE,STL))/STL);
}
ST = SINE(VALUE6) + COSINE(VALUE6);
STA = SINE(SAVG) + COSINE(SAVG);

{
IT= SINE((SUMMATION(PRICE,(ITL-1))+DERIVATIVEMA(C,ITL))/ITL) + COSINE((SUMMATION(PRICE,(ITL-1))+DERIVATIVEMA(PRICE,ITL))/ITL);
}
IT = SINE(VALUE7) + COSINE(VALUE7);
ITA=SINE(IAVG)+ COSINE(IAVG);

SUM= HT+ST+IT; {EST IN CYC ESTIMATOR/ CYCLE EST ERR = SUM - ERR }
ERR =HTA + STA +ITA;

{PHASE DETECT}

CONDITION2=  (SUM > SUM[SOFF]
AND HAVG < HAVG[SOFF])
OR (SUM < SUM[SOFF]
AND HAVG > HAVG[SOFF]) ;
PHASE=1;
IF CONDITION2 THEN PHASE=-1;

ERRSUM = (SUM - ERR)*PHASE;  { ERROR OF THE CYCLE}
ERRSIG=AVERAGE(ERRSUM,SOFF);   { ERROR SIGNAL LINE}

{TREND CATCHER}

VALUE68=VALUE5;
{( (SUMMATION(PRICE,(HARMONIC-1)) + DERIVATIVEMA(PRICE,HARMONIC)) / HARMONIC );}
VALUE69=VALUE13;
{( (SUMMATION(AVGPRICE,(LTL-1)) + DERIVATIVEMA(PRICE,LTL)) / LTL );}

VALUE70 = VALUE68-VALUE69; { EST W DER}
VALUE71 = AVERAGE(VALUE70,HARMONIC);

TC =VALUE70;
TCSIG=VALUE71;

{BEGIN COUNTING BARS}

IF ERRSUM > 0 THEN BEGIN
IF ERRSUM < ERRSUM[1] AND ERRSUM < ERRSIG THEN ERRNUM=1;
IF ERRSUM AND ERRSUM >ERRSIG THEN ERRNUM=2;
IF ERRSUM>ERRSUM[1] AND ERRSUMTHEN ERRNUM=2;
IF ERRSUM > ERRSUM[1] AND ERRSUM> ERRSIG THEN ERRNUM=3;
END;
IF ERRSUM < 0 THEN BEGIN
IF ERRSUM > ERRSUM[1] AND ERRSUM > ERRSIG THEN ERRNUM=-1;
IF ERRSUM AND ERRSUM >ERRSIG THEN ERRNUM=-2;
IF ERRSUM>ERRSUM[1] AND ERRSUMTHEN ERRNUM=-2;
IF ERRSUM < ERRSUM[1] AND ERRSUM< ERRSIG THEN ERRNUM=-3;
END;

IF MOM > 0 THEN BEGIN
IF MOM < MOM[1] AND MOM < MOMSIG THEN MOMNUM=1;
IF MOM AND MOM >MOMSIG THEN MOMNUM=2;
IF MOM>MOM[1] AND MOMTHEN MOMNUM=2;
IF MOM > MOM[1] AND MOM> MOMSIG THEN MOMNUM=3;
END;
IF MOM < 0 THEN BEGIN
IF MOM > MOM[1] AND MOM > MOMSIG THEN MOMNUM=-1;
IF MOM AND MOM >MOMSIG THEN MOMNUM=-2;
IF MOM>MOM[1] AND MOMTHEN MOMNUM=-2;
IF MOM < MOM[1] AND MOM< MOMSIG THEN MOMNUM=-3;
END;

IF TC > 0 THEN BEGIN
IF TC < TC[1] AND TC < TCSIG THEN TCNUM=1;
IF TC AND TC >TCSIG THEN TCNUM=2;
IF TC>TC[1] AND TCTHEN TCNUM=2;
IF TC > TC[1] AND TC> TCSIG THEN TCNUM=3;
END;
IF  TC < 0 THEN BEGIN
IF TC > TC[1] AND TC > TCSIG THEN TCNUM=-1;
IF TC AND TC >TCSIG THEN TCNUM=-2;
IF TC>TC[1] AND TCTHEN TCNUM=-2;
IF TC < TC[1] AND TC< TCSIG THEN TCNUM=-3;
END;

VALUE42= ERRNUM + MOMNUM+TCNUM;

CONFLUENCE = 0;
IF VALUE42 >0 AND TC >0 THEN CONFLUENCE = VALUE42;  { BULLISH }
IF VALUE42<0 AND TC < 0 THEN CONFLUENCE = VALUE42;  { BEARISH }
IF (VALUE42 > 0 AND TC <0) OR (VALUE42 <0 AND TC>0) THEN CONFLUENCE = VALUE42 / 10;```