help with division by 0 error
Forums › ProRealTime English forum › ProOrder support › help with division by 0 error
- This topic has 5 replies, 5 voices, and was last updated 3 years ago by
JC_Bywan.
-
-
04/28/2021 at 1:16 PM #1682841234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950DEFPARAM CumulateOrders = TRUE // Cumulating positions deactivatedDEFPARAM preloadbars = 1000//Trigger to enter position (all other criteria must be met)//current time framersi1 = RSI[8](close)rsi2 = RSI[1](close)c1 = (rsi2 CROSSES over rsi1)//c2 = (close >= MA2)Timeframe (2 minutes)//base moving average indicator percentages 3 candle look backInd1 = Average[15] (close[3])Ind2 = Average[20] (close[3])Ind3 = Average[25] (close[3])Ind4 = Average[30] (close[3])//moving average candle indicator percentagesInd5 = Average[15] (close)Ind6 = Average[20] (close)Ind7 = Average[25] (close)Ind8 = Average[30] (close)//get distance from averages in percentage relative to one above or belowDistPer1 = abs(Ind1-Ind2)*100/Ind1DistPer2 = abs(Ind2-Ind3)*100/Ind2DistPer3 = abs(Ind3-Ind4)*100/Ind3DistPer4 = abs(Ind5-Ind6)*100/Ind5DistPer5 = abs(Ind6-Ind7)*100/Ind6DistPer6 = abs(Ind7-Ind8)*100/Ind7c3 = DistPer4-DistPer1c4 = DistPer5-DistPer2c5 = DistPer6-DistPer3IF Ind5 > Ind6 AND Ind6 > Ind7 AND Ind7 > Ind8 THENUpTrend = 1ELSEUpTrend = 0ENDIFPer1 = .001Per2 = .002Per3 = .003// Conditions to enter long positionsIF c1 AND c3 >= Per1 AND c4 >= Per2 AND c5 >= Per3 AND UpTrend THENBUY 1 CONTRACTS AT MARKETENDIF
Hi Guys,
Im hoping someone can point me in the right direction with where my code is causing division by 0 error. i think its in the “DistPer” section of the code. essentially im trying to get 3 different averages from 3 candles back & compare to the current average. if there is an increase in percentage as at the “Per” value. it keeps throwing the div by 0 error which i cant seem to clear.
I have reviewed other threads around div by 0 error but haven’t found a workable solution as yet.
any help is appreciated.
cheers
04/28/2021 at 1:40 PM #168289Post your topic in the correct forum:
_ ProRealTime Platform Support: only platform related issues.
_ ProOrder: only strategy topics.
_ ProBuilder: only indicator topics.
_ ProScreener: only screener topics
_ General Discussion: any other topics.
_ Welcome New Members: for new forum members to introduce themselves.Thank you 🙂
04/28/2021 at 1:57 PM #168290Don’t you need
1DistPerN = abs(Ind4-Ind3)*100/Ind4?
Try using GRAPH to monitor the variables involved in division:
1234567GRAPH Ind1GRAPH Ind2GRAPH Ind3GRAPH Ind4GRAPH Ind5GRAPH Ind6GRAPH Ind7or this version:
1234567GRAPH Ind1 = 0GRAPH Ind2 = 0GRAPH Ind3 = 0GRAPH Ind4 = 0GRAPH Ind5 = 0GRAPH Ind6 = 0GRAPH Ind7 = 004/28/2021 at 7:55 PM #168310Hello Mishap, the division by 0 error is due to
1RSI[1](close)I had exactly the same error when running a strategy live and I searched during a long time before finding the solution.
Try to use at least
1RSI[2](close)as the parameter must be an integer greater than 1
1 user thanked author for this post.
09/12/2022 at 11:07 AM #200609Hello Mishap, the division by 0 error is due to
1RSI[1](close)I had exactly the same error when running a strategy live and I searched during a long time before finding the solution.
Try to use at least
1RSI[2](close)as the parameter must be an integer greater than 1
is it true ? someone else has the same issue with [1] previous value ?
🙂
09/12/2022 at 2:09 PM #200619 -
AuthorPosts