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

Re: Using Arrays - how and when?



PureBytes Links

Trading Reference Links

>Here's the function: 

> IF Condition1 and Condition2 and Condition3 and Condition4
> THEN ArrowDown=Low[2];

you can be a bit more efficient with the function by skipping the
conditions

If Low > Low[1] and Low[1] > Low[2] and Low[2] < Low[3] and Low[3] < Low[4]
then arrowdown = Low[2];
 
> So, forget about the SwingLow syntax stuff - 

Hey, if you want to program your own code, you ought to know how the
"stuff" works.

here's a function that will do what you want - store the most recent 10
arrows.

//////////// FUNCTION:arrowdown ////////////////////////
input: lookback(NumericSimple);
vars: counter(0);
array: arrows[10](0);

If Low > Low[1] and Low[1] > Low[2] and Low[2] < Low[3] and Low[3] < Low[4]
then begin
	for counter = 9 downto 1 begin
		arrows[counter] = arrows[counter-1];
		arrows[0] = Low[2];
	End;
End;

arrowdown = arrows[lookback];
/////////////////////////////////////////////////////////////

you can call the function from indicators or systems like this

value1 = lookback(0);  {this return the latest arrow down}
value2 = lookback(1);  {this returns the 2nd to last arrow down etc...}

use the print log to check your points against a chart (a good habit
hint,hint):
print(arrowdown(1),arrowdown(2),arrowdown(3),arrowdown(4),arrowdown(5),arrow
down(6));

By the way, your function might be a bit too restrictive, you might miss
some important swings because you insist on low[2]<low[3] and low[3]<low[4]
  
maybe try low[2] < low[3] and low[2]<low[4] ?

an example is todays s&p chart. on a 15 min chart your function as written
will miss an important swinglow at 3:30pm @ 1108.00


JM