Help to code basic stochastic strategy
Forums › ProRealTime English forum › ProOrder support › Help to code basic stochastic strategy
- This topic has 8 replies, 3 voices, and was last updated 6 years ago by
Vonasi.
-
-
11/27/2018 at 9:22 AM #85799
Hi from complete ProRealTime noob. Have started watching the training videos and hope to contribute in the near future.
Could someone assist with the code for a very simply strategy to play around with.
Enter: When stochastics reaches a certain level, e.g. 95
Exit: TP 1 x atr and SL 1 x atr
11/27/2018 at 9:50 AM #8580111/27/2018 at 10:19 AM #85809A little more detail on the exact strategy might be helpful to save someone the time writing something that is not what you exactly have in mind. Stochastic settings, average true range period, single position or multiple positions held, do you want the ATR stop and target to be adjusted at each bar closure or fixed at the levels when a trade is opened etc etc?
11/27/2018 at 10:52 AM #85811Apologies Vonasi, and thanks for moving the post to correct forum.
I have managed to create some simple code using the “Simplified Creation” tool, just to get familiar with the backtesting tool. Just entered fixed TP and SL points for now.
I am testing the strategy on the South Africa 40 Cash Index.
The very basic strategy is that when stochastic goes below a certain level, e.g. 20, price will typically continue in the same direction for a few more points (ie becoming more oversold). Also will play around with the code once it is working properly to test many different strategies just based on the stochastic indicator and different R:R.
1234567891011121314// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Conditions to enter long positionsindicator1 = Stochastic[14,3](close)c1 = (indicator1 <= 20)IF c1 THENSELLSHORT 1 CONTRACT AT MARKETENDIF// Stops and targetsSET STOP pLOSS 200SET TARGET pPROFIT 200For now my three challenges:
a. When I enter a “Spread” to be taken into account, the number of trades become significantly less, not sure why this is happening?
b. I would like to add some code to only allow trades during certain timeframes, e.g. when the ALSI market is open from 08:30 – 17:30 GMT+2
c. Need to add a reset level, otherwise it could open trades if TP or SL reached while stochastic is still below the entry level
11/27/2018 at 11:25 AM #8581412345678910111213141516c1 = Stochastic[14,3](close) <= 20c2 = time >= 083000 and time < 173000if tradeon and Stochastic[14,3](close) > 20 thentradeon = 0endifIF not onmarket and c1 and c2 and not tradeon THENSELLSHORT 1 CONTRACT AT MARKETtradeon = 1ENDIFsltplevel = averagetruerange[14]SET STOP pLOSS sltplevelSET TARGET pPROFIT sltplevelMaybe the above is something like what you want? It resets to trade again when the stochastic returns over 20.
I would suggest using GRAPH to show the TIME and/or C2 to double check it is trading when you actually want it to.
I have put in an ATR stop which will change the stop and target levels at each bar close. Move lines 13 to 16 to within your IF THEN SELLSHORT ENDIF section of code to have it fixed at the ATR at the time of the conditions being met.
I’m not sure why the spread should effect your trade quantity.
1 user thanked author for this post.
11/27/2018 at 11:34 AM #85815When I enter a “Spread”
where are you entering “Spread” … in your code (post an example) or in the box that gets ticked and is called Spread?
11/27/2018 at 11:42 AM #85817I am ticking the box “Spread” and entering the typical point spread in this market
11/27/2018 at 11:57 AM #85818Thanks a lot for the help Vonasi!
11/27/2018 at 12:08 PM #85819Thanks a lot for the help Vonasi!
No problem – I hope it helps.
Just click on the ‘Thanks’ button in any future posts where you want to thank someone and it will be highlighted on their post and give them a warm fuzzy glow inside! 🙂
2 users thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on