I'm currently using something I found on the forum, a DLL function import of MS 'Sleep([seconds])' function.
Wanted to make sure this was correct, I kind of doubled up on logic to be sure. I'm trying to use microseconds, and eventually add in variance to the latency randomly to simulate actual conditions. First things first :
Code: Select all
//[function_name = sleep_delay, BOOLEAN]
inputs:
delay_in_us(numericsimple);
//varBool(0),
//var_plus_minus(50);
vars:
s(0),
beg_delay(0),
end_delay(0);
//Sleep Function import from DLL
DEFINEDLLFUNC: ThreadSafe,"Kernel32.dll",void,"Sleep",dword;
//In Milliseconds, divide by 1k to convert to microseconds
Sleep(delay_in_us/1000);
if time <> time[1] then
begin
beg_delay = millisecondsfromdatetime(computerdatetime);
end_delay = beg_delay+.25 //250us in milliseconds
Sleep(delay_in_us);
if millisecondsfromdatetime(computerdatetime) > end_delay then sleep_delay = True;
end
else
sleep_delay = False;
// In Strategy Code (Tick data):
vars: run(false);
if LongCondition then
begin
run = sleep_delay(250);
if run then buy this bar at close;
end;
//Same for short.
Let me know if I'm missing something -- My thoughts:
If it's buying on a close, I may be waiting for a close regardless?
(I've heard there's ms data somewhere, don't know where to find if so)
Want to confirm it's running before every order, not just once then caching.
Thanks!
Zach