Help to code basic stochastic strategy

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #85799 quote
    pasopvirpot
    Participant
    New

    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

    #85801 quote
    Vonasi
    Moderator
    Master

    Welcome to the forums.

    Please try to post in the correct forum with future topics. I have moved your post to the ProOrder forums which is the best place to find strategy coding solutions.

    #85809 quote
    Vonasi
    Moderator
    Master

    A 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?

    #85811 quote
    pasopvirpot
    Participant
    New

    Apologies 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.

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    // Conditions to enter long positions
    indicator1 = Stochastic[14,3](close)
    c1 = (indicator1 <= 20)
    
    IF c1 THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    
    // Stops and targets
    SET STOP pLOSS 200
    SET TARGET pPROFIT 200

    For 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

    #85814 quote
    Vonasi
    Moderator
    Master
    c1 = Stochastic[14,3](close) <= 20
    c2 = time >= 083000 and time < 173000
    
    if tradeon and Stochastic[14,3](close) > 20 then
    tradeon = 0
    endif
     
    IF not onmarket and c1 and c2 and not tradeon THEN
    SELLSHORT 1 CONTRACT AT MARKET
    tradeon = 1
    ENDIF
     
    sltplevel = averagetruerange[14]
    
    SET STOP pLOSS sltplevel
    SET TARGET pPROFIT sltplevel
    

    Maybe 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.

    pasopvirpot thanked this post
    #85815 quote
    GraHal
    Participant
    Master

    When 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?

    #85817 quote
    pasopvirpot
    Participant
    New

    I am ticking the box “Spread” and entering the typical point spread in this market

    #85818 quote
    pasopvirpot
    Participant
    New

    Thanks a lot for the help Vonasi!

    #85819 quote
    Vonasi
    Moderator
    Master

    Thanks 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! 🙂

    pasopvirpot and Inertia thanked this post
Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.

Help to code basic stochastic strategy


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 8 replies,
has 3 voices, and was last updated by Vonasi
7 years, 3 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 11/27/2018
Status: Active
Attachments: No files
Logo Logo
Loading...