[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Code Help!



PureBytes Links

Trading Reference Links

Hi ericzhou,

ericzhou wrote:
> 
> Hi list,
> 
> Could anybody help me coding this strategy:
> 
> A bar is considered a set-up bar and will be marked with a small purple
> square on the chart or identified by the scanner if the following conditions
> are met:
> 
> Buy conditions:
> 
> ?Current bar is a new 20 bar low.
> ?AND the new low is at least 3 bars from the previous 20 bar low.
> ?AND the close of the new low bar is less than or equal to the previous 20
> bar low. The previous bar low is labeled with a ^.
> 
> The buy reference is the previous new low.

The following will do as you ask, however I don't know if this is what
you have in mind. Copy the code to TS and run it as an indicator scaled
to your symbol.

vars:nl(0),newnl(0),barnum(0);

if barnumber = 1 then {This will establish the first 20 bar low - a one
time look}
	nl= lowest(close,20); 

{note - the first 20 bars are burned getting this value - so the first
bar that is checked is really bar number 23} 

if barnumber = (barnum +3) then begin  {You want the new low to be no
less than 3 bars from the old low - so we'll check it every three bars
to see if a new low is reached}
	newnl=lowest(close,20);
	barnum=barnum+3;  

	if newnl <= nl then begin {check the new low to see if it is = or lower
than the old low} 
		nl = newnl;
		{other conditions - if new low is reached}
		plot1(nl);
	end;
end;

This code will follow the close as it goes lower, however nl has no way
to re-set - it will stay at the lowest value until a new low is
reached.  If the close goes up nl will stay where it was until a new low
is reached. {note - if you eliminate the "if barnumber = 1 then" and
just use "nl = lowest(close,20);" the nl comparison is different as are
the results}

Larry