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

Re: evaluate trades at specific times



PureBytes Links

Trading Reference Links

Mike Marcott wrote:
>This is the hard part - for me...
>
>All I am trying to do is run an hourly system on a 1min bar chart so I 
>can autoexecute my stop loss order within 1 min of my order so I'm not 
>exposing myself to adverse market moves.

Have you tried using "sliding window" hourly bars?  That is, every
minute, the OHLC values come from the last 60 bars.  That's a lot
easier than what you're trying to do, and in some strategies the
performance is better too.

Other than that...

If you want hourly bars at the 30 minute mark of each hour (which I
think is what you want), then the following code will store the OHLC
values in arrays op, hi, lo, and cl, such that hi[0] is the most
recent 60-minute high, hi[1] is the high of the previous 60-minute
bar, etc.

arrays: op[50](0), hi[50](0), lo[50](0), cl[50](0);
vars: j(0), modtime(0), lastbarnum(0);
modtime = mod(timetominutes(time)+30, 60);
if modtime < modtime[1] then begin {new bar starting}
   for j = 50 downto 1 begin {shift array to make room}
      op[j] = op[j-1];
      hi[j] = hi[j-1];
      lo[j] = lo[j-1];
      cl[j] = cl[j-1];
   end;
   j = currentbar - lastbarnum;
   op[0] = Open[j-1];
   hi[0] = Highest(High, j);
   lo[0] = Lowest(Low, j);
   cl[0] = Close;
   lastbarnum = currentbar;
end;

You could also keep track of the hi and lo values on the fly, but
the code above executes only every 60 minutes so speed shouldn't
matter.

The code above is UNTESTED (I just made it up) but it should give
you the idea of what's going on.  It should work for trading hours
that have less than 60 bars (this is what the 'lastbarnum' variable
is for).  It should also work if there happens to be no activity on
the 1-minute bar occurring at the 30-minute mark (in which case it
will use the next bar as the end of the hour).

-- 
  ,|___    Alex Matulich -- alex@xxxxxxxxxxxxxx
 // +__>   Director of Research and Development
 //  \ 
 // __)    Unicorn Research Corporation -- http://unicorn.us.com