Wrong Pivot points on Futures NQ and DJ

Viewing 15 posts - 31 through 45 (of 53 total)
  • Author
    Posts
  • #227580 quote
    LucasBest
    Participant
    Average
    ONCE DayH = high
    ONCE DayL = low
    ONCE DayC = close
    ONCE FullDay = 0
    ONCE FullWeek = 0
    ONCE FullMonth = 0
    
    IF (OpenTime=010000 and dayofweek<>1) or (dayofweek<DAYOFWEEK[1]) THEN
    
    drawvline(barindex)
    
    if dayofweek <> 1 or (dayofweek<DAYOFWEEK[1]) THEN
    PivotDuJour  = (DHigh(1) + DLow(1) + DClose(1)) / 3
    elsif dayofweek = 1 then
    PivotDuJour  = (DHigh(2) + DLow(2) + DClose(2)) / 3
    endif
    
    MonthH = max(MonthH,DayH)
    MonthL = min(MonthL,DayL)
    MonthC = DayC
    WeekH = max(WeekH,DayH)
    WeekL = min(WeekL,DayL)
    WeekC = DayC
    
    
    pDayofWeekI = DayofWeekI
    pDayI = DayI
    pDayH = DayH
    pDayL = DayL
    pDayC = DayC
    DayofWeekI = DayofWeek
    DayI = Day
    DayH = High
    DayL = Low
    DayC = Close
    
    If FullDay then
    DayPivot = (pDayH + pDayL + pDayC)/3
    Else
    DayPivot = undefined
    FullDay = 1
    Endif
    
    If DayofWeekI < pDayofWeekI then
    pWeekH = WeekH
    pWeekL = WeekL
    pWeekC = WeekC
    WeekH = High
    WeekL = Low
    WeekC = Close
    
    If FullWeek then
    WeekPivot = (pWeekH + pWeekL + pWeekC)/3
    Else
    WeekPivot = undefined
    FullWeek = 1
    Endif
    //drawvline(barindex)
    Endif
    
    If DayI < pDayI then
    pMonthH = MonthH
    pMonthL = MonthL
    pMonthC = MonthC
    MonthH = High
    MonthL = Low
    MonthC = Close
    
    If FullMonth then
    MonthPivot = (pMonthH + pMonthL + pMonthC)/3
    Else
    MonthPivot = undefined
    FullMonth = 1
    Endif
    //drawvline(barindex)
    Endif
    
    ENDIF
    
    DayH = max(DayH,high)
    DayL = min(DayL,low)
    DayC = close
    
    Return dayofweek
    

    Can you test this last one at same barindex as previously ?

    Capture-decran-2024-02-07-152927.png Capture-decran-2024-02-07-152927.png
    #227589 quote
    Jerome888
    Participant
    Average

    Attached, thank you

    4.png 4.png
    #227599 quote
    LucasBest
    Participant
    Average

    Weird, dayofweek is supposed to change at 1 am (at the end of the bar that begin at 0h55min to be more accurate, not at 7 am…

    Is it the same for Allemagne 40 (DAX) ?

    #227600 quote
    Jerome888
    Participant
    Average

    Yes it is a known problem on PRT with  futures. That s why in one of the first post i have included a code correcting this.

    #227603 quote
    LucasBest
    Participant
    Average

    Yes it is a known problem on PRT with futures. That s why in one of the first post i have included a code correcting this.

    Is your Nasdaq future is differnt from US Tech 100 CFD (from IG) ? If it is, tell me how you do to put the Nasdaq future on PRT so i will be able to solve your problem… The code i posted works for CFD index that have Dayofweek change at 1 am. Mayb i need an other broker ?

    If i want to do the same for future i have to do sevral tests while coding it…

    Jerome888 thanked this post
    #227604 quote
    Jerome888
    Participant
    Average

    To access the futures you would need to use the “other” PRT (with broker IB) a demo account is enough. Probuilder code is the same.

     

    Then instead of searching for us tech 100… you search for NQXXXX

    Then you have the futures nasdaq in front of the eyes ! 🙂 thank you a lot

    #227606 quote
    Jerome888
    Participant
    Average
    #227625 quote
    Jerome888
    Participant
    Average

    Now it works.

    The problem was the use of Close[1] instead of DClose(1) which corresponds is the Settlement Price (Prix de Règlement) and can be different from Close[1].

    Here the code which works and which “correct” also the PRT bug about the fact that the dayofWeek changes only at 7:00 on some futures.

    defparam drawonlastbaronly = true
    
    myTime=Time
    myDay=day
    myMonth=month
    myYear=Year
    
    if (myTime>=000000 and myTime<= 065959) then
    myDay=myDay+1
    
    if myYear <> myYear[1] then
    if ((myYear mod 4 = 0) and (myYear mod 100 <> 0)) or (myYear mod 400 = 0) then
    MaxDayInFeburary=29
    else
    MaxDayInFeburary=28
    endif
    endif
    
    if myMonth=1 and myDay>31 then
    myMonth=2
    myDay=1
    elsif myMonth=2 and myDay>MaxDayInFeburary then
    myMonth=3
    myDay=1
    elsif myMonth=3 and myDay>31 then
    myMonth=4
    myDay=1
    elsif myMonth=4 and myDay>30 then
    myMonth=5
    myDay=1
    elsif myMonth=5 and myDay>31 then
    myMonth=6
    myDay=1
    elsif myMonth=6 and myDay>30 then
    myMonth=7
    myDay=1
    elsif myMonth=7 and myDay>31 then
    myMonth=8
    myDay=1
    elsif myMonth=8 and myDay>31 then
    myMonth=9
    myDay=1
    elsif myMonth=9 and myDay>30 then
    myMonth=10
    myDay=1
    elsif myMonth=10 and myDay>31 then
    myMonth=11
    myDay=1
    elsif myMonth=11 and myDay>30 then
    myMonth=12
    myDay=1
    elsif myMonth=12 and myDay>31 then
    myMonth=1
    myDay=1
    endif
    endif
    
    
    
    //PRC_MonthlyPivotPoints | indicator
    //26.10.2016
    //Nicolas @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    //adapted from PRT original indicator
     
    //select mode of calculation of the Monthly pivot points (0,1,2)
    mode = 0
    If myMonth<>myMonth[1] then
    MonthlyHigh = Highest[max(1,BarIndex - lastMonthBarIndex)](High)[1]
    MonthlyLow = Lowest[max(1,BarIndex - lastMonthBarIndex)](Low)[1]
    lastMonthBarIndex = BarIndex
    a=DClose(1)
    If mode = 0 then
    MonthlyPivot = (MonthlyHigh + MonthlyLow + DClose(1)) / 3
    Elsif mode = 1 then
    MonthlyPivot = (Open + MonthlyHigh + MonthlyLow + DClose(1)) / 4
    Elsif mode = 2 then
    MonthlyPivot = (MonthlyHigh + MonthlyLow + DClose(1)*2) / 4
    Else
    MonthlyPivot = (Open*2 + MonthlyHigh + MonthlyLow) / 4
    Endif
    MonthlyR1 = 2*MonthlyPivot - MonthlyLow
    MonthlyS1 = 2*MonthlyPivot - MonthlyHigh
    MonthlyR2 = MonthlyPivot + (MonthlyHigh - MonthlyLow)
    MonthlyS2 = MonthlyPivot - (MonthlyHigh - MonthlyLow)
    MonthlyR3 = MonthlyR1 + (MonthlyHigh - MonthlyLow)
    MonthlyS3 = MonthlyS1 - (MonthlyHigh - MonthlyLow)
    Endif
    //
    return MonthlyPivot as "Monthly P", MonthlyR1 as "Monthly R1", MonthlyS1 as "Monthly S1", MonthlyR2 as "Monthly R2", MonthlyS2 as "Monthly S2", MonthlyR3 as "Monthly R3", MonthlyS3 as "Monthly S3"
    

    Thank you a lot LucasBest for your valuable support. If you see any improvements to be brought to this code, it is very welcome, I saw you publish a lot of good things here on the forum…

    PeterSt thanked this post
    #227626 quote
    Jerome888
    Participant
    Average

    Remain still the problem of managing the hours changes… summer/winter : sometimes the day does not change at 7:00 but at 6:00

    #227628 quote
    Jerome888
    Participant
    Average

    For 2023 I have just brought weeksofShift and TimeOfDayChange pfor managing the week difference between Paris and US…

    weeksOfShift = (myMonth=3 and (myDay>=12 and myDay<=26)) or ((myMonth=10 and myDay>=29) or (myMonth=11 and myDay<=5))
    if weeksOfShift then
    TimeofDayChange=055959
    else
    TimeofDayChange=065959
    endif

    weeksOfShift = (myMonth=3 and (myDay>=12 and myDay<=26)) or ((myMonth=10 and myDay>=29) or (myMonth=11 and myDay<=5))
    if weeksOfShift then
    TimeofDayChange=055959
    else
    TimeofDayChange=065959
    endif
    
    
    if (myTime>=000000 and myTime<= TimeofDayChange)  then
    myDay=myDay+1
    ...................

    Now I am looking for a code which defines the date (day and month) of the last sunday of March and the last sunday of October  automatically (for a given year)

    #227633 quote
    PeterSt
    Participant
    Master

    Jerome, that will not help you, as it is not only about our Daylight Saving but also about the US. In the past years I experienced a difference that lasted 1 week, 2 weeks and even 3 weeks.
    The rule in the US I don’t know. Ours is what you suggested (end of March etc.).

    Peter

    Jerome888 thanked this post
    #227634 quote
    Jerome888
    Participant
    Average

    Thank you Peter, I think you are right, a manual entry for each year is better

    #227635 quote
    PeterSt
    Participant
    Master

    The problem was the use of Close[1] instead of DClose(1) which corresponds is the Settlement Price (Prix de Règlement) and can be different from Close[1].

    Wow, I did not know this existed. But exactly as what was asked here : and with this response from Nicolas :

    Dclose returns the official daily close of the instrument.

    which to me in the context of the “constant” is the same as No answer … would it be true indeed that for the DAX this would return 17:30 ? Please remember, the DAX closes at 22:00.
    It would mean 22:00 for ES and NQ (etc.) which close at 23:00.

    Of course I like to believe you. Did you test this ? (which I could do myself – haha).
    The manual (“Programming Guide” – ProBacktest and ProOrder) does not tell much about it. And if anything it is what Nicolas literally said (quote above). The manual speaks in the context of “and it does not depend on your TimeZone settings”. Not that I can warp my head around that. 🙂

    Curious …

    #227636 quote
    PeterSt
    Participant
    Master

    Thank you Peter, I think you are right, a manual entry for each year is better

    I am quite sure you don’t need this. So just in case :

    DLS = 0   // 30-10-2022,PS. 0 = Normal. 1 = Autumn. 2 = Spring.
    
    If Date >= 20221031 and Date <= 20221104 then
      DLS = 1   // Autumn. USA is one hour early.
    elsif Date >= 20230312 and Date <= 20230326 then   // 11-03-2023,PS.
      DLS = 2   // Spring. USA is one hour early.
    endif  
      
    // 29-10-2023,PS, Justadd a group for convenience (no difficult If/Else stuff). 
    // And the above can even be used for more history backtesting.
    
    If Date >= 20231029 and Date <= 20231105 then
      DLS = 1   // Autumn. USA is one hour early.
    elsif Date >= 20240310 and Date <= 20240331 then
      DLS = 2   // Spring. USA is one hour early.
    endif  
    
    Jerome888 thanked this post
    #227637 quote
    PeterSt
    Participant
    Master

    … If DClose really would do what you describe, it would even solve the problem of White Thursday, Good Friday and other crazy stuff like following Easter on Monday which does not exist in the US, but where they these days make up various other holidays on such days (as Easter Monday). N.b.: I think in this thread you talked about this too ?
    Anyway, we could make an indicator for that, so we can just see it coming, instead of trying to look it up for the xth time, knowing that IBKR is sparse with such data (IG is OK).

    PS: The crazy stuff is about not being able to judge your daily gain properly because it depends on the Settlement dates/times (DAX is a daily pain if you’re not used to it).

    Jerome888 thanked this post
Viewing 15 posts - 31 through 45 (of 53 total)
  • You must be logged in to reply to this topic.

Wrong Pivot points on Futures NQ and DJ


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Jerome888 @jerome888 Participant
Summary

This topic contains 52 replies,
has 6 voices, and was last updated by PeterSt
2 years, 1 month ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 02/05/2024
Status: Active
Attachments: 26 files
Logo Logo
Loading...