division by zero error but im not dividing anything
Forums › ProRealTime English forum › ProOrder support › division by zero error but im not dividing anything
- This topic has 5 replies, 5 voices, and was last updated 2 years ago by Mishap.
-
-
03/01/2022 at 3:41 AM #189098
Hi guys as the title suggests i keep getting the division by zero error but im not dividing anything. can anyone see an issue with the attached? i scratching my head. the code at the bottom is a custom indicator is this causing the issue?
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889// Definition of code parametersDEFPARAM CumulateOrders = true // Cumulating positions deactivated// The system will cancel all pending orders and close all positions at 0:00. No new ones will be allowed until after the "FLATBEFORE" time.DEFPARAM FLATBEFORE = 100000// Cancel all pending orders and close all positions at the "FLATAFTER" timeDEFPARAM FLATAFTER = 060000// Prevents the system from placing new orders on specified days of the weekdaysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0if not onmarket thenc1 =1c5 = 1endif// Conditions to enter long positionsindicator1 = CALL "trend/no trend"c1 = indicator1indicator2 = RSI[1](close)c2 = (indicator2 < 30)indicator3 = MACDline[12,26,9](close)indicator4 = ExponentialAverage[9](MACDline[12,26,9](close))c3 = (indicator3 CROSSES OVER indicator4)IF (c1=0 AND c2 AND c3) and not daysForbiddenEntry THENBUY 1 CONTRACT AT MARKETENDIF// Conditions to exit long positionsindicator5 = MACDline[12,26,9](close)indicator6 = ExponentialAverage[9](MACDline[12,26,9](close))c4 = (indicator5 CROSSES UNDER indicator6)indicator13 = CALL "trend/no trend"c9 = (indicator13 = 1)IF c4 and c9 THENSELL AT MARKETENDIF// Conditions to enter short positionsindicator7 = CALL "trend/no trend"c5 = indicator7indicator8 = RSI[1](close)c6 = (indicator8 >= 60)indicator9 = MACDline[12,26,9](close)indicator10 = ExponentialAverage[9](MACDline[12,26,9](close))c7 = (indicator9 CROSSES UNDER indicator10)IF (c5 AND c6 AND c7) AND not daysForbiddenEntry THENSELLSHORT 1 CONTRACT AT MARKETENDIF// Conditions to exit short positionsindicator11 = MACDline[12,26,9](close)indicator12 = ExponentialAverage[9](MACDline[12,26,9](close))c8 = (indicator11 CROSSES OVER indicator12)indicator14 = CALL "trend/no trend"c10 = (indicator14 = 1)IF c8 and c10 THENEXITSHORT AT MARKETENDIF// Stops and targetsSET TARGET PPROFIT 15SET STOP pLOSS 10//-------------------------------------------------------------------------// Function : trend/no trend//-------------------------------------------------------------------------// period da ottimizzareAA = 50t=(LinearRegressionSlope[AA](close)-0)*SQRT(AA-2)/(STE[AA](close)/STD[AA](Barindex))if t>1.96 thenbeta=1endifif t<-1.96 thenbeta=-1endifif t-1.96 thenbeta=0endifreturn beta03/01/2022 at 4:46 AM #18909903/01/2022 at 5:07 AM #189100The issue could be due to the indicator “trend/no trend”.
Check any division in there.
03/01/2022 at 7:11 AM #189101Hi @Mishap
t=(LinearRegressionSlope[AA](close)–0)*SQRT(AA–2)/(STE[AA](close)/STD[AA](Barindex))
When BarIndex = 0 then STD[AA](BarIndex) is zero (devision by zero)
Remarks:
(Close)-0) ???
Standarddeviation of the BarIndex???
CumulateOrders is not deactivated because = true
03/01/2022 at 8:40 AM #189109Weird code, but ok 🙂
The problem is located in your indicator, make sure you have sufficient history in order to calculate the standard deviation of the barindex (!??) 😆
123456789101112131415161718192021//-------------------------------------------------------------------------// Function : trend/no trend//-------------------------------------------------------------------------// period da ottimizzareAA = 50if barindex>AA thent=(LinearRegressionSlope[AA](close)-0)*SQRT(AA-2)/(STE[AA](close)/STD[AA](Barindex))if t>1.96 thenbeta=1endifif t<-1.96 thenbeta=-1endifif t-1.96 thenbeta=0endifendifreturn beta03/01/2022 at 11:44 AM #189134 -
AuthorPosts
Find exclusive trading pro-tools on