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

Re: EL question - static variables - clarification



PureBytes Links

Trading Reference Links

> In the following code, I want the variables ThirtyMinHi,
> ThirtyMinLo, WentLong, WentShort to be what I call "static". For
> example, if I set WentLong in bar 45 of an intraday chart and
> don't do anything after it, at bar 100 (for example) I want to be
> able to just get the value of WentLong and not have to reference
> the bar on which I set it (or worry about keeping track of that). 
> 
> How can I do this in EL?

Just set the value in WentLong and leave it.  It'll keep that value 
as long as you don't change it.

The problem is, you DO change it:

> If (time <= 1000) then
> { if it's before 10:00am then update the 1st Thirty minutes of the 
> day high and low}
> begin
> 	ThirtyMinHi = MaxList(H, ThirtyMinHi); WentLong = 0;
> 	ThirtyMinLo = MinList(L, ThirtyMinLo); WentShort = 0;
> end

So every morning, on any bar before 10:00, you reset WentLong and 
WentShort to 0.

Now, if that's what you want -- you only want WentLong to be 1 if you 
went long TODAY -- then everything is cool.  Every morning you'll 
reset it to 0, and when you go long you'll set it to 1.  It will keep 
that value until you re-set it the next morning.

You might want to re-consider your "morning" test, though.  I don't 
know what bar size you run this on -- how many bars are there before 
10:00?  If only 1, then you're OK, as long as you run it in the right 
timezone.  It would be a bit more flexible to use an offset from 
Sess1StartTime so your system would work fo any market open time. 

You can make it insensitive to bar size and time zone by looking at 
the date on the current & previous bar:

  if Date <> Date[1] then begin
     { first bar of the day, initialize WentLong/etc }
  end;

Another possibility is to dispense with WentLong/WentShort altogether 
and use some of the built-in EL functions.  EntryDate(N) returns the 
date of the entry N positions ago.  0 is the date of entry for the 
current position (returns 0 if flat), 1 returns the entry date of the 
most recently closed position.  So "EntryDate(1) <> Date" is true if 
you haven't closed out any trades today.  "EntryDate(0) <> Date and 
EntryDate(1) <> Date" is true if you haven't entered ANY trades 
today, whether you're currently in a trade or not.

Gary