Erreur de division par 0 (pas en back test)

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #221245 quote
    NathanC
    Participant
    New

    Bonjour quand je lance ce code, il retourne tjs une erreur de division par 0 (pas en backtest) , d’où peut-elle venir ?

    //Source
    //multitf//https://www.prorealcode.com/topic/indicateurs-mtf-pour-prorealtime-disponible/
    //capitalmanuel//https://www.prorealcode.com/topic/utiliser-le-capital-initial-dans-son-probacktest/
    //https://www.prorealtime.com/fr/pdf/probuilder.pdf
    //https://www.prorealtime.com/fr/pdf/probacktest.pdf
    
    // Définition des paramètres du code
    DEFPARAM CumulateOrders = False // Cumul des positions désactivé
    
    ichi1 = 9
    ichi2 = 26
    ichi3 = 52
    
    
    //Tednance sur le autres timeframe
    // listing variable
    //UT+2
    timeframe(15 minutes)
    KIJUN15 = KijunSen[ichi1,ichi2,ichi3]
    TENKAN15 = TenkanSen[ichi1,ichi2,ichi3]
    SSA15 = SenkouSpanA[ichi1,ichi2,ichi3]
    SSB15 = SenkouSpanB[ichi1,ichi2,ichi3]
    
    
    //UT+1
    timeframe(5 minutes)
    KIJUN5 = KijunSen[ichi1,ichi2,ichi3]
    TENKAN5 = TenkanSen[ichi1,ichi2,ichi3]
    SSA5 = SenkouSpanA[ichi1,ichi2,ichi3]
    SSB5 = SenkouSpanB[ichi1,ichi2,ichi3]
    
    
    //UT
    timeframe(1 minute)
    KIJUN = KijunSen[ichi1,ichi2,ichi3]
    TENKAN = TenkanSen[ichi1,ichi2,ichi3]
    SSA = SenkouSpanA[ichi1,ichi2,ichi3]
    SSB = SenkouSpanB[ichi1,ichi2,ichi3]
    
    
    //Indiquateur
    //Cassure kijun
    Prev1UnderKijunO = (open<KIJUN)
    Prev1UpperKijunO = (open>KIJUN)
    Prev1UnderKijunC = (close<KIJUN)
    Prev1UpperKijunC = (close>KIJUN)
    //Tenkan
    Prev1UpperTenkanO = (open>TENKAN)
    Prev1UnderTenkanO = (open<TENKAN)
    Prev1UpperTenkanC = (close>TENKAN)
    Prev1UnderTenkanC = (close<TENKAN)
    //Nuage kumo
    Prev1UpperSSA = (close>SSA)
    Prev1UpperSSB = (close>SSB)
    Prev1UnderSSA = (close<SSA)
    Prev1UnderSSB = (close<SSB)
    //Tendance
    //Baisse
    HausseUT = open > SSA  and  SSA > SSB
    BaisseUT = open < SSA and  SSA < SSB
    HausseUT1 = open > SSA5  and  SSA5 > SSB5
    BaisseUT1 = open < SSA5 and  SSA5 < SSB5
    HausseUT2 = open > SSA15  and  SSA15 > SSB15
    BaisseUT2 = open < SSA15  and  SSA15 < SSB15
    
    
    //Money management
    ONCE Capital = 3500
    ONCE Risk = 0.005
    equity = Capital + StrategyProfit
    maxrisk = round(equity*Risk)
    SLLong= abs( close - LOWEST[10](low))
    SLShort = abs( close - Highest[10](high))
    PositionSizeL = abs(round((maxrisk/SLLong)/PointValue)*pipsize)
    PositionSizeS = abs(round((maxrisk/SLShort)/PointValue)*pipsize)
    
     
    //ORDER Achat:
    //Kijun
    //close 2 avant sskijun// close prev au dessus// close pre au dessus tenkan// prev au dessus du nage SSA-SSB// convergence UT UT1 UT2
    IF Prev1UnderKijunO AND Prev1UpperKijunC AND Prev1UpperTenkanC AND Prev1UpperSSA AND Prev1UpperSSB and HausseUT and HausseUT1 and HausseUT2  THEN
    SELLSHORT PositionSizeS SHARES AT MARKET
    SET STOP LOSS SLShort
    type = 1
    ENDIF
    //fermeture ss kijun
    IF Prev1UnderKijunC AND type = 1 THEN
    EXITSHORT AT MARKET
    type = 0
    ENDIF
    //tenkan(descri)
    //close 2 avant sstenkan// close prev au dessus tenkan// close pre au dessus kijun// prev au dessus du nage SSA-SSB// convergence UT UT1 UT2
    IF Prev1UnderTenkanO  AND Prev1UpperTenkanC AND Prev1UpperKijunC AND Prev1UpperSSA AND Prev1UpperSSB AND HausseUT and HausseUT1 and HausseUT2 and type<>1 THEN
    SELLSHORT PositionSizeS SHARES AT MARKET
    SET STOP LOSS SLShort
    type = 2
    ENDIF
    //fermeture ss kijun
    IF Prev1UnderTenkanC AND type = 2 THEN
    EXITSHORT AT MARKET
    type =0
    ENDIF
    
    
    //Order Sell
    //close 2 avant au dessuskijun// close prev en dessous// close pre au dessous tenkan// prev au dessous du nage SSA-SSB// convergence UT UT1 UT2
    IF Prev1UpperKijunO AND Prev1UnderKijunC AND Prev1UnderTenkanC AND Prev1UnderSSA AND Prev1UnderSSB AND BaisseUT and BaisseUT2 AND BaisseUT1 THEN
    BUY PositionSizeL SHARES AT MARKET
    SET STOP LOSS SLLong
    type = 3
    ENDIF
    //fermeture haut kijun
    IF Prev1UpperKijunC AND type = 3 THEN
    SELL AT MARKET
    type = 0
    ENDIF
    //tenkan(descri)
    //close 2 avant au dessustenkan// close prev en dessous tenkan// close pre en dessous kijun// prev en dessous du nuage SSA-SSB// convergence UT UT1 UT2
    IF Prev1UpperTenkanO  AND Prev1UnderTenkanC AND Prev1UnderKijunC AND Prev1UnderSSA AND Prev1UnderSSB AND BaisseUT and BaisseUT2 AND BaisseUT1 AND type<>3 THEN
    BUY PositionSizeL SHARES AT MARKET
    SET STOP LOSS SLLong
    type = 4
    ENDIF
    //fermeture haut tenkan
    IF Prev1UpperTenkanC AND type = 4 THEN
    SELL AT MARKET
    type = 0
    ENDIF
    

    Merci !

    #221247 quote
    Nicolas
    Keymaster
    Master

    Sauf erreur de ma part, les seules divisions que je vois dans ton code se situent aux lignes 74 et 75:

    PositionSizeL = abs(round((maxrisk/SLLong)/PointValue)*pipsize)
    PositionSizeS = abs(round((maxrisk/SLShort)/PointValue)*pipsize)
    Il faudrait donc s’assurer que SLLong et SLShort soit bien supérieur à 0 avant de faire ces calculs et aussi pour lancer des ordres.
    #221248 quote
    NathanC
    Participant
    New

    Merci pour la réponse, j’ai eu le même raisonnement, c’est pour ca que dans le calcul SLlong et SL short j’ai mi abs :

    SLLong= abs( close LOWEST[10](low))
    SLShort = abs( close Highest[10](high))

    cela ne certifie pas une valeurs positive ?

    #221252 quote
    JC_Bywan
    Moderator
    Master

    Abs te garantit un signe plus si la valeur est non nulle, mais si elle vaut zéro avant de passer par un abs, elle vaudra zéro aussi après.

    #221265 quote
    NathanC
    Participant
    New

    Oui j’ai compris ou était l’erreur merci 🙂
    Je calculerais mes tailles de positions juste avant de la prendre  après les if.
    Ca évitera de la calculer tout le temps et de faire des erreurs.

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

Erreur de division par 0 (pas en back test)


ProBuilder : Indicateurs & Outils Personnalisés

New Reply
Author
author-avatar
NathanC @nathanc Participant
Summary

This topic contains 4 replies,
has 3 voices, and was last updated by NathanC
2 years, 5 months ago.

Topic Details
Forum: ProBuilder : Indicateurs & Outils Personnalisés
Language: French
Started: 09/18/2023
Status: Active
Attachments: No files
Logo Logo
Loading...