+1 888 340 6572

SlowK_Divergence

Article/Author: Origin: www.bayou.com/~smcg/tscode2.htm. E-mail: trade1@bayou.com

Download: Bayou1.ela

File Includes:
PaintBar - SlowK_Divergence
Indicator - SlowK Divergence

Category: PaintBars > SlowK_Divergence

Description:

Look for a bullish divergence if the current "slowk_var" is less than 20. The code defines the shape of the slowk curve first.
If the slowk curve's shape meets the criteria for a bullish divergence, the code then will check for a bullish divergence.

Inputs:

slowklength
slowkaverage

EasyLanguage Code:
INPUTS: SLOWKLENGTH(9),SLOWKAVERAGE(3); 

VARS: SLOWK_VAR(0),NEAR_LOW(0),NEAR_LOW_BAR(0),NEAR_LOW_TIME(0),
NEAR_LOW_DATE(0),COUNT(0),MID_MARKER(0),FOUND_DIV(0),
FOUND_OFF(0),MOVE_DOWN(0),LOOK_UP(0),OLD_SLOWK(100);

{CREATE THE VARIABLE SLOWK_VAR. SLOWK_VAR WILL STORE THE AVERAGE OF SLOWK_VAR.
THE PERIOD TO AVERAGE SLOWK_VAR IS DEFINED BY THE INPUT SLOWKAVERAGE.}
SLOWK_VAR=AVERAGE(SLOWK(SLOWKLENGTH),SLOWKAVERAGE);

{LATER IN THE CODE ,THE VARIABLES , MID_MARKER ; FOUND_DIV ; FOUND_OFF ; MOVE_DOWN, ARE USED TO INDENTIFY
THE SHAPE OF THE SLOWK CURVE. IT IS NECESSARY TO RESET THESE VALUES TO 0 AT THE BEGINNING OF EACH NEW BAR. }
MID_MARKER=0; FOUND_DIV=0; FOUND_OFF=0; MOVE_DOWN=0; OLD_SLOWK=100;

