ProBackTest : les ordres ne passent pas

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #121562 quote
    smart.fr
    Participant
    New

    Bonjour,
    Lorsque je backtest ce système il ne se passe strictement rien : aucun ordre n’est simulé.
    Le système est hyper simple : un stop suiveur à l’achat, un autre stop suiveur à la vente. Les seules positions autorisées sont seulement les positions longues.
    Il doit y avoir une erreur évidente dans mon code, mais je ne la vois pas.
    Help! 😉

    //////////////////////////////////////////////////////////////////////////////////////////
    //   VARIABLES
    //////////////////////////////////////////////////////////////////////////////////////////
    //PriceBaseStage [1000],
    //DropConfirmationLevel [700;900][50]
    //BuyLevel [100;300][50]
    //RaiseConfirmationLevel[700;900][50]
    //SellLevel [100;300][50]
    
    //////////////////////////////////////////////////////////////////////////////////////////
    //   POSITIONS
    //////////////////////////////////////////////////////////////////////////////////////////
    ONCE CapitalInitial = 10000
    
    // Conditions pour ouvrir une position acheteuse
    IF NOT LongOnMarket AND ConditionAchat THEN
    Quantite = Round(0.9 * (CapitalInitial + StrategyProfit) / Close)
    BUY Quantite CONTRACTS AT MARKET
    ENDIF
    
    // Conditions pour fermer une position acheteuse
    If LongOnMarket AND ConditionVente THEN
    SELL AT MARKET
    ENDIF
    
    //////////////////////////////////////////////////////////////////////////////////////////
    // CALCUL DES STOP LOSS
    //////////////////////////////////////////////////////////////////////////////////////////
    
    // Initialisation
    ONCE StopLossBuy = -1
    ONCE StopLossSell = -1
    ONCE DropConfirmationPrice = PriceBaseStage * (ROUND(Close / PriceBaseStage) - 1) + DropConfirmationLevel
    ONCE RaiseConfirmationPrice = PriceBaseStage * ROUND(Close / PriceBaseStage) + RaiseConfirmationLevel
    
    // Suivre la baisse
    IF (Low <= DropConfirmationPrice[1]) THEN
    // La baisse est confirmée, on diminue le stop loss d'achat et la prochaine confirmation de baisse
    StopLossBuy = PriceBaseStage * ROUND(DropConfirmationPrice[1] / PriceBaseStage) + BuyLevel
    DropConfirmationPrice = DropConfirmationPrice[1] - PriceBaseStage
    ELSE
    StopLossBuy = StopLossBuy[1]
    DropConfirmationPrice = DropConfirmationPrice[1]
    ENDIF
    
    // Suivre la hausse
    IF (High >= RaiseConfirmationPrice[1]) THEN
    // La hausse est confirmée, on augmente le stop loss de vente et la prochaine confirmation de hausse
    StopLossSell = PriceBaseStage * (ROUND(RaiseConfirmationPrice[1] / PriceBaseStage) - 1) + SellLevel
    RaiseConfirmationPrice = RaiseConfirmationPrice[1] + PriceBaseStage
    ELSE
    StopLossSell = StopLossSell[1]
    RaiseConfirmationPrice = RaiseConfirmationPrice[1]
    ENDIF
    
    //////////////////////////////////////////////////////////////////////////////////////////
    // CALCUL DES SIGNAUX
    //////////////////////////////////////////////////////////////////////////////////////////
    
    // Condition pour ouvrir une position longue
    ConditionAchat = (High >= StopLossBuy[1])
    
    // Condition pour clôturer une position longue ouverte
    ConditionVente = (Low <= StopLossSell[1])
    
    #121569 quote
    Nicolas
    Keymaster
    New

    Je n’ai pas testé, mais est-ce que “ConditionAchat” est bien vérifié au moins une fois ?

    #121578 quote
    fifi743
    Participant
    Master
    //////////////////////////////////////////////////////////////////////////////////////////
    //   VARIABLES
    //////////////////////////////////////////////////////////////////////////////////////////
    //PriceBaseStage [1000],
    //DropConfirmationLevel [700;900][50]
    //BuyLevel [100;300][50]
    //RaiseConfirmationLevel[700;900][50]
    //SellLevel [100;300][50]
    
    //////////////////////////////////////////////////////////////////////////////////////////
    //   POSITIONS
    //////////////////////////////////////////////////////////////////////////////////////////
    ONCE CapitalInitial = 10000
    
    // Conditions pour ouvrir une position acheteuse
    IF NOT LongOnMarket AND ConditionAchat THEN
    Quantite = Round(0.9 * (CapitalInitial + StrategyProfit) / Close)
    BUY Quantite CONTRACTS AT MARKET
    ENDIF
    
    // Conditions pour fermer une position acheteuse
    If LongOnMarket AND ConditionVente THEN
    SELL AT MARKET
    ENDIF
    
    //////////////////////////////////////////////////////////////////////////////////////////
    // CALCUL DES STOP LOSS
    //////////////////////////////////////////////////////////////////////////////////////////
    
    // Initialisation
    ONCE StopLossBuy = -1
    ONCE StopLossSell = -1
     DropConfirmationPrice = PriceBaseStage * (ROUND(Close / PriceBaseStage) - 1) + DropConfirmationLevel
     RaiseConfirmationPrice = PriceBaseStage * ROUND(Close / PriceBaseStage) + RaiseConfirmationLevel
    
    // Suivre la baisse
    IF (Low <= DropConfirmationPrice[1]) THEN
    // La baisse est confirmée, on diminue le stop loss d'achat et la prochaine confirmation de baisse
    StopLossBuy = PriceBaseStage * ROUND(DropConfirmationPrice[1] / PriceBaseStage) + BuyLevel
    DropConfirmationPrice = DropConfirmationPrice[1] - PriceBaseStage
    ELSE
    StopLossBuy = StopLossBuy[1]
    DropConfirmationPrice = DropConfirmationPrice[1]
    ENDIF
    
    // Suivre la hausse
    IF (High >= RaiseConfirmationPrice[1]) THEN
    // La hausse est confirmée, on augmente le stop loss de vente et la prochaine confirmation de hausse
    StopLossSell = PriceBaseStage * (ROUND(RaiseConfirmationPrice[1] / PriceBaseStage) - 1) + SellLevel
    RaiseConfirmationPrice = RaiseConfirmationPrice[1] + PriceBaseStage
    ELSE
    StopLossSell = StopLossSell[1]
    RaiseConfirmationPrice = RaiseConfirmationPrice[1]
    ENDIF
    
    //////////////////////////////////////////////////////////////////////////////////////////
    // CALCUL DES SIGNAUX
    //////////////////////////////////////////////////////////////////////////////////////////
    // Condition pour ouvrir une position longue
    ConditionAchat = (High >= StopLossBuy[1])
    
    // Condition pour clôturer une position longue ouverte
    ConditionVente = (Low <= StopLossSell[1])
    //GRAPH StopLossBuy
    //graph Quantite
    graph DropConfirmationPrice
    graph PriceBaseStage * (ROUND(Close / PriceBaseStage) - 1) + DropConfirmationLevel

    bonjour,

    je ne comprend pas pourquoi quand je

    graph DropConfirmationPrice

    rien ne s’affiche

    et quand je

    graph  PriceBaseStage * (ROUND(Close / PriceBaseStage) – 1) + DropConfirmationLevel

    j’obtiens une valeur

    #121587 quote
    fifi743
    Participant
    Master

    j’ai crée un indicateur pour chercher ou été l’erreur.

    voici le code

    PriceBaseStage = 1000
    DropConfirmationLevel = 50
    
    DropConfirmationPrice =  PriceBaseStage *(ROUND(Close / PriceBaseStage) - 1) + DropConfirmationLevel
    return DropConfirmationPrice

     

    l’indicateur retourne bien les valeurs mais  dans proorder

    DropConfirmationPrice =  (ROUND(Close / PriceBaseStage) - 1) + DropConfirmationLevel

    DropConfirmationPrice  ne retourne rien dans proorder

    #121594 quote
    smart.fr
    Participant
    New

    Merci pour vos réponses.

    Nicolas, manifestement “ConditionAchat” n’est jamais vérifié.
    Fifi743, effectivement il semble que l’affectation de mes variables StopLossBuy, RaiseConfirmationPrice, StopLossSell et DropConfirmationPrice ne fonctionne pas puisqu’elles valent toujours 0. Pourtant lorsqu’on graphe les formules permettant de les calculer, on a bien des valeurs.

    J’ai déplacé toutes mes commandes “ONCE” au début du code, sans amélioration. Aurais-je oublié une instruction d’initialisation ?

    #121602 quote
    smart.fr
    Participant
    New

    Voici une version peut-être plus lisible ?
    Je ne comprends vraiment pas ce qui ne va pas.
    Tout se passe comme si “Close” valait 0 dans toutes les instructions “ONCE” d’initialisation puis tout le reste du code était inactif.

    // Initialisation
    ONCE StopLossBuy = PriceBaseStage * ROUND(Close / PriceBaseStage) + BuyLevel
    ONCE RaiseConfirmationPrice = PriceBaseStage * ROUND(Close / PriceBaseStage) + RaiseConfirmationLevel
    ONCE StopLossSell = PriceBaseStage * (ROUND(Close / PriceBaseStage) - 1) + SellLevel
    ONCE DropConfirmationPrice = PriceBaseStage * (ROUND(Close / PriceBaseStage) - 1) + DropConfirmationLevel
    ONCE CapitalInitial = 10000
    
    //////////////////////////////////////////////////////////////////////////////////////////
    //   VARIABLES
    //////////////////////////////////////////////////////////////////////////////////////////
    //PriceBaseStage [1000],
    //DropConfirmationLevel [700;900][50]
    //BuyLevel [100;300][50]
    //RaiseConfirmationLevel[700;900][50]
    //SellLevel [100;300][50]
    
    GRAPH StopLossBuy
    GRAPH RaiseConfirmationPrice
    GRAPH StopLossSell
    GRAPH DropConfirmationPrice
    
    //////////////////////////////////////////////////////////////////////////////////////////
    // CALCUL DES STOP LOSS
    //////////////////////////////////////////////////////////////////////////////////////////
    
    // Suivre la baisse
    StopLossBuy = StopLossBuy[1]
    DropConfirmationPrice = DropConfirmationPrice[1]
    IF (Low <= DropConfirmationPrice) THEN
    // La baisse est confirmée, on diminue le stop loss d'achat et la prochaine confirmation de baisse
    StopLossBuy = StopLossBuy - PriceBaseStage
    DropConfirmationPrice = DropConfirmationPrice - PriceBaseStage
    ENDIF
    
    // Suivre la hausse
    StopLossSell = StopLossSell[1]
    RaiseConfirmationPrice = RaiseConfirmationPrice[1]
    IF (High >= RaiseConfirmationPrice) THEN
    // La hausse est confirmée, on augmente le stop loss de vente et la prochaine confirmation de hausse
    StopLossSell = StopLossSell + PriceBaseStage
    RaiseConfirmationPrice = RaiseConfirmationPrice + PriceBaseStage
    ENDIF
    
    //////////////////////////////////////////////////////////////////////////////////////////
    // CALCUL DES SIGNAUX
    //////////////////////////////////////////////////////////////////////////////////////////
    
    // Condition pour ouvrir une position longue
    ConditionAchat = (High >= StopLossBuy)
    
    // Condition pour clôturer une position longue ouverte
    ConditionVente = (Low <= StopLossSell)
    
    //////////////////////////////////////////////////////////////////////////////////////////
    //   POSITIONS
    //////////////////////////////////////////////////////////////////////////////////////////
    
    // Conditions pour ouvrir une position acheteuse
    IF NOT LongOnMarket AND ConditionAchat THEN
    Quantite = Round(0.9 * (CapitalInitial + StrategyProfit) / Close)
    BUY Quantite CONTRACTS AT MARKET
    ENDIF
    
    // Conditions pour fermer une position acheteuse
    If LongOnMarket AND ConditionVente THEN
    SELL AT MARKET
    ENDIF
    
    #121606 quote
    fifi743
    Participant
    Master

    pour résoudre le problème il faut faire appele a l’indicateur

    #121607 quote
    fifi743
    Participant
    Master

    pourquoi l’indicateur fonctionne et pas le code dans proorder ?

    #121610 quote
    fifi743
    Participant
    Master

    j’ai fais l’indicateur et algo

    dans l’ago tu peux faire varier les valeurs.

    sur le graph l’algo retourne bien les valeurs

    il y a bien une erreur ,mais ou

    smart.fr thanked this post
    #121613 quote
    fifi743
    Participant
    Master

    la condition fonctionne

    tous ce qui est en remarque c’est qu’il y a un probleme

    ONCE CapitalInitial = 10000
    
    PriceBaseStage,DropConfirmationPrice,RaiseConfirmationPrice,StopLossBuy,StopLossSell= call"SMART IND"[1000,50,50,50,50]
    Quantite = Round(0.9 * (CapitalInitial + StrategyProfit) / Close)
    if Quantite<1 then
    Quantite=1
    endif
    
    //////////////////////////////////////////////////////////////////////////////////////////
    // CALCUL DES STOP LOSS
    //////////////////////////////////////////////////////////////////////////////////////////
    if PriceBaseStage then
    endif
    //Suivre la baisse
    //StopLossBuy = StopLossBuy[1]
    //DropConfirmationPrice = DropConfirmationPrice[1]
    //IF (Low <= DropConfirmationPrice) THEN
    //// La baisse est confirmée, on diminue le stop loss d'achat et la prochaine confirmation de baisse
    //StopLossBuy = StopLossBuy - PriceBaseStage
    //DropConfirmationPrice = DropConfirmationPrice - PriceBaseStage
    //ENDIF
    //
    //// Suivre la hausse
    //StopLossSell = StopLossSell[1]
    //RaiseConfirmationPrice = RaiseConfirmationPrice[1]
    //IF (High >= RaiseConfirmationPrice) THEN
    //// La hausse est confirmée, on augmente le stop loss de vente et la prochaine confirmation de hausse
    //StopLossSell = StopLossSell + PriceBaseStage
    //RaiseConfirmationPrice = RaiseConfirmationPrice + PriceBaseStage
    //ENDIF
    
    //////////////////////////////////////////////////////////////////////////////////////////
    // CALCUL DES SIGNAUX
    //////////////////////////////////////////////////////////////////////////////////////////
    
    // Condition pour ouvrir une position longue
    ConditionAchat = High >= StopLossBuy
    //(High >= StopLossBuy)
    // Condition pour clôturer une position longue ouverte
    ConditionVente = Low <= StopLossSell
    
    //////////////////////////////////////////////////////////////////////////////////////////
    //   POSITIONS
    //////////////////////////////////////////////////////////////////////////////////////////
    
    // Conditions pour ouvrir une position acheteuse
    IF NOT LongOnMarket AND ConditionAchat THEN
    
    BUY Quantite CONTRACTS AT MARKET
    ENDIF
    
    // Conditions pour fermer une position acheteuse
    If LongOnMarket AND ConditionVente THEN
    SELL AT MARKET
    ENDIF
    graph ConditionAchat
    GRAPH StopLossBuy
    GRAPH RaiseConfirmationPrice
    GRAPH StopLossSell
    GRAPH DropConfirmationPrice
    
    smart.fr thanked this post
    #121637 quote
    Nicolas
    Keymaster
    New

    Un autre sujet a été ouvert dans le forum anglophone: https://www.prorealcode.com/topic/initialization-not-working/

    Je continuerai donc à répondre là bas, merci d’éviter les doubles posts. Les pistes de débuggage “classiques” avec ProOrder : éviter les calculs non nécessaires avant le début d’un backtest (avec un preloadbar nul) et vérifier les erreurs de division par zéro.

    #121709 quote
    smart.fr
    Participant
    New

    Merci encore Fifi743 pour tous tes efforts.
    Ta réponse m’aide concrètement en ce qu’elle me rappelle d’utiliser un indicateur plutôt que de faire les calculs dans le système.
    Malheureusement cela n’est pas suffisant. J’ai l’impression que le problème est dû au fait que les calculs ne sont pas identiques à l’initialisation des seuils et niveaux de stops et ensuite.
    Cf l’indicateur et le système, ci-dessous. Les valeurs retournées par l’indicateur sont toujours incorrectes, valant 250 ou -1250 selon les cas, sur toute la période temporelle.

    PS Nicolas : PriceBaseStage ne vaut pas 0 au début, c’est une variable du système en l’occurrence fixée à 1000. DEFPARAM PreLoadBars = 0 n’améliore malheureusement pas la situation.

    #121710 quote
    smart.fr
    Participant
    New
    //////////////////////////////////////////////////////////////////////////////////////////
    // INITIALISATION
    //////////////////////////////////////////////////////////////////////////////////////////
    ONCE StopLossBuy = PriceBaseStage * ROUND(Close / PriceBaseStage) + BuyLevel
    ONCE RaiseConfirmationPrice = PriceBaseStage * ROUND(Close / PriceBaseStage) + RaiseConfirmationLevel
    ONCE StopLossSell = PriceBaseStage * (ROUND(Close / PriceBaseStage) - 1) + SellLevel
    ONCE DropConfirmationPrice = PriceBaseStage * (ROUND(Close / PriceBaseStage) - 1) + DropConfirmationLevel
    
    //////////////////////////////////////////////////////////////////////////////////////////
    // RECALCUL DES STOP LOSS
    //////////////////////////////////////////////////////////////////////////////////////////
    
    // Suivre la baisse
    StopLossBuy = StopLossBuy[1]
    DropConfirmationPrice = DropConfirmationPrice[1]
    IF (Low <= DropConfirmationPrice[1]) THEN
    // La baisse est confirmée, on diminue le stop loss d'achat et la prochaine confirmation de baisse
    StopLossBuy = StopLossBuy[1] - PriceBaseStage
    DropConfirmationPrice = DropConfirmationPrice[1] - PriceBaseStage
    ENDIF
    
    // Suivre la hausse
    StopLossSell = StopLossSell[1]
    RaiseConfirmationPrice = RaiseConfirmationPrice[1]
    IF (High >= RaiseConfirmationPrice[1]) THEN
    // La hausse est confirmée, on augmente le stop loss de vente et la prochaine confirmation de hausse
    StopLossSell = StopLossSell[1] + PriceBaseStage
    RaiseConfirmationPrice = RaiseConfirmationPrice[1] + PriceBaseStage
    ENDIF
    
    
    return DropConfirmationPrice as "DropConfirmationPrice", RaiseConfirmationPrice as "RaiseConfirmationPrice", StopLossBuy as "StopLossBuy", StopLossSell as "StopLossSell"
    #121711 quote
    smart.fr
    Participant
    New
    // Initialisation
    DEFPARAM PreLoadBars = 0
    ONCE CapitalInitial = 10000
    
    //////////////////////////////////////////////////////////////////////////////////////////
    //   VARIABLES
    //////////////////////////////////////////////////////////////////////////////////////////
    //PriceBaseStage [1000],
    //DropConfirmationLevel [-300;-100][50]
    //BuyLevel [100;300][50]
    //RaiseConfirmationLevel[100;300][50]
    //SellLevel [-300;-100][50]
    
    GRAPH StopLossBuy
    GRAPH RaiseConfirmationPrice
    GRAPH StopLossSell
    GRAPH DropConfirmationPrice
    
    //////////////////////////////////////////////////////////////////////////////////////////
    // CALCUL DES STOP LOSS
    //////////////////////////////////////////////////////////////////////////////////////////
    
    DropConfirmationPrice, RaiseConfirmationPrice, StopLossBuy, StopLossSell = call "stfTrailingStops_Indicator"[1000,-250,250,250,-250]
    
    //////////////////////////////////////////////////////////////////////////////////////////
    // CALCUL DES SIGNAUX
    //////////////////////////////////////////////////////////////////////////////////////////
    
    // Condition pour ouvrir une position longue
    ConditionAchat = (High >= StopLossBuy)
    
    // Condition pour clôturer une position longue ouverte
    ConditionVente = (Low <= StopLossSell)
    
    //////////////////////////////////////////////////////////////////////////////////////////
    //   POSITIONS
    //////////////////////////////////////////////////////////////////////////////////////////
    
    // Conditions pour ouvrir une position acheteuse
    IF NOT LongOnMarket AND ConditionAchat THEN
    Quantite = Round(0.9 * (CapitalInitial + StrategyProfit) / Close)
    BUY Quantite CONTRACTS AT MARKET
    ENDIF
    
    // Conditions pour fermer une position acheteuse
    If LongOnMarket AND ConditionVente THEN
    SELL AT MARKET
    ENDIF
    
    #121796 quote
    JC_Bywan
    Moderator
    New

    Attention avec des écritures de type variable = variable[1] sans condition sur le barindex pour voir si on ne crée pas un problème de première barre, car la barre avant la première, la variable[1] est undefined… et donc de bougie en bougie on propage le undefined

    Il semble assez probable qu’il faille encadrer les lignes concernées par un “if barindex>1 then … endif”:

    if barindex>1 then
       StopLossBuy = StopLossBuy[1]
       DropConfirmationPrice = DropConfirmationPrice[1]
       StopLossSell = StopLossSell[1]
       RaiseConfirmationPrice = RaiseConfirmationPrice[1]
    endif

    Après, est-ce qu’il y a d’autres choses à corriger au-delà j’ai pas regardé, mais faut au moins déjà vérifier que ça trace ces 4 valeurs correctement  dans l’indicateur avec ce if barindex>1

    Nicolas, smart.fr and fifi743 thanked this post
Viewing 15 posts - 1 through 15 (of 16 total)
  • You must be logged in to reply to this topic.

ProBackTest : les ordres ne passent pas


Support ProOrder

New Reply
Author
author-avatar
smart.fr @smart-fr Participant
Summary

This topic contains 15 replies,
has 4 voices, and was last updated by smart.fr
5 years, 10 months ago.

Topic Details
Forum: Support ProOrder
Language: French
Started: 03/09/2020
Status: Active
Attachments: 3 files
Logo Logo
Loading...