RSI CODE help!

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #126779 quote
    rsd001
    Participant
    New

    Hi Everyone,

    Hoping someone can help me.

    I am new to this and have written a simple code which opens a sell order when the RSI is >70 and a buy order at <30. I have included for a target point range, which for this example can be 5.

    The code works fine, except, when it opens a long/short and the market moves in the required direction taking the RSI below 70 or above 30 but does not however trigger the target of 5  but instead renters the >70 or <30 area, the program gets confused and will ignore the target of 5 and then only closes the short or long at the point of <30 and long at >70. Is there a change I can make that will ensure that any opened position will close at the target value irrespective if the value goes above or below the 30/70 RSI level, and also if this were to occur then every time it does break the RSI level, it opens a subsequent position. When I back test it as it is, its doing what I want except the times where it bounces in and out of the 70/30 area.

    Any advice, help or modifications to the code would be appreciated.

    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    DEFPARAM FLATBEFORE = 000000
    DEFPARAM FLATAFTER = 000000
    
    //Conditions
    
    C1 = (RSI < 30)
    C2 = (RSI > 70)
    
    // Conditions to enter long positions
    
    IF NOT LongOnMarket AND C1 THEN
    BUY 1 CONTRACTS AT MARKET
    ENDIF
    
    // Conditions to exit long positions
    If LongOnMarket AND C2 THEN
    SELL AT MARKET
    ENDIF
    
    // Conditions to enter short positions
    IF NOT ShortOnMarket AND C2 THEN
    SELLSHORT 1 CONTRACTS AT MARKET
    ENDIF
    
    // Conditions to exit short positions
    IF ShortOnMarket AND C1 THEN
    EXITSHORT AT MARKET
    ENDIF
    
    // Stops and targets : Enter your protection stops and profit targets here
    
    SET STOP PLOSS 0
    SET TARGET PPROFIT 5
    RSD-RSI-AUTOTRADE.itf
    #126803 quote
    robertogozzi
    Moderator
    Master

    >> For clarity of messages on ProRealCode’s forums, please use the “insert code PRT” button to separate the text of the code part! Thank you! <<
    🙂

    #126810 quote
    robertogozzi
    Moderator
    Master

    Try increasing the your TP, 5 seems to not abide by the minimum distance required.

    10+ might solve it.

    #126884 quote
    rsd001
    Participant
    New

    I don’t think that makes any difference, whilst backtesting and having found this issue, the problem isn’t with the TP its when the price drops below/above the 70/30 RSi and then revisits that area. at that point, I want the code to open another trade or if nothing else, just close out the original trade at the required TP. what actually happens is that it doesn’t do this and waits for it to open/close a trade at the opposite RSI. logically, it should close at the required TP, for whatever reason this does work, but fails if it renters the are of  70/30.

    #126897 quote
    robertogozzi
    Moderator
    Master

    I can’t understand lines 2 and 3, They might be confusing.

    Line 2 is useless, since there cannot be anything  before 000000, -1 does not exist.

    Line 3 means at anytime because whatever the time it will be >  0.

    Your trades shouldn’t open at all, but if they do they should be immediately closed.

    #126906 quote
    rsd001
    Participant
    New

    They do open.

    In any case, the issue I have is not with times as I can change them to suit.

     

    just trying to find a solution to the real problem, it’s not the TP.

    #126914 quote
    robertogozzi
    Moderator
    Master

    You have to tell me:

    • instrument used
    • TF used
    • date & time of (some) candles where the strategy did not what expected.
    #126915 quote
    robertogozzi
    Moderator
    Master

    Anyway, you can replace lines 7-8 with:

    C1 = 0
    C2 = 0
    IF Not OnMarket THEN
       C1 = (RSI < 30)
       C2 = (RSI > 70)
    ENDIF

    this should do.

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

RSI CODE help!


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
rsd001 @rsd001 Participant
Summary

This topic contains 7 replies,
has 2 voices, and was last updated by robertogozzi
5 years, 10 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 04/18/2020
Status: Active
Attachments: 1 files
Logo Logo
Loading...