Difference between revisions of "Confluence"

From MultiCharts
Jump to navigation Jump to search
 
Line 12: Line 12:
 
NOTE: These default input values seem to work well on 30-min SPX
 
NOTE: These default input values seem to work well on 30-min SPX
  
 +
'''DerivativeMA FUNCTION CODE'''
 +
<syntaxhighlight>
 +
[LegacyColorValue = TRUE];
 +
 +
Inputs:  Price(numeric), Length(Numeric);
 +
 +
 +
VARS: DERIV(0),SUMD(0),LENG2(0),N1(0),DR(0);
 +
 +
DERIV= (AVERAGE(Price,Length)*2) - AVERAGE(Price,Length)[1];
 +
 +
SUMD=Length*DERIV;
 +
 +
LENG2=length - 1 ;
 +
 +
N1= (AVERAGE(Price,LENG2))*LENG2;
 +
 +
DR=SUMD-N1;
 +
 +
DerivativeMA = DR;
 +
</syntaxhighlight>
  
 
'''CONFLUENCE FUCNTION CODE:'''
 
'''CONFLUENCE FUCNTION CODE:'''

Latest revision as of 17:01, 10 December 2013

Origin: Gary Fritz`s site.


Description: Based on Dale Legan's Confluence indicator that was posted to the Omega list in November 1998. See the Confluence function to see how the Conf oscillator is calculated.


Inputs:
Price - Price to use in the Confluence calculations.
Harmonic - An estimate of the dominant cycle length.
Trigger - System buys/sells Trigger points above/below the bar where Confluence goes bullish/bearish. When the Confluence drops out of bullish/bearish mode, the system sets an exit stop Trigger points below Low / above High.
AggStops - If true, the system tightens its stops if the market moves in your direction. E.g. if High is 1000 and Trigger is 2, initial long stop is set at 1002. If the next bar has a high of 999, stop is moved to 999.
NOTE: These default input values seem to work well on 30-min SPX

DerivativeMA FUNCTION CODE

[LegacyColorValue = TRUE];

Inputs:  Price(numeric), Length(Numeric);


VARS: DERIV(0),SUMD(0),LENG2(0),N1(0),DR(0);

DERIV= (AVERAGE(Price,Length)*2) - AVERAGE(Price,Length)[1];

SUMD=Length*DERIV;

LENG2=length - 1 ;

N1= (AVERAGE(Price,LENG2))*LENG2;

DR=SUMD-N1;

DerivativeMA = DR;

CONFLUENCE FUCNTION CODE:

[LegacyColorValue = TRUE];

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

 Written by Dale Legan <dlegan@flash.net>
}

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 <ErrSum[1] and ErrSum >ErrSig then ErrNum=2;
If ErrSum>ErrSum[1] and ErrSum<ErrSig then 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 <ErrSum[1] and ErrSum >ErrSig then ErrNum=-2;
If ErrSum>ErrSum[1] and ErrSum<ErrSig then 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 <mom[1] and mom >momsig then momNum=2;
If mom>mom[1] and mom<momsig then 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 <mom[1] and mom >momsig then momNum=-2;
If mom>mom[1] and mom<momsig then 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 <TC[1] and TC >TCsig then TCNum=2;
If TC>TC[1] and TC<TCsig then 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 <TC[1] and TC >TCSig then TCNum=-2;
If TC>TC[1] and TC<TCSig then 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;

CONFLUENCE SIGNAL CODE

 INPUTS: PRICE(CLOSE), HARMONIC(4), TRIGGER(5), AGGSTOPS(FALSE);
 
 
 
VARS: CONF(0), SIGNAL(0), LSTOP(99999), LEXIT(0), SSTOP(0), SEXIT(99999);
 
 
 
 
 
{ IS THE INDICATOR IN BULL/BEAR MODE? }
 
 
 
CONF = CONFLUENCE(PRICE, HARMONIC);
 
SIGNAL = 0;
 
IF (CONF >= 1)  THEN SIGNAL = 1;   {BULL}
 
IF (CONF <= -1) THEN SIGNAL = -1;  {BEAR}
 
 
 
{ SET ENTRY STOPS WHEN INDICATOR FIRST MOVES INTO BULL/BEAR MODE }
 
 
 
IF (SIGNAL = 1) AND (SIGNAL[1] <> 1) THEN BEGIN
 
  LSTOP = HIGH + TRIGGER;
 
  LEXIT = 0;
 
  END;
 
IF (SIGNAL = -1) AND (SIGNAL[1] <> -1) THEN BEGIN
 
  SSTOP = LOW - TRIGGER;
 
  SEXIT = 99999;
 
  END;
 
 
 
{ SET EXIT-POSITION STOPS WHEN INDICATOR LEAVES BULL/BEAR STATE }
 
 
 
IF (SIGNAL <> 1) AND (SIGNAL[1] = 1) THEN BEGIN
 
  LEXIT = LOW - TRIGGER;
 
  LSTOP = 99999;
 
  END;
 
IF (SIGNAL <> -1) AND (SIGNAL[1] = -1) THEN BEGIN
 
  SEXIT = HIGH + TRIGGER;
 
  SSTOP = 0;
 
  END;
 
 
 
{ AGGRESSIVE STOPS:  MOVE THEM IF MKT MOVES IN OUR DIRECTION }
 
 
 
IF AGGSTOPS THEN BEGIN
 
  IF (LSTOP <> 99999) THEN LSTOP = MINLIST(LSTOP, HIGH + TRIGGER);
 
  IF (LEXIT <> 0) THEN LEXIT = MAXLIST(LEXIT, LOW - TRIGGER);
 
  IF (SSTOP <> 0) THEN SSTOP = MAXLIST(SSTOP, LOW - TRIGGER);
 
  IF (SEXIT <> 99999) THEN SEXIT = MINLIST(SEXIT, HIGH + TRIGGER);
 
  END;
 
 
 
{ CLEAR STOPS WHEN OUR PRICE IS HIT }
 
 
 
IF (H > LSTOP) THEN LSTOP = 99999;
 
IF (L < LEXIT) THEN LEXIT = 0;
 
IF (L < SSTOP) THEN SSTOP = 0;
 
IF (H > SEXIT) THEN SEXIT = 99999;
 
 
 
{ ISSUE THE BUY/SELL ORDER ON EACH BAR UNTIL PRICE IS HIT }
 
 
 
IF (LSTOP <> 99999) THEN BUY NEXT BAR AT LSTOP STOP;
 
IF (LEXIT <> 0) THEN SELL NEXT BAR AT LEXIT STOP;
 
IF (SSTOP <> 0) THEN SELL NEXT BAR AT SSTOP STOP;
 
IF (SEXIT <> 99999) THEN BUYTOCOVER NEXT BAR AT SEXIT STOP;

CONFLUENCE INDICATOR CODE

[LegacyColorValue = TRUE];

Input: price(close),Harmonic(10);

Vars: Conf(0);

Conf = Confluence(price, Harmonic);

IF Conf >= 1 THEN Plot1(Conf, "Bull");

IF Conf <= -1 THEN Plot2(Conf,"Bear");

If (Conf = 0) then Plot4(0,"ZERO")
else If (Conf > -1) and (Conf < 1) then Plot3(10*Conf, "Yellow");