Hi Everyone,
I have an issue with the result produced by the below loop code.
Basically, when body_50 =1 bar[i], then look forward when condition: new row's low[j] < low[i] + add_level_1[i] then mark:
1 - entry_time = time[j]
2 - entry_price =ceil(low[i] * 100) / 100+ add_level_1[i]
As shown in the picture attached, on the row 9:27, body_1 =1 with low[i] + add_level_1[i] = 231.13 and SAS starts look forward.
BUT it pick row 9:30 where low is 131.50 which is bigger than 231.13. It means the condition is Not met and somehow SAS still pick that row.
Any help is very much appreciated.
Thanks,
HHC
proc sort data=ss; by tic date clock_time;run;
data ss1; set ss nobs=nobs;
drop i j_: out ;
format entry_time bigbar time9.;
i+1;
out=0;
by tic;
if body_50=1 then do;
do j=i+1 to nobs until (out=1);
set ss (keep=tic date clock_time low high rename = (tic=J_tic date=J_date clock_time=J_clock_time low=J_low high=J_high) ) point=j;
low_plus_add_level_1=low+add_level_1 ;
gap=(J_clock_time - clock_time) / 60;
if date^=J_date or tic^=J_tic or J_clock_time>'15:30't then do; out=1; leave; end;
else
if gap<20 and J_low<=low+add_level_1 then do;
entry_time=J_clock_time;
entry_price=ceil(low * 100) / 100+ add_level_1;
bigbar=clock_time;
out=1; leave;
end;
else
if gap<60 and J_low<=low+add_level_3 then do;
entry_time=J_clock_time;
entry_price=ceil(low * 100) / 100+ add_level_3;
bigbar=clock_time;
out=1; leave;
end;
else
if gap<120 and J_low<=low+add_level_4 then do;
entry_time=J_clock_time;
entry_price=ceil(low * 100) / 100+ add_level_4;
bigbar=clock_time;
out=1; leave;
end;
else
if gap<180 and J_low<=low+add_level_5 then do;
entry_time=J_clock_time;
entry_price=ceil(low * 100) / 100+ add_level_5;
bigbar=clock_time;
out=1; leave;
end;
else
if gap>=180 and J_low<= low +add_level_6 then do;
entry_time=J_clock_time;
entry_price=ceil(low * 100) / 100+ add_level_6;
bigbar=clock_time;
out=1; leave;
end;
end;
end;
run;
Hi Tom,
Thanks for checking.
I found the issue.
HHC
if gap<60 then do;
if J_low<=low+add_level_3 then do;
entry_time=J_clock_time;
entry_price=ceil(low * 100) / 100+ add_level_3;
bigbar=clock_time;
out=1; leave;
end;end;
else
if gap<120 then do;
if J_low<=low+add_level_4 then do;
entry_time=J_clock_time;
entry_price=ceil(low * 100) / 100+ add_level_4;
bigbar=clock_time;
out=1; leave;
end;end;
else
I do not understand what the LEAVE statements are for. What is it that you want to LEAVE?
Hi Tom,
Thanks for checking.
I found the issue.
HHC
if gap<60 then do;
if J_low<=low+add_level_3 then do;
entry_time=J_clock_time;
entry_price=ceil(low * 100) / 100+ add_level_3;
bigbar=clock_time;
out=1; leave;
end;end;
else
if gap<120 then do;
if J_low<=low+add_level_4 then do;
entry_time=J_clock_time;
entry_price=ceil(low * 100) / 100+ add_level_4;
bigbar=clock_time;
out=1; leave;
end;end;
else
Still don't understand why you have both the LEAVE and the UNTIL().
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.