stochastic indicator
Forums › ProRealTime English forum › ProBuilder support › stochastic indicator
- This topic has 7 replies, 3 voices, and was last updated 5 years ago by Vonasi.
-
-
10/26/2019 at 5:08 PM #11128210/26/2019 at 6:12 PM #111285
Trebor – Welcome to the forums.
You may need to give a little more info. What do you mean exactly by pips between >80 and < 20? Do we start counting when the stochastic crosses up or when it crosses down over each of these values? What do we do if it recrosses the 20 – do we start counting again or ignore it?
10/26/2019 at 6:32 PM #111286Hi Vonasi,
Thank you for your answer and thank you for the welcome
I would like to get it start to count when %K enters <20 and stop count when it becomes >80. I would like to get the difference between entering <20 and to entering >80. Also as you write, I would not like it to start to recount if it reenters <20 before it has entered >80. Hope this is enough information.
10/26/2019 at 9:02 PM #111290Try this:
1234567891011121314mystoch = Stochastic[10,3](close)if not on and mystoch crosses under 20 thenmyopen = closeon = 1endifif on and mystoch crosses over 80 thenmyclose = closediff = myclose - myopenon = 0endifreturn diff1 user thanked author for this post.
10/27/2019 at 7:50 AM #11131010/27/2019 at 10:22 AM #11131710/27/2019 at 11:23 AM #111322Just for fun I turned it into something that draws lines on the chart from the open to the close of the simulated trade. The total gain or loss is also displayed on the chart at the close of each trade. Lines and values are red for losers and green for winners.
I also added a spread value that is subtracted from the results to more accurately simulate what the gain or loss might be. Change it to match whatever instrument you are using the indicator on or set to zero to test with no spread.
Apply the indicator to the price chart.
1234567891011121314151617181920212223242526Spread = 1.5StochN = 10StochK = 3mystoch = Stochastic[StochN,StochK](customclose)if not on and mystoch crosses under 20 thenmyopen = closeopenindex = barindexon = 1endifif on and mystoch crosses over 80 thendiff = close - myopen - spreadr = 0g = 128if diff <= 0 thenr = 128g = 0endifdrawsegment(openindex, myopen,barindex,close) coloured(r,g,0)drawtext("#diff#",barindex,high+average[500](high-low)/2,SansSerif,Bold,12) coloured(r,g,0)on = 0endifreturn1 user thanked author for this post.
10/27/2019 at 1:10 PM #111327I must be really bored because I developed it a bit further. This version also calculated the returns for going long or short and displays them on the chart. It displays the gain or loss on this trade, the average gain per trade, the win rate for all trades and the total gain or loss for all trades.
- G = Total gain
- AvgG = Average Gain per Trade
- WR = % Win Rate
- Unlabelled = The gain or loss for this trade.
Long trade results are above the candle in green and short trade results are below in red.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051Spread = 1.5StochN = 10StochK = 3UpperLevel = 80LowerLevel = 20mystoch = Stochastic[StochN,StochK](customclose)if not on and mystoch crosses under lowerlevel thenmyopen = closeopenindex = barindexon = 1endifif on and mystoch crosses over upperlevel thendiff = close - myopen - spreadsdiff = myopen - close - spreadcount = count + 1if sdiff > 0 thenr = 128g = 0swin = swin + 1endifif diff > 0 thenr = 0g = 128lwin = lwin + 1endifltotal = ltotal + diffstotal = stotal + sdifflwinrate = round(((lwin/count)*100)*10)/10swinrate = round(((swin/count)*100)*10)/10lavgwin = round((ltotal/count)*10)/10savgwin = round((stotal/count)*10)/10ltotalr = round(ltotal*10)/10stotalr = round(stotal*10)/10drawsegment(openindex, myopen,barindex,close) coloured(r,g,0)drawtext("G #ltotalr#",barindex,high+(average[500](high-low)/2)*4,SansSerif,Standard,12) coloured(0,128,0)drawtext("AvgG #lavgwin#",barindex,high+(average[500](high-low)/2)*3,SansSerif,Standard,12) coloured(0,128,0)drawtext("WR #lwinrate#%",barindex,high+(average[500](high-low)/2)*2,SansSerif,Standard,12) coloured(0,128,0)drawtext("#diff#",barindex,high+(average[500](high-low)/2),SansSerif,Standard,12) coloured(0,128,0)drawtext("#sdiff#",barindex,low-(average[500](high-low)/2),SansSerif,Standard,12) coloured(128,0,0)drawtext("WR #swinrate#%",barindex,low-(average[500](high-low)/2)*2,SansSerif,Standard,12) coloured(128,0,0)drawtext("AvgG #savgwin#",barindex,low-(average[500](high-low)/2)*3,SansSerif,Standard,12) coloured(128,0,0)drawtext("G #stotalr#",barindex,low-(average[500](high-low)/2)*4,SansSerif,Standard,12) coloured(128,0,0)on = 0endifreturnI also turned the code into a line chart to show the historical results. You can turn on or off which of the three line types are displayed.
Really it would be easier just to write a strategy to get all this same information but like I said I was bored!
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960DisplayTotal = 1 //0=off 1=onDisplayWinRate = 1 //0=off 1=onDisplayAvgGain = 1 //0=off 1=onSpread = 1.5StochN = 10StochK = 3UpperLevel = 80LowerLevel = 20mystoch = Stochastic[StochN,StochK](customclose)if not on and mystoch crosses under lowerlevel thenmyopen = closeon = 1endifif on and mystoch crosses over upperlevel thendiff = close - myopen - spreadsdiff = myopen - close - spreadcount = count + 1if sdiff > 0 thenswin = swin + 1endifif diff > 0 thenlwin = lwin + 1endifltotal = ltotal + diffstotal = stotal + sdifflwinrate = round(((lwin/count)*100)*10)/10swinrate = round(((swin/count)*100)*10)/10lavgwin = round((ltotal/count)*10)/10savgwin = round((stotal/count)*10)/10on = 0endifonce ltotalr = undefinedonce lwinrater = undefinedonce lavgwinr = undefinedonce stotalr = undefinedonce swinrater = undefinedonce savgwinr = undefinedif DisplayTotal thenltotalr = ltotalstotalr = stotalendifif DisplayWinRate thenlwinrater = lwinrateswinrater = swinrateendifif DisplayAvgGain thenlavgwinr = lavgwinsavgwinr = savgwinendifreturn 0,ltotalr coloured(0,128,0) as "LGain",stotalr coloured(128,0,0) as "SGain",lwinrater coloured(0,128,0) as "LWR%", swinrater coloured(128,0,0) as "SWR%",lavgwinr coloured(0,128,0) as "LAvgG", savgwinr coloured(128,0,0) as "SAvgG"1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on