How to identify the closest pivot points level to current price

Viewing 9 posts - 16 through 24 (of 24 total)
  • Author
    Posts
  • #91013 quote
    Vonasi
    Moderator
    Master

    Also be aware that on a Monday your daily pivots will be based on a small Sunday candle.

    #91014 quote
    juanj
    Participant
    Master

    Already made provision for the Sunday candle on Mondays by using DClose(2), DHigh(2) and DLow(2) if dayofweek = 1

    #91015 quote
    juanj
    Participant
    Master

    It is almost like the code only updates line 68-237 Daily instead of on the Timeframe(Default) as specified.

    #91017 quote
    juanj
    Participant
    Master

    Found 3 major bugs in my code, Line 119, 175, 231 (each should be the same Pivot as in the first part of the if statement). Typical copy/paste issue 🙂

    #91019 quote
    juanj
    Participant
    Master

    Okay so here is the ‘fixed’ code. It now correctly identifies the pivot directly above and below the last close. I am now trying to find the pivot levels two levels above an below the code. The logic I am now following is that I am measuring against either PivotAbove or PivotBelow instead of close. When graphed the results are correct here and there but often it either makes PivotAbove2 = PivotAbove or PivotBelow2 = PivotBelow

    Defparam cumulateorders = False
    
    //pivot calculations
    
    Timeframe(Monthly)
    
    MHigh = high[1]
    MClose = close[1]
    MLow = low[1]
    
    MPivot = (MHigh + MLow + MClose)/3 //Monthly Pivot Calculation
    
    MR1 = MPivot*2-MLow
    MS1 = MPivot*2-MHigh
    MR2 = MPivot+(MHigh-MLow)
    MS2 = MPivot-(MHigh-MLow)
    MR3 = MHigh+(2*(MPivot-MLow))
    MS3 = MLow-(2*(MHigh-MPivot))
    
    Timeframe(Weekly)
    
    WHigh = high[1]
    WClose = close[1]
    WLow = low[1]
    
    WPivot = (WHigh + WLow + WClose)/3 //Weekly Pivot Calculation
    
    WR1 = WPivot*2-WLow
    WS1 = WPivot*2-WHigh
    WR2 = WPivot+(WHigh-WLow)
    WS2 = WPivot-(WHigh-WLow)
    WR3 = WHigh+(2*(WPivot-WLow))
    WS3 = WLow-(2*(WHigh-WPivot))
    
    TImeframe(Default)
    
    If dayofweek = 1 Then
    DPivot = (DHigh(2) + DLow(2) + DClose(2))/3 //Daily Pivot Calculation
    
    DR1 = DPivot*2-Dlow(2)
    DS1 = DPivot*2-DHigh(2)
    DR2 = DPivot+(DHigh(2)-DLow(2))
    DS2 = DPivot-(DHigh(2)-DLow(2))
    DR3 = DHigh(2)+(2*(DPivot-DLow(2)))
    DS3 = DLow(2)-(2*(DHigh(2)-DPivot))
    Else
    DPivot = (DHigh(1) + DLow(1) + DClose(1))/3 //Daily Pivot Calculation
    
    DR1 = DPivot*2-Dlow(1)
    DS1 = DPivot*2-DHigh(1)
    DR2 = DPivot+(DHigh(1)-DLow(1))
    DS2 = DPivot-(DHigh(1)-DLow(1))
    DR3 = DHigh(1)+(2*(DPivot-DLow(1)))
    DS3 = DLow(1)-(2*(DHigh(1)-DPivot))
    EndIf
    
    //If MR1 + MS1 + MR2 + MS2 + MR3 + MS3 + Mpivot + WR1 + WS1 + WR2 + WS2 + WR3 + WS3 + Wpivot + DR1 + DS1 + DR2 + DS2 + DR3 + DS3 + Dpivot = 0 Then
    //EndIf
    
    //Find Pivot One Level Above and Below Close
    
    If MR1 > close Then
    MR1Above = MR1
    MR1Below = 0
    ElsIf MR1 < close Then
    MR1Below = MR1
    MR1Above = 100000
    EndIf
    
    If MS1 > close Then
    MS1Above = MS1
    MS1Below = 0
    ElsIf MS1 < close Then
    MS1Below = MS1
    MS1Above = 100000
    EndIf
    
    If MR2 > close Then
    MR2Above = MR2
    MR2Below = 0
    ElsIf MR2 < close Then
    MR2Below = MR2
    MR2Above = 100000
    EndIf
    
    If MS2 > close Then
    MS2Above = MS2
    MS2Below = 0
    ElsIf MS2 < close Then
    MS2Below = MS2
    MS2Above = 100000
    EndIf
    
    If MR3 > close Then
    MR3Above = MR3
    MR3Below = 0
    ElsIf MR3 < close Then
    MR3Below = MR3
    MR3Above = 100000
    EndIf
    
    If MS3 > close Then
    MS3Above = MS3
    MS3Below = 0
    ElsIf MS3 < close Then
    MS3Below = MS3
    MS3Above = 100000
    EndIf
    
    If MPivot > close Then
    MPivotAbove = MPivot
    MPivotBelow = 0
    ElsIf MPivot < close Then
    MPivotBelow = MPivot
    MPivotAbove = 100000
    EndIf
    
    If WR1 > close Then
    WR1Above = WR1
    WR1Below = 0
    ElsIf WR1 < close Then
    WR1Below = WR1
    WR1Above = 100000
    EndIf
    
    If WS1 > close Then
    WS1Above = WS1
    WS1Below = 0
    ElsIf WS1 < close Then
    WS1Below = WS1
    WS1Above = 100000
    EndIf
    
    If WR2 > close Then
    WR2Above = WR2
    WR2Below = 0
    ElsIf WR2 < close Then
    WR2Below = WR2
    WR2Above = 100000
    EndIf
    
    If WS2 > close Then
    WS2Above = WS2
    WS2Below = 0
    ElsIf WS2 < close Then
    WS2Below = WS2
    WS2Above = 100000
    EndIf
    
    If WR3 > close Then
    WR3Above = WR3
    WR3Below = 0
    ElsIf WR3 < close Then
    WR3Below = WR3
    WR3Above = 100000
    EndIf
    
    If WS3 > close Then
    WS3Above = WS3
    WS3Below = 0
    ElsIf WS3 < close Then
    WS3Below = WS3
    WS3Above = 100000
    EndIf
    
    If WPivot > close Then
    WPivotAbove = WPivot
    WPivotBelow = 0
    ElsIf WPivot < close Then
    WPivotBelow = WPivot
    WPivotAbove = 100000
    EndIf
    
    If DR1 > close Then
    DR1Above = DR1
    DR1Below = 0
    ElsIf DR1 < close Then
    DR1Below = DR1
    DR1Above = 100000
    EndIf
    
    If DS1 > close Then
    DS1Above = DS1
    DS1Below = 0
    ElsIf DS1 < close Then
    DS1Below = DS1
    DS1Above = 100000
    EndIf
    
    If DR2 > close Then
    DR2Above = DR2
    DR2Below = 0
    ElsIf DR2 < close Then
    DR2Below = DR2
    DR2Above = 100000
    EndIf
    
    If DS2 > close Then
    DS2Above = DS2
    DS2Below = 0
    ElsIf DS2 < close Then
    DS2Below = DS2
    DS2Above = 100000
    EndIf
    
    If DR3 > close Then
    DR3Above = DR3
    DR3Below = 0
    ElsIf DR3 < close Then
    DR3Below = DR3
    DR3Above = 100000
    EndIf
    
    If DS3 > close Then
    DS3Above = DS3
    DS3Below = 0
    ElsIf DS3 < close Then
    DS3Below = DS3
    DS3Above = 100000
    EndIf
    
    If DPivot > close Then
    DPivotAbove = DPivot
    DPivotBelow = 0
    ElsIf DPivot < close Then
    DPivotBelow = DPivot
    DPivotAbove = 100000
    EndIf
    
    PivotAbove = min(min(min(min(min(min(min(min(min(min(min(min(min(min(min(min(min(min(min(min(MR1Above,MS1Above),MR2Above),MS2Above),MR3Above),MS3Above),MPivotAbove),WR1Above),WS1Above),WR2Above),WS2Above),WR3Above),WS3Above),WPivotAbove),DR1Above),DS1Above),DR2Above),DS2Above),DR3Above),DS3ABove),DPivotAbove)
    PivotBelow = max(max(max(max(max(max(max(max(max(max(max(max(max(max(max(max(max(max(max(max(MR1Below,MS1Below),MR2Below),MS2Below),MR3Below),MS3Below),MPivotBelow),WR1Below),WS1Below),WR2Below),WS2Below),WR3Below),WS3Below),WPivotBelow),DR1Below),DS1Below),DR2Below),DS2Below),DR3Below),DS3Below),DPivotBelow)
    
    //Find Pivot Two Levels Above and Below Close
    
    If MR1 > PivotAbove Then
    MR1Above2 = MR1
    MR1Below2 = 0
    ElsIf MR1 < PivotBelow Then
    MR1Below2 = MR1
    MR1Above2 = 100000
    EndIf
    
    If MS1 > PivotAbove Then
    MS1Above2 = MS1
    MS1Below2 = 0
    ElsIf MS1 < PivotBelow Then
    MS1Below2 = MS1
    MS1Above2 = 100000
    EndIf
    
    If MR2 > PivotAbove Then
    MR2Above2 = MR2
    MR2Below2 = 0
    ElsIf MR2 < PivotBelow Then
    MR2Below2 = MR2
    MR2Above2 = 100000
    EndIf
    
    If MS2 > PivotAbove Then
    MS2Above2 = MS2
    MS2Below2 = 0
    ElsIf MS2 < PivotBelow Then
    MS2Below2 = MS2
    MS2Above2 = 100000
    EndIf
    
    If MR3 > PivotAbove Then
    MR3Above2 = MR3
    MR3Below2 = 0
    ElsIf MR3 < PivotBelow Then
    MR3Below2 = MR3
    MR3Above2 = 100000
    EndIf
    
    If MS3 > PivotAbove Then
    MS3Above2 = MS3
    MS3Below2 = 0
    ElsIf MS3 < PivotBelow Then
    MS3Below2 = MS3
    MS3Above2 = 100000
    EndIf
    
    If MPivot > PivotAbove Then
    MPivotAbove2 = MPivot
    MPivotBelow2 = 0
    ElsIf MPivot < PivotBelow Then
    MPivotBelow2 = MPivot
    MPivotAbove2 = 100000
    EndIf
    
    If WR1 > PivotAbove Then
    WR1Above2 = WR1
    WR1Below2 = 0
    ElsIf WR1 < PivotBelow Then
    WR1Below2 = WR1
    WR1Above2 = 100000
    EndIf
    
    If WS1 > PivotAbove Then
    WS1Above2 = WS1
    WS1Below2 = 0
    ElsIf WS1 < PivotBelow Then
    WS1Below2 = WS1
    WS1Above2 = 100000
    EndIf
    
    If WR2 > PivotAbove Then
    WR2Above2 = WR2
    WR2Below2 = 0
    ElsIf WR2 < PivotBelow Then
    WR2Below2 = WR2
    WR2Above2 = 100000
    EndIf
    
    If WS2 > PivotAbove Then
    WS2Above2 = WS2
    WS2Below2 = 0
    ElsIf WS2 < PivotBelow Then
    WS2Below2 = WS2
    WS2Above2 = 100000
    EndIf
    
    If WR3 > PivotAbove Then
    WR3Above2 = WR3
    WR3Below2 = 0
    ElsIf WR3 < PivotBelow Then
    WR3Below2 = WR3
    WR3Above2 = 100000
    EndIf
    
    If WS3 > PivotAbove Then
    WS3Above2 = WS3
    WS3Below2 = 0
    ElsIf WS3 < PivotBelow Then
    WS3Below2 = WS3
    WS3Above2 = 100000
    EndIf
    
    If WPivot > PivotAbove Then
    WPivotAbove2 = WPivot
    WPivotBelow2 = 0
    ElsIf WPivot < PivotBelow Then
    WPivotBelow2 = WPivot
    WPivotAbove2 = 100000
    EndIf
    
    If DR1 > PivotAbove Then
    DR1Above2 = DR1
    DR1Below2 = 0
    ElsIf DR1 < PivotBelow Then
    DR1Below2 = DR1
    DR1Above2 = 100000
    EndIf
    
    If DS1 > PivotAbove Then
    DS1Above2 = DS1
    DS1Below2 = 0
    ElsIf DS1 < PivotBelow Then
    DS1Below2 = DS1
    DS1Above2 = 100000
    EndIf
    
    If DR2 > PivotAbove Then
    DR2Above2 = DR2
    DR2Below2 = 0
    ElsIf DR2 < PivotBelow Then
    DR2Below2 = DR2
    DR2Above2 = 100000
    EndIf
    
    If DS2 > PivotAbove Then
    DS2Above2 = DS2
    DS2Below2 = 0
    ElsIf DS2 < PivotBelow Then
    DS2Below2 = DS2
    DS2Above2 = 100000
    EndIf
    
    If DR3 > PivotAbove Then
    DR3Above2 = DR3
    DR3Below2 = 0
    ElsIf DR3 < PivotBelow Then
    DR3Below2 = DR3
    DR3Above2 = 100000
    EndIf
    
    If DS3 > PivotAbove Then
    DS3Above2 = DS3
    DS3Below2 = 0
    ElsIf DS3 < PivotBelow Then
    DS3Below2 = DS3
    DS3Above2 = 100000
    EndIf
    
    If DPivot > PivotAbove Then
    DPivotAbove2 = DPivot
    DPivotBelow2 = 0
    ElsIf DPivot < PivotBelow Then
    DPivotBelow2 = DPivot
    DPivotAbove2 = 100000
    EndIf
    
    PivotAbove2 = min(min(min(min(min(min(min(min(min(min(min(min(min(min(min(min(min(min(min(min(MR1Above2,MS1Above2),MR2Above2),MS2Above2),MR3Above2),MS3Above2),MPivotAbove2),WR1Above2),WS1Above2),WR2Above2),WS2Above2),WR3Above2),WS3Above2),WPivotAbove2),DR1Above2),DS1Above2),DR2Above2),DS2Above2),DR3Above2),DS3Above2),DPivotAbove2)
    PivotBelow2 = max(max(max(max(max(max(max(max(max(max(max(max(max(max(max(max(max(max(max(max(MR1Below2,MS1Below2),MR2Below2),MS2Below2),MR3Below2),MS3Below2),MPivotBelow2),WR1Below2),WS1Below2),WR2Below2),WS2Below2),WR3Below2),WS3Below2),WPivotBelow2),DR1Below2),DS1Below2),DR2Below2),DS2Below2),DR3Below2),DS3Below2),DPivotBelow2)
    
    Graph PivotAbove coloured(255,0,0) as "Pivot Above"
    Graph PivotBelow coloured(0,255,0) as "Pivot Below"
    Graph PivotAbove2 coloured(255,0,0) as "Pivot Above 2"
    Graph PivotBelow2 coloured(0,255,0) as "Pivot Below 2"
    
    Buy possize contract at market
    
    Graph close[1] coloured(0,0,0) as "close"
    //Graph MPivot coloured(255,0,0) as "MPivot"
    //Graph WPivot coloured(0,255,0) as "WPivot"
    //Graph DPivot coloured(0,0,255) as "DPivot" //DP 47173 DR1 47190 DR2 47225
    
    #91028 quote
    Nicolas
    Keymaster
    Master

    With this small code snippet, you’ll be able to find the nearest pivot points: (lines 26 to 89)

    https://www.prorealcode.com/topic/fractal-systeme/page/2/#post-88943

    Adapt it to weekly, monthly points..

    Vonasi thanked this post
    #91029 quote
    Vonasi
    Moderator
    Master

    I’ve now had time to actually read your code! I can’t explain why you sometimes get exactly the same values – maybe you need to graph every pivot line and see what their values actually are.

    Also I notice sometimes that there may not actually be a pivot line above or below price and so you are left with a value of 10000 or zero. Not a major problem in a strategy as long as you take it into consideration in the code.

    #91035 quote
    juanj
    Participant
    Master

    @Nicolas @Vonasi, thank you for all your help managed to get my code working perfectly. Just had to initialize each Pivot Above and Pivot Below level at the beginning instead of in the If statements.

    #91042 quote
    GraHal
    Participant
    Master

    With this small code snippet, you’ll be able to find the nearest pivot points: (lines 26 to 89)

    I just added above to here 

    Snippet Link Library

Viewing 9 posts - 16 through 24 (of 24 total)
  • You must be logged in to reply to this topic.

How to identify the closest pivot points level to current price


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
juanj @juanj Participant
Summary

This topic contains 23 replies,
has 5 voices, and was last updated by GraHal
7 years ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 02/10/2019
Status: Active
Attachments: No files
Logo Logo
Loading...