I keep getting floating-point errors in my strategy code. I don't get these errors in TS. Does anyone have any ideas?
Thanks
Code: Select all
long_entry = highest(h,entry_chan) + entry_offset;
short_entry = lowest(l,entry_chan) - entry_offset;
tl_stop = tl_getvalue(1, currentdate, currenttime);
//============================= POSTION SIZING =============================
if direction = 1 then
if lowest(l,5) > tl_stop then istop = tl_stop else if lowest(l,5) <= tl_stop then istop = lowest(l,5) - entry_offset;
value1 = (risk /(long_entry - istop))/100;
if direction = -1 then
if highest(h,5) < tl_stop then istop = tl_stop else if highest(h,5) >= tl_stop then istop = highest(h,5) + entry_offset;
value1 = (risk /(istop - short_entry))/100;
//============================= ROUNDING =============================
if value1 < 1 then value2 = round(value1,2);
if value1 > 1 then value2 = round(value1,1);
if value1 > 5 then value2 = round(value1/.5,0)*.5;
if value1 > 10 then value2 = round(value1,0);
positionsize = value2 * 100;