RC3 B136 Highest/Lowest in range bug

When TimeToFrom + curDayStartTime becomes larger than a day, the values for Highest/lowest in range are screwed.

it is possible to see that simply testing a strategy that have that indicator on 2 different Timezone.



i attach a test of a strategy Btested with data from EST07 and GMT+1 DST US.


on a simple H1 strategy that is a big issue, becouose if someone of us have 2 or 3 brokers on different Timezone, can not use the strategy.



Attachments
HighestLowestInRange.png
(63.01 KiB)
  • Votes +10
  • Project StrategyQuant X
  • Type Bug
  • Status New
  • Priority Normal

History

l
#1

Loonly

13.12.2022 20:27

Task created

l
#2

Loonly

13.12.2022 20:29

Description changed:

When TimeToFrom + curDayStartTime becomes larger than a day, the values for Highest/lowest in range are screwed.

it is possible to see that simply testing a strategy that have that indicator on 2 different Timezone.



i attach a test of a strategy Btested with data from EST07 and GMT+1 DST US.


on a simple H1 strategy that is a big issue, becouose if someone of us have 2 or 3 brokers on different Timezone, can not use the strategy.




TR
#3

Tim

13.12.2022 20:33
Voted for this task.
b
#4

bentra

13.12.2022 21:05
Voted for this task.
l
#5

Loonly

13.12.2022 21:17
Voted for this task.
b
#6

bentra

13.12.2022 21:29


it is like the highest from 2 AM TO 0:30 AM next day. So I am afraid if you shift from UTC + 2 2 AM to 0:30 AM to UTC + 1 which will be 1 AM to 23:30 PM previous day the level will be very different. You might try to alter the shift [2] to correct that and use the same prices Hope this might help or let me know if you have any issues still Sincerely, Tomas Matejka StrategyQuant Team


It's a bug, this should all be accounted for in the code. I can show you how to do it if you can't figure it out, I have a similar start time end time function in my own EA which does not have this problem.




k
#7

Karish

13.12.2022 22:29
Voted for this task.
b
#8

bentra

14.12.2022 14:03
The fact that a specific time range doesn't work as expected means there is a bug, whether or not it does actually work correctly in some other time zone is irrelevant. The time zone switching is just happened to be what exposed the bug. In the code I can see you've wisely made the times an offset from day start time but you forgot to account for all scenario's but you're almost there. I can show you how to do it if you can't figure it out, I have a similar start time end time function in my own EA which does not have this problem.


E
#9

Emmanuel

14.12.2022 21:26
Voted for this task.
mb
#10

Michal Brauner

15.12.2022 04:24
Voted for this task.
b
#11

bentra

17.12.2022 18:11

OK I explain what I mean in the universal language of code. This should work but I didn't compile it. Anyways, I'm sure you can see what we need to do now. 
Should do this:
-allows start time to be greater than end time without breaking
-adjusts for all timezones automatically.



    private void calculateSessionTimes(long currentTime) {         long dayStart = SQTime.correctDayStart(currentTime);                  long startTime = dayStart + (startHours * 60 + startMinutes) * 60000; // very nice work! you made the times to be timezone insensitive by incorporating dayStart!         long endTime = dayStart + (endHours * 60 + endMinutes) * 60000;                  // if(startHHMM >= endHHMM) ;{         //    endTime += DAY_MILLIS;         //} NO! don't do this here! This would cause the end time to be the end of the day SERVER TIME.

// Why go through all the trouble of making the times be timezone insensitive and then do this? We will

// account for when end time is lower than begin time elsewhere in the snippet

       // if(currentTime < (endTime - DAY_MILLIS)) ;{

        //    startTime -= DAY_MILLIS;         //    endTime -= DAY_MILLIS;        // }        // else if(currentTime > endTime || endTime == sessionEndTime) {        //     startTime += DAY_MILLIS;        //     endTime += DAY_MILLIS;        // } Lets just get the timezone adjusted start and end times simply? Because I think whatever you're

// trying to do here isn't working we can account later for when start and end times are reversed...

// Account for wrap around times and get the proper times of the triggers if (startTime >= DAY_MILLIS) startTime -= DAY_MILIS;// result should be 0 to 23xx if (endTime >= DAY_MILLIS) endTime -= DAY_MILIS;// result should be 0 to 23xx

        sessionStartTime = startTime;         sessionEndTime = endTime;     }      }





private void calculate() throws TradingException { long currentTime = Chart.Time(dataShift);

calculateSessionTimes(currentTime);// We need to adjust the sessiontimes for the timezone differences here before the other logic if((sessionStartTime < sessionEndTime && currentTime >= sessionEndTime) ||

(sessionStartTime >= sessionEndTime && (currentTime < sessionStartTime && currentTime >= sessionEndTime))) { if(!sessionClose.isEmpty()) { sessionClose.set(0, Chart.Close(dataShift + 1)); long prevTime = Chart.Time(dataShift + 1); if(prevTime >= sessionStartTime && prevTime < sessionEndTime) { sessionHigh.set(0, Math.max(Chart.High(dataShift + 1), sessionHigh.get(0))); sessionLow.set(0, Math.min(Chart.Low(dataShift + 1), sessionLow.get(0))); } } // calculateSessionTimes(currentTime); // I'mpretty sure we need to call this before all the time check logic.... waitingForSession = true; } if((sessionStartTime < sessionEndTime && currentTime >= sessionStartTime) ||

(sessionStartTime >= sessionEndTime && (currentTime < sessionEndTime || currentTime >= sessionStartTime))) {

if(waitingForSession) { waitingForSession = false; sessionOpen.add(0, Chart.Open(dataShift)); sessionHigh.add(0, Chart.High(dataShift)); sessionLow.add(0, Chart.Low(dataShift)); sessionClose.add(0, Chart.Close(dataShift)); } else { sessionHigh.set(0, Math.max(Chart.High(dataShift), sessionHigh.get(0))); sessionLow.set(0, Math.min(Chart.Low(dataShift), sessionLow.get(0))); sessionClose.set(0, Chart.Close(dataShift)); } }













JP
#12

JWP

20.12.2022 07:46
Voted for this task.
CG
#13

Chris G

27.12.2022 11:26
Voted for this task.
a
#14

astral

26.01.2023 17:24
Voted for this task.
BT
#15

EndUser

27.04.2023 16:09
Voted for this task.

Votes: +10

Drop files to upload

or

choose files

Max size: 5MB

Not allowed: exe, msi, application, reg, php, js, htaccess, htpasswd, gitignore

...
Wait please