Pivot Point 4h miscalculation on one day only: August 5, 2020

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #142101 quote
    BobOgden
    Participant
    Average

    Hello everybody,

    I’ve been looking at the different threads that offer some formula to calculate pivot points in order to use it in strategies and I’ve eventually used Nicolas’s that you may find here : https://www.prorealcode.com/prorealtime-indicators/fibonacci-pivots-points-4-hours-daily-weekly-monthly/

    (Thank you very much Nicolas, you’ve been a tremendous help)

     

    I’ve kept this part only (from line 50 to 56 in the original post)

     if minute=0 and (hour=0 or hour=4 or hour=8 or hour=12 or hour=16 or hour=20) then
      hhigh = Highest[BarIndex - last4HourBarIndex](High)[1]
      llow = Lowest[BarIndex - last4HourBarIndex](Low)[1]
      cclose=close[0]
      last4HourBarIndex = BarIndex[0]
      firstbar=barindex[0]
     endif

    I’ve changed the first line adding 1 to each hour because otherwise ProOrder wouldn’t take  the right hour frames into account. Probably because I’m on a different time frame on PRT, but it doesn’t seem to matter really.

     

    I’ve used it on the DAX30 and I have checked around 20 occurrences and it works like a charm… except on one day.

    On August 5, 2020, from 9 am to 13 (so 8 to 12 with the normal time frame), the pivot point is supposed to be 12 658,53 but the code’s calculation makes it 12 656,27.

    Previous close is 12682, previous high is 12688,3 and previous low is 12605,3.

    It does the same from 5 pm to 9 (so 4 pm to 8 on a normal time frame) on the same day!

     

    You may try it out for yourself with this bit of code :

    (don’t forget to change the first line depending on your time frame)

    //************************************
    // Définition des paramètres du code
    defparam CumulateOrders = False // Cumul des positions désactivé
    
    // Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d'une position avant 8H
    noEntryBeforeTime = 080000
    timeEnterBefore = time >= noEntryBeforeTime
    
    // Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d'une position après 22H
    noEntryAfterTime = 220000
    timeEnterAfter = time < noEntryAfterTime
    
    // Empêche le système de placer de nouveaux ordres le samedi ou dimanche
    daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
    //---------------------------------------------------------
    
    graph4h = 1
    
    //**********************************
    // Définition PP 4h
    if minute=0 and (hour=1 or hour=5 or hour=9 or hour=13 or hour=17 or hour=21) then
    hhigh = Highest[BarIndex - last4HourBarIndex](High)[1]
    llow = Lowest[BarIndex - last4HourBarIndex](Low)[1]
    cclose=close[0]
    last4HourBarIndex = BarIndex[0]
    endif
     
    Piv4h = (hhigh+llow+cclose)/3.0
    
    
    if graph4H then
    graph Piv4h as "pivH4"
    endif
    
    //-----------------------------------------------------
    
    
    
    //************************************
    MyRSI = RSI[14](close) >= 99
    Vosconditions = MyRSI
    if Vosconditions then
    endif
    
    // Conditions pour ouvrir une position acheteuse
    if timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry then
    if not LongOnMarket and VosConditions then
    buy 1 contract at market
    endif
    endif
    
    // Conditions pour fermer une position acheteuse
    //If LongOnMarket AND VosConditions THEN
    //SELL AT MARKET
    //ENDIF
    
    // Stops et objectifs : entrez vos stops et vos objectifs ici
    set stop pLoss 10
    set target pProfit 10
    

     

    I have no idea why there’s a mistake or even where, so if you might help it would be very much appreciated!

    Obviously, I haven’t checked all the possible pivot points but it might have happened elsewhere too without my knowing.

    Sans-titre.png Sans-titre.png
    #142152 quote
    Nicolas
    Keymaster
    Master

    We must grapher the variables of the pivot: hhigh + llow + cclose, and see which one is wrong. If the result is not good, we analyze the calculation and by going up like that you will find the reason for the bad result.

    #142529 quote
    BobOgden
    Participant
    Average

    Hey thx for your help, I should have thought about it.

    So for both Pivot Points, the mistake is that ProOrder doesn’t use the correct hhigh.

    To calculate the PP from 9 am to 13, it uses the hhigh from the candle preceding the closing candle even if the high of the closing candle is higher. For example, with a 2-minute timeframe, it’ll take into consideration the candle from 08:56 to 08:58 instead of the candle from 08:58 to 09:00

     

    To calculate the PP from 5 pm to 9, ProOrder uses the hhigh from the candle preceding the opening candle. For instance, with a 2-minute timeframe, it’ll take into consideration the candle from 12:58 to 13:00 instead of using the candle from 1:34 pm to 1:36.

     

    It might seem that ProOrder’s calculation is always one candle late, meaning for example that it uses the 8:58 to 12:58 timeframe instead of the 09:00 to 13:00 timeframe to get its data. But it collects the correct data for cclose, which means it does include the last candle. Would it mean that it doesn’t include the last candle only to get the hhigh data (and maybe the llow too)?

    Not sure what to do with that… If ever you have any ideas, please let me know.

    #142569 quote
    Nicolas
    Keymaster
    Master

    Try to use OpenHour instead of Hour for your highest/lowest calculation.

    #142686 quote
    BobOgden
    Participant
    Average

    Hey, it has had no effect. Either on hhigh values or llow values. Cclose hasn’t changed either though.

     

    So I’ve checked a few other occurrencies and there’s also a discrepancy between the actual llows and the llows that ProOrder uses.

    For example, on August 26 from 9pm to 1am (8pm to 0pm on a normal timeframe), ProOrder uses the llow from 4:58 to 5:00 when it should only consider the lows from 5:00 to 9:00 to make its calculations.

    There are other similar examples the same day.

     

    In view of the examples given above and the new ones, it leads me to assume that ProOrder (or the code) does use the correct timeframe to collect the cclose but does not to collect the hhigh and llow. It is even more strange that, when using the graph command, all values change at the same time, between the last candle of each 4-hour period.

    #148144 quote
    BobOgden
    Participant
    Average

    @Tanou found the solution in another thread, many thanks!

    In case anyone needs it, here it is:

    //Original code from Tanou
    
    // Calcul Points Pivots 4h
    Int = (OpenTime[1] < 010000 AND OpenTime > 010000) OR (OpenTime[1] < 050000 AND OpenTime > 050000) OR (OpenTime[1] < 090000 AND OpenTime > 090000) OR (OpenTime[1] < 130000 AND OpenTime > 130000) OR (OpenTime[1] < 170000 AND OpenTime > 170000) OR (OpenTime[1] < 210000 AND OpenTime > 210000) OR (Openday <> Openday[1] AND DayOfWeek < DayOfWeek[1])
    IF (OpenTime Mod 40000 = 10000) OR Int THEN
    myLastHigh = myHigh
    myLastLow = myLow
    myLastClose = Close[1]
    myHigh = High
    myLow = Low
    ELSE
    myHigh = Max(myHigh, High)
    myLow = Min(myLow, Low)
    ENDIF
     
    PP = (myLastHigh + myLastLow + myLastClose) / 3
    #149738 quote
    Tanou
    Participant
    Senior

    Glad to see that it helps! 😃😉

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.

Pivot Point 4h miscalculation on one day only: August 5, 2020


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
BobOgden @bobogden Participant
Summary

This topic contains 6 replies,
has 3 voices, and was last updated by Tanou
5 years, 3 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 08/20/2020
Status: Active
Attachments: 1 files
Logo Logo
Loading...