ProBackTest : les ordres ne passent pas
Forums › ProRealTime forum Français › Support ProOrder › ProBackTest : les ordres ne passent pas
- This topic has 15 replies, 4 voices, and was last updated 4 years ago by smart.fr.
-
-
03/09/2020 at 1:51 PM #121562
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! 😉Système simple de stop suiveurs12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364//////////////////////////////////////////////////////////////////////////////////////////// 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 acheteuseIF NOT LongOnMarket AND ConditionAchat THENQuantite = Round(0.9 * (CapitalInitial + StrategyProfit) / Close)BUY Quantite CONTRACTS AT MARKETENDIF// Conditions pour fermer une position acheteuseIf LongOnMarket AND ConditionVente THENSELL AT MARKETENDIF//////////////////////////////////////////////////////////////////////////////////////////// CALCUL DES STOP LOSS//////////////////////////////////////////////////////////////////////////////////////////// InitialisationONCE StopLossBuy = -1ONCE StopLossSell = -1ONCE DropConfirmationPrice = PriceBaseStage * (ROUND(Close / PriceBaseStage) - 1) + DropConfirmationLevelONCE RaiseConfirmationPrice = PriceBaseStage * ROUND(Close / PriceBaseStage) + RaiseConfirmationLevel// Suivre la baisseIF (Low <= DropConfirmationPrice[1]) THEN// La baisse est confirmée, on diminue le stop loss d'achat et la prochaine confirmation de baisseStopLossBuy = PriceBaseStage * ROUND(DropConfirmationPrice[1] / PriceBaseStage) + BuyLevelDropConfirmationPrice = DropConfirmationPrice[1] - PriceBaseStageELSEStopLossBuy = StopLossBuy[1]DropConfirmationPrice = DropConfirmationPrice[1]ENDIF// Suivre la hausseIF (High >= RaiseConfirmationPrice[1]) THEN// La hausse est confirmée, on augmente le stop loss de vente et la prochaine confirmation de hausseStopLossSell = PriceBaseStage * (ROUND(RaiseConfirmationPrice[1] / PriceBaseStage) - 1) + SellLevelRaiseConfirmationPrice = RaiseConfirmationPrice[1] + PriceBaseStageELSEStopLossSell = StopLossSell[1]RaiseConfirmationPrice = RaiseConfirmationPrice[1]ENDIF//////////////////////////////////////////////////////////////////////////////////////////// CALCUL DES SIGNAUX//////////////////////////////////////////////////////////////////////////////////////////// Condition pour ouvrir une position longueConditionAchat = (High >= StopLossBuy[1])// Condition pour clôturer une position longue ouverteConditionVente = (Low <= StopLossSell[1])03/09/2020 at 2:42 PM #12156903/09/2020 at 3:55 PM #12157812345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667//////////////////////////////////////////////////////////////////////////////////////////// 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 acheteuseIF NOT LongOnMarket AND ConditionAchat THENQuantite = Round(0.9 * (CapitalInitial + StrategyProfit) / Close)BUY Quantite CONTRACTS AT MARKETENDIF// Conditions pour fermer une position acheteuseIf LongOnMarket AND ConditionVente THENSELL AT MARKETENDIF//////////////////////////////////////////////////////////////////////////////////////////// CALCUL DES STOP LOSS//////////////////////////////////////////////////////////////////////////////////////////// InitialisationONCE StopLossBuy = -1ONCE StopLossSell = -1DropConfirmationPrice = PriceBaseStage * (ROUND(Close / PriceBaseStage) - 1) + DropConfirmationLevelRaiseConfirmationPrice = PriceBaseStage * ROUND(Close / PriceBaseStage) + RaiseConfirmationLevel// Suivre la baisseIF (Low <= DropConfirmationPrice[1]) THEN// La baisse est confirmée, on diminue le stop loss d'achat et la prochaine confirmation de baisseStopLossBuy = PriceBaseStage * ROUND(DropConfirmationPrice[1] / PriceBaseStage) + BuyLevelDropConfirmationPrice = DropConfirmationPrice[1] - PriceBaseStageELSEStopLossBuy = StopLossBuy[1]DropConfirmationPrice = DropConfirmationPrice[1]ENDIF// Suivre la hausseIF (High >= RaiseConfirmationPrice[1]) THEN// La hausse est confirmée, on augmente le stop loss de vente et la prochaine confirmation de hausseStopLossSell = PriceBaseStage * (ROUND(RaiseConfirmationPrice[1] / PriceBaseStage) - 1) + SellLevelRaiseConfirmationPrice = RaiseConfirmationPrice[1] + PriceBaseStageELSEStopLossSell = StopLossSell[1]RaiseConfirmationPrice = RaiseConfirmationPrice[1]ENDIF//////////////////////////////////////////////////////////////////////////////////////////// CALCUL DES SIGNAUX//////////////////////////////////////////////////////////////////////////////////////////// Condition pour ouvrir une position longueConditionAchat = (High >= StopLossBuy[1])// Condition pour clôturer une position longue ouverteConditionVente = (Low <= StopLossSell[1])//GRAPH StopLossBuy//graph Quantitegraph DropConfirmationPricegraph PriceBaseStage * (ROUND(Close / PriceBaseStage) - 1) + DropConfirmationLevelbonjour,
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
03/09/2020 at 4:34 PM #121587j’ai crée un indicateur pour chercher ou été l’erreur.
voici le code
12345PriceBaseStage = 1000DropConfirmationLevel = 50DropConfirmationPrice = PriceBaseStage *(ROUND(Close / PriceBaseStage) - 1) + DropConfirmationLevelreturn DropConfirmationPricel’indicateur retourne bien les valeurs mais dans proorder
1DropConfirmationPrice = (ROUND(Close / PriceBaseStage) - 1) + DropConfirmationLevelDropConfirmationPrice ne retourne rien dans proorder
03/09/2020 at 5:44 PM #121594Merci 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 ?
03/09/2020 at 6:15 PM #121602Voici 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.12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667// InitialisationONCE StopLossBuy = PriceBaseStage * ROUND(Close / PriceBaseStage) + BuyLevelONCE RaiseConfirmationPrice = PriceBaseStage * ROUND(Close / PriceBaseStage) + RaiseConfirmationLevelONCE StopLossSell = PriceBaseStage * (ROUND(Close / PriceBaseStage) - 1) + SellLevelONCE DropConfirmationPrice = PriceBaseStage * (ROUND(Close / PriceBaseStage) - 1) + DropConfirmationLevelONCE CapitalInitial = 10000//////////////////////////////////////////////////////////////////////////////////////////// VARIABLES////////////////////////////////////////////////////////////////////////////////////////////PriceBaseStage [1000],//DropConfirmationLevel [700;900][50]//BuyLevel [100;300][50]//RaiseConfirmationLevel[700;900][50]//SellLevel [100;300][50]GRAPH StopLossBuyGRAPH RaiseConfirmationPriceGRAPH StopLossSellGRAPH DropConfirmationPrice//////////////////////////////////////////////////////////////////////////////////////////// CALCUL DES STOP LOSS//////////////////////////////////////////////////////////////////////////////////////////// Suivre la baisseStopLossBuy = 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 baisseStopLossBuy = StopLossBuy - PriceBaseStageDropConfirmationPrice = DropConfirmationPrice - PriceBaseStageENDIF// Suivre la hausseStopLossSell = 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 hausseStopLossSell = StopLossSell + PriceBaseStageRaiseConfirmationPrice = RaiseConfirmationPrice + PriceBaseStageENDIF//////////////////////////////////////////////////////////////////////////////////////////// CALCUL DES SIGNAUX//////////////////////////////////////////////////////////////////////////////////////////// Condition pour ouvrir une position longueConditionAchat = (High >= StopLossBuy)// Condition pour clôturer une position longue ouverteConditionVente = (Low <= StopLossSell)//////////////////////////////////////////////////////////////////////////////////////////// POSITIONS//////////////////////////////////////////////////////////////////////////////////////////// Conditions pour ouvrir une position acheteuseIF NOT LongOnMarket AND ConditionAchat THENQuantite = Round(0.9 * (CapitalInitial + StrategyProfit) / Close)BUY Quantite CONTRACTS AT MARKETENDIF// Conditions pour fermer une position acheteuseIf LongOnMarket AND ConditionVente THENSELL AT MARKETENDIF03/09/2020 at 8:23 PM #12160603/09/2020 at 8:24 PM #12160703/09/2020 at 9:22 PM #12161003/09/2020 at 9:36 PM #121613la condition fonctionne
tous ce qui est en remarque c’est qu’il y a un probleme
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960ONCE CapitalInitial = 10000PriceBaseStage,DropConfirmationPrice,RaiseConfirmationPrice,StopLossBuy,StopLossSell= call"SMART IND"[1000,50,50,50,50]Quantite = Round(0.9 * (CapitalInitial + StrategyProfit) / Close)if Quantite<1 thenQuantite=1endif//////////////////////////////////////////////////////////////////////////////////////////// CALCUL DES STOP LOSS//////////////////////////////////////////////////////////////////////////////////////////if PriceBaseStage thenendif//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 longueConditionAchat = High >= StopLossBuy//(High >= StopLossBuy)// Condition pour clôturer une position longue ouverteConditionVente = Low <= StopLossSell//////////////////////////////////////////////////////////////////////////////////////////// POSITIONS//////////////////////////////////////////////////////////////////////////////////////////// Conditions pour ouvrir une position acheteuseIF NOT LongOnMarket AND ConditionAchat THENBUY Quantite CONTRACTS AT MARKETENDIF// Conditions pour fermer une position acheteuseIf LongOnMarket AND ConditionVente THENSELL AT MARKETENDIFgraph ConditionAchatGRAPH StopLossBuyGRAPH RaiseConfirmationPriceGRAPH StopLossSellGRAPH DropConfirmationPrice1 user thanked author for this post.
03/10/2020 at 9:18 AM #121637Un 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.
03/10/2020 at 2:42 PM #121709Merci 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.
03/10/2020 at 2:43 PM #121710stfTrailingStops_Indicator1234567891011121314151617181920212223242526272829303132//////////////////////////////////////////////////////////////////////////////////////////// INITIALISATION//////////////////////////////////////////////////////////////////////////////////////////ONCE StopLossBuy = PriceBaseStage * ROUND(Close / PriceBaseStage) + BuyLevelONCE RaiseConfirmationPrice = PriceBaseStage * ROUND(Close / PriceBaseStage) + RaiseConfirmationLevelONCE StopLossSell = PriceBaseStage * (ROUND(Close / PriceBaseStage) - 1) + SellLevelONCE DropConfirmationPrice = PriceBaseStage * (ROUND(Close / PriceBaseStage) - 1) + DropConfirmationLevel//////////////////////////////////////////////////////////////////////////////////////////// RECALCUL DES STOP LOSS//////////////////////////////////////////////////////////////////////////////////////////// Suivre la baisseStopLossBuy = 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 baisseStopLossBuy = StopLossBuy[1] - PriceBaseStageDropConfirmationPrice = DropConfirmationPrice[1] - PriceBaseStageENDIF// Suivre la hausseStopLossSell = 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 hausseStopLossSell = StopLossSell[1] + PriceBaseStageRaiseConfirmationPrice = RaiseConfirmationPrice[1] + PriceBaseStageENDIFreturn DropConfirmationPrice as "DropConfirmationPrice", RaiseConfirmationPrice as "RaiseConfirmationPrice", StopLossBuy as "StopLossBuy", StopLossSell as "StopLossSell"03/10/2020 at 2:46 PM #121711stfTrailingStops123456789101112131415161718192021222324252627282930313233343536373839404142434445464748// InitialisationDEFPARAM PreLoadBars = 0ONCE CapitalInitial = 10000//////////////////////////////////////////////////////////////////////////////////////////// VARIABLES////////////////////////////////////////////////////////////////////////////////////////////PriceBaseStage [1000],//DropConfirmationLevel [-300;-100][50]//BuyLevel [100;300][50]//RaiseConfirmationLevel[100;300][50]//SellLevel [-300;-100][50]GRAPH StopLossBuyGRAPH RaiseConfirmationPriceGRAPH StopLossSellGRAPH 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 longueConditionAchat = (High >= StopLossBuy)// Condition pour clôturer une position longue ouverteConditionVente = (Low <= StopLossSell)//////////////////////////////////////////////////////////////////////////////////////////// POSITIONS//////////////////////////////////////////////////////////////////////////////////////////// Conditions pour ouvrir une position acheteuseIF NOT LongOnMarket AND ConditionAchat THENQuantite = Round(0.9 * (CapitalInitial + StrategyProfit) / Close)BUY Quantite CONTRACTS AT MARKETENDIF// Conditions pour fermer une position acheteuseIf LongOnMarket AND ConditionVente THENSELL AT MARKETENDIF03/11/2020 at 10:31 AM #121796Attention 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”:
123456if barindex>1 thenStopLossBuy = StopLossBuy[1]DropConfirmationPrice = DropConfirmationPrice[1]StopLossSell = StopLossSell[1]RaiseConfirmationPrice = RaiseConfirmationPrice[1]endifAprè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
-
AuthorPosts
Find exclusive trading pro-tools on