Help programming this code to trade shorts as well

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #57766 quote
    Mags67
    Participant
    Average
    Hi!

    I’m new to programming so need some help.

    Why can’t I get this system to trade shorts as well?

    Thxs, Magnus

    //-------------------------------------------------------------------------
    // Main code : Mov&RSI
    //-------------------------------------------------------------------------
    DEFPARAM CumulateOrders = false
    
    ShortRSI = RSI[3](close)
    LongRSI = RSI[25](close) //1 month RSI
    MA = Average[22,0](close) //1 month moving average of close
    Slope = MA/MA[1]-1 //Slope of 1 month moving average
    
    LongEntry = LongEntry AND ShortRSI < 15 //Buy when RSI2 below 15
    LongEntry = LongEntry AND LongRSI > 50 //Filter for long RSI above 50
    LongEntry = LongEntry AND Slope > 0 //Filter for positive slope of MovAvg
    
    LongExit = ShortRSI > 65 //Exit position when short RSI above 65
    
    // Conditions to enter long positions
    IF LongEntry THEN
    BUY AT MARKET
    ENDIF
    
    // Conditions to exit long positions
    IF LongExit THEN
    SELL AT MARKET
    ENDIF
    
    ShortEntry = ShortEntry AND ShortRSI > 85 //Sell when RSI2 above 85
    ShortEntry = ShortEntry AND LongRSI < 50 //Filter for long RSI under 50
    ShortEntry = ShortEntry AND Slope < 0 //Filter for negative slope of MovAvg
    
    ShortExit = ShortRSI < 35 //Exit position when short RSI under 35
    
    // Conditions to enter short positions
    IF ShortEntry THEN
    SELL AT MARKET
    ENDIF
    
    // Conditions to exit short positions
    IF ShortExit THEN
    BUY AT MARKET
    ENDIF

     

    #57772 quote
    Nicolas
    Keymaster
    Master

    Rules of the forum are written in bold and in the yellow box just above the text editor when you write a post, please respect them. Thank you.

    At line 35 of your code, you must use SELLSHORT to initiate a new sell order, SELL instruction is made to close long orders.

    Same for line 40, use EXITSHORT to close a short position.

    #57838 quote
    Mags67
    Participant
    Average

    Thanks Nicolas, but now I don’t get it to take any positions at all..? Am I doing it all wrong?

    Sorry to waste your time on trivialities!

    #57840 quote
    Nicolas
    Keymaster
    Master

    Should work if you only changed the lines 35 and 40.

    #57855 quote
    GraHal
    Participant
    Master

    I played about with it after I got no trades (even after Nicolas change) then I got it to trade but was a  ‘oblique path to doom’ (looked like all losers?) then I reversed the buy sellshort conditions (as a quick look see) but still not good.

    Then I started to change the code and got trades on Daily TF and 4 Hours, but was still looking way out so I abandoned it.

    I reckon you should comment out all except 1 entry and 1 exit condition and get it trading and then uncomment more … making  only 1 change at a time?

    Please post results as I may get back into it at some stage?

    GraHal

    #57858 quote
    Nicolas
    Keymaster
    Master

    You can test each variable with the GRAPH instruction while backtesting, that way you’ll get a better view of what’s not working:

    Just add these lines at the end of the code and launch a backtest.

    graph longentry as "long entry"
    graph shortentry as "short entry"

    If a variable is true, then it should be equal to 1, and a new order should be initiated as per your conditions.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.

Help programming this code to trade shorts as well


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Mags67 @mags67 Participant
Summary

This topic contains 5 replies,
has 3 voices, and was last updated by Nicolas
8 years, 1 month ago.

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