Croisement période antérieur points pivots

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #115880 quote
    Tanou
    Participant
    Senior

    Bonjour tout le monde!

    Je viens de finir de réussir de bricoler un code pour me donner les pp j/w/m grâce à Nicolas et Roberto! Cependant, je me heurte désormais à un nouveau problème (sinon ce ne serait pas drôle…!), j’aimerai obtenir une condition qui me dise si le prix (close) à croisé le ppm durant les x dernières périodes. Cette condition me serait utile pour éviter de reprendre position si le cours recroise le ppm alors qu’il l’a déjà croisé il y à x temps/barres.

    Auriez-vous une idée?

     

    Merci énormément par avance pour votre aide 🙂

     

    Pour info, voici le code de mon indicateur pour les pp j/w/m:

    //POINT PIVOT JOURNALIER
    
    
    IF dayofweek = 1 THEN
    HighJ = DHigh(2)
    LowJ = DLow(2)
    SettlementJ = DClose(2)
    ENDIF
    
    IF dayofweek >=2 and dayofweek < 6 THEN
    HighJ = DHigh(1)
    LowJ = DLow(1)
    SettlementJ = DClose(1)
    ENDIF
    
    PPJ = (HighJ + LowJ + SettlementJ) / 3
    R3J = HighJ + 2 * (PPJ - LowJ)
    R2J = PPJ + (HighJ - LowJ)
    R1J = (2 * PPJ) - LowJ
    S1J = (2 * PPJ) - HighJ
    S2J = PPJ - (HighJ - LowJ)
    S3J = LowJ - 2 * (HighJ - PPJ)
    
    //POINT PIVOT WEEKLY
    
    If DayOfWeek<DayOfWeek[1] then
    weeklyHigh = Highest[BarIndex - lastWeekBarIndex](High)[1]
    weeklyLow = Lowest[BarIndex - lastWeekBarIndex](Low)[1]
    lastWeekBarIndex = BarIndex
    weeklyPivot = (weeklyHigh + weeklyLow + Close[1]) / 3
    weeklyR1 = 2*weeklyPivot - weeklyLow
    weeklyS1 = 2*weeklyPivot - weeklyHigh
    weeklyR2 = weeklyPivot + (weeklyHigh - weeklyLow)
    weeklyS2 = weeklyPivot - (weeklyHigh - weeklyLow)
    weeklyR3 = weeklyR1 + (weeklyHigh - weeklyLow)
    weeklyS3 = weeklyS1 - (weeklyHigh - weeklyLow)
    Endif
    
    //POINT PIVOT MENSUEL
    
    If Month<>Month[1] then
    monthlyHigh = Highest[BarIndex - lastMonthBarIndex](High)[1]
    monthlyLow = Lowest[BarIndex - lastMonthBarIndex](Low)[1]
    lastMonthBarIndex = BarIndex
    monthlyPivot = (monthlyHigh + monthlyLow + Close[1]) / 3
    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 PPJ COLOURED (0,52,0) style(line) as "Pivot Day", R3J COLOURED (0,128,0) style(line) as "R3J", R2J COLOURED (0,128,0) style(line) as "R2J", R1J COLOURED (0,128,0) style(line) as "R1J", S1J COLOURED (0,128,0) style(line) as "S1J", S2J COLOURED (0,128,0) style(line) as "S2J", S3J COLOURED (0,128,0) style(line) as "S3J", weeklyPivot COLOURED (0,52,0) style(line) as "weeklyPivot", weeklyR1 COLOURED (0,0,128) style(line) as "weeklyR1", weeklyS1 COLOURED (0,0,128) style(line) as "weeklyS1", weeklyR2 COLOURED (0,0,128) style(line) as "weeklyR2", weeklyS2 COLOURED (0,0,128) style(line) as "weeklyS2", weeklyR3 COLOURED (0,0,128) style(line) as "weeklyR3", weeklyS3 COLOURED (0,0,128) style(line) as "weeklyS3", monthlyPivot COLOURED (0,52,0) style(line) as "monthlyPivot", monthlyR1 COLOURED (128,0,0) style(line) as "monthlyR1", monthlyS1 COLOURED (128,0,0) style(line) as "monthlyS1", monthlyR2 COLOURED (128,0,0) style(line) as "monthlyR2", monthlyS2 COLOURED (128,0,0) style(line) as "monthlyS2", monthlyR3 COLOURED (128,0,0) style(line) as "monthlyR3", monthlyS3 COLOURED (128,0,0) style(line) as "monthlyS3"
    

     

    Et voici le code que j’ai bricolé sur proorder pour le moment (je sais que ce n’est pas clean mais là je fais une pause, je ne parviens pas à trouver la condition qui puisse me dire si le cours à croisé le ppm durant les x dernières barres ou temps…:

    //POINT PIVOT JOURNALIER
    
    defparam cumulateorders=false
    //ONCE NbBarLimit = 50
    plage1 = time>008000 and time<120000
    plage2 = time>=130000 and time<180000
    //
    //IF dayofweek = 1 THEN
    //HighJ = DHigh(2)
    //LowJ = DLow(2)
    //SettlementJ = DClose(2)
    //ENDIF
    //
    //IF dayofweek >=2 and dayofweek < 6 THEN
    //HighJ = DHigh(1)
    //LowJ = DLow(1)
    //SettlementJ = DClose(1)
    //ENDIF
    //
    //PPJ = (HighJ + LowJ + SettlementJ) / 3
    //R3J = HighJ + 2 * (PPJ - LowJ)
    //R2J = PPJ + (HighJ - LowJ)
    //R1J = (2 * PPJ) - LowJ
    //S1J = (2 * PPJ) - HighJ
    //S2J = PPJ - (HighJ - LowJ)
    //S3J = LowJ - 2 * (HighJ - PPJ)
    
    //POINT PIVOT WEEKLY
    
    //If DayOfWeek<DayOfWeek[1] then
    //weeklyHigh = Highest[BarIndex - lastWeekBarIndex](High)[1]
    //weeklyLow = Lowest[BarIndex - lastWeekBarIndex](Low)[1]
    //lastWeekBarIndex = BarIndex
    //weeklyPivot = (weeklyHigh + weeklyLow + Close[1]) / 3
    //weeklyR1 = 2*weeklyPivot - weeklyLow
    //weeklyS1 = 2*weeklyPivot - weeklyHigh
    //weeklyR2 = weeklyPivot + (weeklyHigh - weeklyLow)
    //weeklyS2 = weeklyPivot - (weeklyHigh - weeklyLow)
    //weeklyR3 = weeklyR1 + (weeklyHigh - weeklyLow)
    //weeklyS3 = weeklyS1 - (weeklyHigh - weeklyLow)
    //Endif
    //
    //POINT PIVOT MENSUEL
    
    If Month<>Month[1] then
    monthlyHigh = Highest[BarIndex - lastMonthBarIndex](High)[1]
    monthlyLow = Lowest[BarIndex - lastMonthBarIndex](Low)[1]
    lastMonthBarIndex = BarIndex
    monthlyPivot = (monthlyHigh + monthlyLow + Close[1]) / 3
    //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
    
    IF close crosses under monthlyPivot then
    t=1
    ENDIF
    x=0
    for i=0 to 10 do
    
    If close crosses under monthlyPivot then
    x=1
    ENDIF
    NEXT
    
    
    IF NOT OnMarket AND t=1 AND x=1 AND plage1 OR plage2 THEN
    BUY 1 SHARES AT market
    SET TARGET PROFIT 5
    ENDIF
    
    #115881 quote
    Tanou
    Participant
    Senior

    Pour être le plus clair possible il faudrait une condition comme ci-dessous:

    Si durant x périodes/barres le cours à franchi le point pivot mensuel alors x=1 sinon x=0

    Si vous pouviez m’éclairer car la je patauge…

     

    Merci 😀

    #115882 quote
    JC_Bywan
    Moderator
    Master

    En supposant que “ppm” c’est ce que tu as appelé dans ton code monthlypivot, tu peux assigner une variable à ta condition, par exemple c1 pour un croisement à la hausse (puis refaire avec c2 si on veut voir pour le croisement à la baisse):

    c1 = close crosses over monthlypivot

    Puis grâce au mot clé summation, vérifier si c1 a eu lieu au moins une fois dans N périodes pour définir ton x à 1 ou 0, celle en cours incluse (donc jusqu’à N-1 en arrière), sans la moindre boucle for next qu’il vaut mieux éviter quand c’est possible pour consommer moins de puissance de calcul:

    if summation[N](c1)>=1 then
       x=1
    else
       x=0
    endif

    Aide pour l’usage de summation dans ce lien: https://www.prorealcode.com/documentation/summation/

    #115883 quote
    Tanou
    Participant
    Senior

    Merci énormément Noobywan! 😀

    #115884 quote
    Tanou
    Participant
    Senior

    @Noobywan,

     

    Je vins de l’implémeter dans mon code. Cependant, il n’agit pas comme il le faudrait. Si je l’applique il prend également en compte le moment n ou le cours cross le ppm. Empêchant toute prise de position…

     

    Aurais-tu une idée?

    //POINT PIVOT MENSUEL
    defparam cumulateorders=false
    If Month<>Month[1] then
    monthlyHigh = Highest[BarIndex - lastMonthBarIndex](High)[1]
    monthlyLow = Lowest[BarIndex - lastMonthBarIndex](Low)[1]
    lastMonthBarIndex = BarIndex
    monthlyPivot = (monthlyHigh + monthlyLow + Close[1]) / 3
    Endif
    
    c1 = close crosses under monthlypivot or close crosses over monthlypivot
    
    if summation[10](c1)>=1 then
    x=1
    else
    x=0
    endif
    
    IF close crosses under monthlyPivot AND x=0 then
    buy 1 SHARES AT market
    SET TARGET pPROFIT 10
    SET STOP pLOSS 20
    ENDIF
    #115886 quote
    Tanou
    Participant
    Senior

    Il faudrait que “summation” commence à partir de la bougie précédente car, pour le moment, x sera forcément à 1 puisque summation prend en compte le cross acutel.. sais tu comment l’implémenter?

     

    Merci!!

    #115895 quote
    JC_Bywan
    Moderator
    Master

    Tu pourrais stocker la somme sur N de l’événement dans une autre variable, par exemple sommec1, et poser la condition sur l’occurence précédente de cette variable, ça devrait vérifier une plage entre la bougie précédente et la Nème bougie précédente sans la bougie en cours, par exemple:

    c1 = close crosses over monthlypivot
    
    sommec1 = summation[N](c1)
    
    if sommec1[1]>=1 then
       x=1
    else
       x=0
    endif
    
Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.

Croisement période antérieur points pivots


ProOrder : Trading Automatique & Backtests

New Reply
Author
author-avatar
Tanou @tanou Participant
Summary

This topic contains 6 replies,
has 2 voices, and was last updated by JC_Bywan
6 years, 2 months ago.

Topic Details
Forum: ProOrder : Trading Automatique & Backtests
Language: French
Started: 01/04/2020
Status: Active
Attachments: No files
Logo Logo
Loading...