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

Re: Pass by value



PureBytes Links

Trading Reference Links

> Anyone know how to pass a variable to a function by value so that
> the function does not reference the value of the variable during
> previous bars. 
> Example: Mro(high=variable1,20,1) so that the function will test if
> the previous highs equal the current value of variable1. 

When you pass a variable to a function, and the function declares 
the input as NumericSimple, it's passed by value, as Alex said.

But MRO doesn't do that.  That first parameter isn't a simple 
type; it's TrueFalseSeries.  That in itself isn't all that 
unusual, but then look how it's used.

MRO accepts your "high=variable1" input as a TrueFalse value.  
Because it declares the input as Series type, it explicitly saves 
the history of input values.  More importantly, MRO never sees 
the value of variable1!  The equality test happens before MRO is 
even called.  All MRO sees is the result of the equality test ON 
EACH BAR.  So there's no way for MRO to compare your current 
value of variable1 to a previous value of High.

To do that, you'll have to code it yourself, something like this:

for BarsBack = 0 to 19 begin
  if High[BarsBack] = variable1 then <<do whatever>>;
end;

That way you're comparing the *current* value of variable1 to the 
previous bars' values of High.

Gary