barssince

A forum for all EdgeRater users

Moderator: Chris White

Post Reply
nichjoht
Posts: 8
Joined: Mon Jan 21, 2013 6:02 pm

barssince

Post by nichjoht »

Chris,

first let me say that the new upgrades to edgerater are fantastic!

I am trying to make a scan that returns stocks that:

price has been above the EMA17 for 20 days
price has been above the EMA50 for 10 days
price has been above the EMA200 for 90 days
price is within 10% of the 52 wk high

This is what I have so far:

Sig1:= if(C<EMA(C,17),1,0);
count1:=BARSSINCE(Sig1)-1;
Sig2:= if(C<EMA(C,50),1,0);
count2:=BARSSINCE(Sig2)-1;
Sig3:= if(C<EMA(C,200),1,0);
count3:= BARSSINCE(Sig2)-1;
hv:=(HHV(C, 200)== C);
flg1:count1>=20;
flg2:=count2>=10;
flg3:=count3>=90;
flg4:=C>hv-(hv*.1);
event:=flg1 & flg2 & flg3 & flg4;

I don´t understand the barssince command. Unless I put -1 the function always returns a value of 1. It seems that Sig1 is true as long as 20 bars ago the price was above EMA17 and the current bars is too.
The 52wk high never seems to fire true.

- John
Chris White
Posts: 201
Joined: Mon Nov 29, 2010 9:21 pm

Re: barssince

Post by Chris White »

Hi John,

BARSSINCE(Signal) returns the number of bars since the signal was a 1 value.

So, if 'Signal' is 1 today, BARSSINCE will return 1
If 'Signal' is 0 today but was 1 yesterday, BARSSINCE will return 2.

BARSSINCE only ever returns 0 if there has been no occurrence of Signal in the entire series of data.

You can more easily visualize this if you remove a few of the := in your script and replace with : (which signifies the output should be shown on a chart) and then add the script to a chart. Here's an simplified example:

Code: Select all

Sig1: if(C<EMA(C,17),1,0);
count1:BARSSINCE(Sig1);
flg1:count1>=20;
Which produces the following:
nichjoht.png
nichjoht.png (11.16 KiB) Viewed 10585 times
Chris.
Post Reply