Initialization not working
Forums › ProRealTime English forum › ProOrder support › Initialization not working
- This topic has 4 replies, 2 voices, and was last updated 4 years ago by smart.fr.
-
-
03/09/2020 at 6:22 PM #121603
Hello,
The outcome of the following code is exactly the same as if “Close” was 0 in the “ONCE” instructions, and all the remaining code did not exist.
GRAPHing my variables produces flat lines whereas GRAPHing the formulas used to calculate them produces correct graphs.
It looks like assignations don’t work.
What am I missing here?
(It’s a very simple ProBackTest system based on 2 trailing stops, one to open a long position and another one to close it.)Thanks for your help!
Stephane12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667// 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/10/2020 at 9:15 AM #121636Please do not open multiple topics with the same question.
First idea that come to mind:
- at first run, PriceBaseStage is equal to 0 and a division by zero error has the effect of stopping future evaluations of the variables
- try to limit the preloaded bars with a defparam preloadbars=0 , to exclude calculation before the real start date of the backtest
1 user thanked author for this post.
03/11/2020 at 9:30 AM #121790Thank you Nicolas.
PriceBaseStage is a variable which is set to 1000, so it is never equal to 0.
Unfortunately, DEFPARAM PreLoadBars = 0 doesn’t change anything.I was suggested by Fifi743 to use an indicator instead of doing the calculations in the system. It generally helps.
However here, it doesn’t improve the outcome.
Looks like the ONCE calculations are made out of any bars (hence “Close” seemingly equal to 0).Has anyone experienced this phenomenom? I’m pretty sure there’s an obvious fix or workaround…
Thanks!03/11/2020 at 10:31 AM #12179703/11/2020 at 6:18 PM #121858 -
AuthorPosts
Find exclusive trading pro-tools on