ProRealCode - Trading & Coding with ProRealTime™
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])
Je n’ai pas testé, mais est-ce que “ConditionAchat” est bien vérifié au moins une fois ?
//////////////////////////////////////////////////////////////////////////////////////////
// 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
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
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 ?
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
pour résoudre le problème il faut faire appele a l’indicateur
pourquoi l’indicateur fonctionne et pas le code dans proorder ?
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
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
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.
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.
//////////////////////////////////////////////////////////////////////////////////////////
// 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"
// 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
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
ProBackTest : les ordres ne passent pas
This topic contains 15 replies,
has 4 voices, and was last updated by smart.fr
5 years, 10 months ago.
| Forum: | Support ProOrder |
| Language: | French |
| Started: | 03/09/2020 |
| Status: | Active |
| Attachments: | 3 files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.