Please add Buy/Sell variables to this RSI divergence code.

mohan.sic

Well-Known Member
#1
Hey guys, could anyone please add buy/sell variables to to this code to do autoscan.


--------------------------------------------------------------------------

_SECTION_BEGIN("RSI divergence");

P = Param("Period RSI", 14, 9, 14, 1);
VRSI = RSI(P);

Length = 100;
Lapse = 3;

fUp = VRSI > Ref(VRSI, -1) & VRSI > Ref(VRSI, 1) & VRSI >70;
fDown = VRSI < Ref(VRSI, -1) & VRSI < Ref(VRSI, 1) & VRSI < 30;

Div = 0;

for(i = Length; i < BarCount; i++)
{

// Down
if(fUp)
{
k = i-1;
do
{
if(VRSI[k] > VRSI & fUp & fUp[k])
{
if(C[k] < C & i-k > Lapse)
{
Div = 1;
}
k = i-Length;
}
else
k = k-1;
} while( k > i-Length );
}

////////////////////////////

// Up

if(fDown)
{
k = i-1;
do
{
if(VRSI[k] < VRSI & fDown & fDown[k])
{
if(C[k] > C & i-k > Lapse)
{
Div = -1;
}
k = i-Length;
}
else
k = k-1;
} while( k > i-Length );
}

}



Fon = IIf(Div == 0, 0, 1);

Col = IIf(Div == 1, 4, IIf(Div == -1, 5, 1));

Color = IIf(Div == 1, 32, IIf(Div == -1, 27, 1));

Color = IIf(fUp == 1, 32, IIf(fDown == 1, 27, 1));

Div = IIf(Div == 0, Null, abs(Div));
Fon = abs(Div);


// Title = EncodeColor(4)+"RSI(" + WriteVal(P, 2.0) + ")" + EncodeColor(1) + " ="+WriteVal(RSI(P));
// Plot( RSI(P), "RSI", Col, 5);
// Plot( 25,"", 4, 16+4096);
// Plot( 75,"", 4, 16+4096);
Plot(Fon, "", Color, 16384+32768+4096 | styleOwnScale, MinValue = 0, MaxValue = 1);
_SECTION_END();

--------------------------------------------------------------------------


Thanks in advance. :clap:
 

mohan.sic

Well-Known Member
#2
Hai friends,

No replies...

Is it not possible to add buy/sell conditions to scan with this afl.
Please let me know.


Regards,
Mohan.
 
#3
Hai friends,

No replies...

Is it not possible to add buy/sell conditions to scan with this afl.
Please let me know.


Regards,
Mohan.
It is possible. Do understand how the code operates and then test the syntax. Do note that you will have to check 1 day before data to get the correct output.
 

mohan.sic

Well-Known Member
#4
Sage, please make it much clear. fyi - I am not a tech student. I can write rules, but can code them :). it would be :clapping: if you can do it for us.
 
#5
Buy = Col > 4.50 AND fon == 1 AND Ref(RSI(14),-1) < 35;
Sell = Col < 4.50 AND Fon == 1 AND Ref(RSI(14),-1) > 65;

Change the 35 and 65 to suit your requirements
 

mohan.sic

Well-Known Member
#6
Oh, Thank you very much from me and others also :thumb:
One more request, pls add the condition in the code itself and post it entirely.
And due to this addition if any changes need to be done (i dont know) pls modify them and send us. That would be great. :clapping:

Regards, MohaN
 

mohan.sic

Well-Known Member
#7
Hi Sage,

Tried with your Buy/sell condition. But its not working.
Please check and pls post the entire new code.
Waiting for your reply....

MoHaN.
 

mohan.sic

Well-Known Member
#8
Dear sage, Tried but still not working. my sincere request is pls see if you spare some time and post the entire code.

MoHaN.
 
#10
Nifty Spot Hourly Divergence Buy / Sell Signals using the same afl, (Last 100 days)

Ticker Trade Date Close

^NSEI Buy 19/06/2009 1:54:55 PM 4233.1001
^NSEI Buy 23/06/2009 10:54:55 AM 4174.0000
^NSEI Buy 08/07/2009 3:30:00 PM 4074.5000
^NSEI Sell 22/07/2009 11:54:55 AM 4536.3999
^NSEI Sell 27/07/2009 10:54:40 AM 4584.4502
^NSEI Sell 03/08/2009 3:30:00 PM 4722.0000
^NSEI Buy 12/08/2009 12:54:59 PM 4366.7500
^NSEI Sell 25/08/2009 2:54:57 PM 4665.7500
^NSEI Sell 27/08/2009 1:54:57 PM 4700.5000
^NSEI Sell 10/09/2009 10:54:16 AM 4884.5498
 

Similar threads