{BEGIN TO LOOK FOR A BULLISH DIVERGENCE , ONLY IF THE CURRENT SLOWK_VAR IS LESS THAN 20. THIS IS THE MAIN IF
STATEMENT. THE CODE WITHIN THIS MAIN IF STATEMENT DEFINES THE SHAPE OF THE SLOWK CURVE FIRST. IF THE SLOWK
CURVE'S SHAPE MEETS THE CRITERIA FOR A BULLISH DIVERGENCE, THE CODE THEN WILL CHECK FOR A BULLISH DIVERGENCE. }
IF(SLOWK_VAR<20) THEN BEGIN
{DETERMINE 1ST POINT PRIOR TO THE CURRENT BAR WHERE SLOWK IS GREATER THAN 50. ASSIGN THIS VALUE TO MID_MARKER.}
FOR COUNT=1 TO 25 BEGIN
IF (SLOWK_VAR[COUNT]>50 AND MID_MARKER=0) THEN BEGIN
MID_MARKER=COUNT;
END;
END;
NEAR_LOW=LOWEST(LOW,MID_MARKER);
NEAR_LOW_BAR=LOWESTBAR(LOW,MID_MARKER);
NEAR_LOW_TIME=TIME[NEAR_LOW_BAR];
NEAR_LOW_DATE=DATE[NEAR_LOW_BAR];

{LOOKING BACK TO THE MIDPOINT (MID_MARKER), IF THERE IS A SLOWK VALUE THAT IS BELOW THE CURRENT SLOWK VALUE
THEN TELL THE CODE TO STOP LOOKING FOR THE DIVERGENCE ON THIS BAR. THIS IS DONE BY ASSIGNING A 1 TO FOUND_OFF}
FOR COUNT=1 TO MID_MARKER BEGIN
IF(SLOWK_VAR[COUNT] < SLOWK_VAR) THEN FOUND_OFF=1;
END;

{EARLIER IN THE CODE WE DETERMINED THE 1ST POINT PRIOR TO THE CURRENT BAR WHERE SLOWK IS GREATER THAN 50.
WE ASSIGNED THIS VALUE TO MID_MARKER. IF SLOWK NEVER GOT ABOVE 50 THEN THERE IS NO NEED TO LOOK ANY FURTHER.
THE STATEMENT WILL STOP PROCEDURE IF THIS IS THE CASE. }
IF(MID_MARKER<>0) THEN BEGIN
{NOW, THE CODE WILL LOOK BACK FROM THE MID_POINT ( MID_MARKER) BAR TO 60 BARS BACK. REMEMBER, THE CODE IS LOOKING
BACK FROM THE POINT WHERE SLOWK WAS LAST 50 OR GREATER.}
FOR COUNT=MID_MARKER TO 60 BEGIN
{IF A PRIOR SLOWK_VAR VALUE IS BELOW THE CURRENT SLOWK VALUE , AND THE LOW PRICE THAT ACCOMPANIES THE PRIOR SLOWK
VALUE IS GREATER THAN THE CURRENT LOW, THEN A BULLISH DIVERGENCE HAS BEEN FOUND. ONCE A DIVERGENCE HAS BEEN
FOUND THEN STOP LOOKING.}
IF(SLOWK_VAR[COUNT] < SLOWK_VAR AND LOWEST(L,6)[COUNT-3]>NEAR_LOW AND
FOUND_DIV=0 AND FOUND_OFF=0 AND MOVE_DOWN<=1)THEN BEGIN
FOUND_DIV=1;
END;
{IF A PRIOR LOW IS LESS THAN THE CURRENT LOW, STOP LOOKING FOR A BULLISH DIVERGENCE. REMEMBER, WE ARE LOOKING FOR
THE PRIOR LOW TO BE GREATER THAN THE CURRENT LOW; THE NECESSARY PRICE SETUP FOR A BULLISH DIVERGENCE.}
IF(L[COUNT] < NEAR_LOW) THEN FOUND_OFF=1;
{AFTER THE MIDPOINT (MID_MARKER) BAR TO 60 BARS BACK, KEEP TRACK OF THE NUMBER OF TIMES SLOWK_VAR CROSSES DOWN
BELOW 35 AND STORE THE VALUE TO THE VAR. MOVE_DOWN. AFTER THE MIDPOINT MARKER WE ONLY WILL ALLOW SLOWK_VAR
TO CROSS BELOW 35 ONE TIME WHEN CONSIDERING A BULLISH DIVERGENCE SETUP. }
IF(SLOWK_VAR[COUNT] <= 35 AND SLOWK_VAR[COUNT-1] > 35) THEN MOVE_DOWN=MOVE_DOWN+1;
{AFTER THE MIDPOINT RECORD THE LOWEST SLOWK VALUE.}
IF(SLOWK_VAR[COUNT] < OLD_SLOWK AND MOVE_DOWN<=1) THEN OLD_SLOWK=SLOWK_VAR[COUNT];
END;
END;
END;

{ONCE A BULLISH DIVERGENCE HAS BEEN FOUND, MARKED BY THE VAR FOUND_DIV=1,THEN SET THE VAR LOOK_UP=1. LOOK_UP=1 WILL
TELL THE CODE TO LOOK FOR THE FIRST UPTURN IN THE SLOWK_VAR INDICATOR. THE UPTURN WILL MARK THE BAR TO PLACE THE
PAINT BAR.}
IF (FOUND_DIV=1 AND LOOK_UP=0) THEN LOOK_UP=1;
{WHILE LOOKING FOR AN UPTURN IN THE SLOWK_VAR INDICATOR, IF THE CURRENT VALUE OF THE SLOWK_VAR INDICATOR CROSSES
BELOW THE OLD LOW MADE IN THE SLOWK_VAR INDICATOR , THEN CALL THE BULLISH DIVERGENCE OFF FOR THE PRIMARY RULE
HAS BEEN BROKEN- HIGHER LOW IN SLOWK. }
IF (LOOK_UP=1 AND SLOWK_VAR<=OLD_SLOWK) THEN LOOK_UP=0;

{IF LOOK_UP HAS NOT BEEN RESET TO 0 AND THE SLOWK_VAR UPTURN OCCURS, THEN WE HAVE IT, A BULLISH SLOW_K DIVERGENCE
HAS OCCURED. FIRE OFF THE PAINT BAR}
IF (LOOK_UP=1 AND SLOWK_VAR>SLOWK_VAR[1]) THEN BEGIN
PLOT1 ( H , "SK H" );
PLOT2 ( L , "SK L" );
LOOK_UP=0;
END;