Multiple RSI exits with multiple positions

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #178319 quote
    phoentzsphoentzs
    Participant
    Master

    Hello, I have a small task … if I want to manage 2 positions with an RSI output, how can I write that?
    As a fictitious example: RSI2> 95 then sell short 2 positions. With exitshort there should be 2 outputs, 1 position closes with RSI2 <40, the 2nd position closes with RSI2 <10.

    How can I code this?

    #178334 quote
    MauroProMauroPro
    Participant
    Veteran

    Hi Phoentzs this is just one example (Dax, 15m)

    DEFPARAM cumulateOrders = false
    
    myRsi = Rsi[2](close)
    level40 = 40
    level10 = 10
    
    cLong = close crosses over average[50](close) and high> high[2]
    exitLongRsiA = myRsi crosses under level40
    exitLongRsiB = myRsi crosses under level10
    //-------------------------------------------------------------
    
    if not onMarket and  cLong then
    buy 2 contracts at market
    flagShort = 0
    endif
    
    if exitLongRsiA and flagShort = 0 then
    sell 1 contract at market
    flagShort = 1
    endif
    
    if exitLongRsiB then
    sell 1 contract at market
    endif
    Image-001-1.jpg Image-001-1.jpg
    #178356 quote
    phoentzsphoentzs
    Participant
    Master

    Very good. With a flag … thank you. I try to build it into my strategy like this. But … as a mean reversion in trend, I actually thought it was. So in the downtrend sell short at Crossover 95 and then the exits at the lower levels of the RSI. At least I think that’s a good idea. I’ll try.

    #178358 quote
    MauroProMauroPro
    Participant
    Veteran
    DEFPARAM cumulateOrders = false
    
    myRsi = Rsi[2](close)
    cEnterShort = myrsi crosses over levelEnterShort
    levelEnterShort = 95
    levelA = 40
    levelB = 10
    
    cShort = cEnterShort
    exitRsiLevelA = myRsi crosses under levelA
    exitRsiLevelB = myRsi crosses under levelB
    //-------------------------------------------------------------
    if not onMarket and  cShort then
    sellShort 2 contracts at market
    flagExit = 0
    endif
    if exitRsiLevelA and flagExit = 0 then
    exitShort 1 contract at market
    flagExit = 1
    endif
    if exitRsiLevelB then
    exitShort 1 contract at market
    endif
    
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Multiple RSI exits with multiple positions


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
phoentzs @phoentzs Participant
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by MauroProMauroPro
5 years ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 09/24/2021
Status: Active
Attachments: 1 files
ProRealCode ProRealCode
Loading...