Counting Stochastic does not work in strategy
Forums › ProRealTime English forum › ProOrder support › Counting Stochastic does not work in strategy
- This topic has 10 replies, 4 voices, and was last updated 5 years ago by Vonasi.
Tagged: Stochastic
-
-
10/27/2019 at 2:59 PM #111339
I coded an indicator to simply count how many different stochastics are under a certain level.
12345678910level = 20flag = 0for j = 1 to 100if Stochastic[j,1](close) < level thenflag = flag + 1endifnextreturn flagIt works fine and returns varying values between zero and 100.
I then put the same code in a strategy and it only returns zero or 100 and nothing else.
123456789101112level = 20flag = 0for j = 1 to 100if Stochastic[j,1](close) < level thenflag = flag + 1endifnextbuy at -close limitgraph flagIf I CALL the indicator from the strategy I get 0 or 100 and nothing else too.
It feels like a weird bug but I might just be missing something really obvious as to why it works as an indicator but not in a strategy.
If I do the same test with RSI instead of Stochastic then it works fine.
10/27/2019 at 3:17 PM #111341Why do you have trades opened?
Try GRAPHing j, or replacing FOR…NEXT with WHILE…WEND.
10/27/2019 at 3:43 PM #111344Trades are opened because the image is with the code actually in a working strategy. I was trying to use the flag value for dynamic position sizing. When the position sizes did not change I went looking for the problem and coded the loop as a separate dummy code – it still didn’t work. 🙁
I already did try changing the FOR NEXT loop with WHILE WEND and that did not work either.
If I graph J it will just be 100 because the loop has ended!
10/27/2019 at 6:28 PM #11135010/27/2019 at 6:47 PM #111351fifi743 Thanks for your input but the only difference I can see in your code is the use of DO in line 4 and as far as I am aware DO is an optional instruction so I don’t think that it will make any difference – but I’ll try it anyway!
In fact I have just coded my own stochastic to try to eliminate the platforms stochastic as being the fault but even with my own calculations I get the same results. It works in a loop in an indicator but not in a loop in a strategy.
123456789101112flag = 0for j = 1 to 100d = 1ll = lowest[j](low)hh = highest[j](high)Stoch = average[d](((close - ll)/(hh - ll))*100)if Stoch < level thenflag = flag + 1endifnextreturn flag10/27/2019 at 7:48 PM #111356OK – I’m starting to get somewhere. It has something to do with the averaging in the stochastic calculation. With the following code I get the correct results but this does mean that I can only test STOCHASTIC[j,1].
1234567891011121314level = 20flag = 0for j = 1 to 100ll = lowest[j](low)hh = highest[j](high)stoch = (((close - ll)/(hh - ll))*100)if stoch < level thenflag = flag + 1endifnextbuy at -close limitgraph flag10/27/2019 at 7:57 PM #11135710/27/2019 at 8:49 PM #111359Yes – but if I use STOCHASTIC or use AVERAGE in my own calculation of the stochastic value then I get zero or the maximum value of j and no values in between.
If you see the image in the first post the indicator at the bottom is the exact same code counting stochastics that are below level and it works in an indicator but not in a strategy. There is something wrong in the ProOrder engine that is not wrong in the ProBuilder engine I think.
10/27/2019 at 9:33 PM #111360I coded this dummy strategy that in my mind should be able to calculate a stochastic[j,3] using a second loop to work out the average but even this returns different results to the indicator with settings of [j,3].
Top graphed line is the strategy and bottom is the indicator.
I’ll give up for tonight and wait for Nicolas to clock on to work tomorrow morning and see what he makes of it all!
1234567891011121314151617181920212223level = 20flag = 0for j = 1 to 100ll = lowest[j](low)hh = highest[j](high)stoch = (((close - ll)/(hh - ll))*100)total = 0d = 3for a = 0 to d-1total = total + stoch[a]nextmystoch = total/dif mystoch < level thenflag = flag + 1endifnextbuy at -close limitgraph flag1 user thanked author for this post.
10/28/2019 at 9:45 AM #111389Yes, it reminds me of the problem I encountered in this topic: Possible to code this 3D heatmap in PRT? (Mark Whistler’s Wave PM)
The conclusion was that the average takes the last calculated data and not the one of the period calculated dynamically in a loop..
10/28/2019 at 10:43 AM #111398Yes that all looks very familiar! I wish I’d remembered that topic yesterday as it could have saved a lot of time.
It seems that it has not yet been fixed.
It still seems strange that the last code I posted does not work as I tried to eliminate all built in indicators. When in a loop it must be picking up an incorrect value for something but loops are impossible for us to debug with graph so finding out which value is not possible.
-
AuthorPosts
Find exclusive trading pro-tools on