How to build a RSI Range

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #165359 quote
    imokdesign
    Participant
    Senior

    Good evening, I just have a question from a scretched idea from Yesterday (see screenshot). I want to try to build an RSI Range System which Make a box Range including the incomming “crossesbelow 30” or “crossesabove 70” till “crossesabove 30” or “crossesbelow 70” candle?

    After that happend it should place a Stop Buy and Stop Sell (OCO) a bit over the range, so the Market can decide the direction. A bit like an open Range Breakout but just with the RSI range. After buy or sell order was activated, the stop should be at the low or high of the range with an 1% or 0,5% Moneymanagement. The Profit should be the half or 1:1 of the Range. I haven’t programmed anything for this yet. At first it’s just thoughts.

    Bildschirmfoto-2021-03-25-um-23.49.57.jpg Bildschirmfoto-2021-03-25-um-23.49.57.jpg
    #165361 quote
    robertogozzi
    Moderator
    Master

    There you go:

    // X    = crosses
    // b    = below
    // a    = above
    // OS   = OverSold
    // OB   = OverBought
    //
    // XbOS = Crosses Below OverSold
    // XaOS = Crosses Above OverSold
    // XbOB = Crosses Below OverBought
    // XaOB = Crosses Above OverBought
    //
    DEFPARAM CumulateOrders = FALSE
    Offset = 1 * PipSize             //1   pip above MaxRange/below MinRange
    OB     = 70                      //70 - 30 OverBought & OverSold tresholds
    OS     = 100 - OB
    MyRSI  = Rsi[14](close)          //14  periods
    XbOS   = MyRsi Crosses Under OS
    XaOS   = MyRsi Crosses Over  OS
    XbOB   = MyRsi Crosses Under OB
    XaOB   = MyRsi Crosses Over  OB
    IF XbOS or XaOB THEN
       GoShort  = 0
       GoLong   = 0
       Entry    = 0
       SL       = 0
       TP       = 0
       MaxRange = high
       MinRange = low
    ENDIF
    MaxRange = max(MaxRange,high)
    MinRange = min(MinRange,low)
    // exit LONG
    IF LongOnMarket  AND XaOB THEN
       SELL AT Market
    ENDIF
    // exit SHORT
    IF ShortOnMarket AND XbOS THEN
       EXITSHORT AT Market
    ENDIF
    // enter LONG
    IF XaOS THEN
       GoShort = 0
       GoLong  = 1
       Entry   = MaxRange + Offset
       SL      = abs(Entry - MinRange)
       TP      = abs(MaxRange - MinRange) / 2
    ENDIF
    IF GoLong  AND Not LongOnMarket THEN
       BUY 1 Contract AT Entry STOP
       SET TARGET PROFIT TP
       SET STOP   LOSS   SL
    ENDIF
    // enter SHORT
    IF XbOB THEN
       GoShort = 1
       GoLong  = 0
       Entry   = MinRange - Offset
       SL      = abs(Entry - MinRange)
       TP      = abs(MaxRange - MinRange) / 2
    ENDIF
    IF GoShort AND Not ShortOnMarket THEN
       SELLSHORT 1 Contract AT Entry STOP
       SET TARGET PROFIT TP
       SET STOP   LOSS   SL
    ENDIF
    #165519 quote
    imokdesign
    Participant
    Senior

    Hi robertogozzi, thank you very much. That was fast. The code does something, but sometimes it does something else. I can’t say exactly what it does (see screenshot, after the second box). There are some trades that I can’t explain. I draw a box from the RSI range to see, if the price breaks out of the high or low of this Range. Or do I have to change something in lines 22 to 26?

    Bildschirmfoto-2021-03-27-um-23.10.50.png Bildschirmfoto-2021-03-27-um-23.10.50.png
    #165524 quote
    robertogozzi
    Moderator
    Master

    I added some code to clear data when OnMarket and I also apopended some debugging instructions to help you better identify Entry price, ST, TP and other variables using GRAPH and GRAPHONPRICE:

    // X    = crosses
    // b    = below
    // a    = above
    // OS   = OverSold
    // OB   = OverBought
    //
    // XbOS = Crosses Below OverSold
    // XaOS = Crosses Above OverSold
    // XbOB = Crosses Below OverBought
    // XaOB = Crosses Above OverBought
    //
    DEFPARAM CumulateOrders = FALSE
    Offset = 1 * PipSize             //1   pip above MaxRange/below MinRange
    OB     = 70                      //70 - 30 OverBought & OverSold tresholds
    OS     = 100 - OB
    MyRSI  = Rsi[14](close)          //14  periods
    XbOS   = MyRsi Crosses Under OS
    XaOS   = MyRsi Crosses Over  OS
    XbOB   = MyRsi Crosses Under OB
    XaOB   = MyRsi Crosses Over  OB
    //
    IF OnMarket OR StrategyProfit <> StrategyProfit[1] THEN
       XaOB = 0
       XbOB = 0
       XaOS = 0
       XbOS = 0
       MaxRange = 0
       MinRange = 0
       Entry    = 0
       GoShort  = 0
       GoLong   = 0
    ENDIF
    //
    IF XbOS or XaOB THEN
       GoShort  = 0
       GoLong   = 0
       Entry    = 0
       SL       = 0
       TP       = 0
       MaxRange = high
       MinRange = low
    ENDIF
    MaxRange = max(MaxRange,high)
    MinRange = min(MinRange,low)
    // exit LONG
    IF LongOnMarket  AND XaOB THEN
       SELL AT Market
    ENDIF
    // exit SHORT
    IF ShortOnMarket AND XbOS THEN
       EXITSHORT AT Market
    ENDIF
    // enter LONG
    IF XaOS AND (MaxRange > 0) AND (MinRange > 0) THEN
       GoShort = 0
       GoLong  = 1
       Entry   = MaxRange + Offset
       SL      = abs(Entry - MinRange)
       TP      = abs(MaxRange - MinRange) / 2
    ENDIF
    IF GoLong  AND Not LongOnMarket THEN
       BUY 1 Contract AT Entry STOP
       SET TARGET PROFIT TP
       SET STOP   LOSS   SL
    ENDIF
    // enter SHORT
    IF XbOB AND (MaxRange > 0) AND (MinRange > 0) THEN
       GoShort = 1
       GoLong  = 0
       Entry   = MinRange - Offset
       SL      = abs(Entry - MinRange)
       TP      = abs(MaxRange - MinRange) / 2
    ENDIF
    IF GoShort AND Not ShortOnMarket THEN
       SELLSHORT 1 Contract AT Entry STOP
       SET TARGET PROFIT TP
       SET STOP   LOSS   SL
    ENDIF
    /////////////////////////////////////////////////////////////////////////////
    GraphOnPrice Entry
    AA = TP
    BB = SL
    IF LongOnMarket THEN
       GraphOnPrice TradePrice + AA coloured(0,0,255,255) AS "TP"
       GraphOnPrice TradePrice - BB coloured(255,0,0,255) AS "SL"
    ELSIF ShortOnMarket THEN
       GraphOnPrice TradePrice - AA coloured(0,0,255,255) AS "TP"
       GraphOnPrice TradePrice + SL coloured(255,0,0,255) AS "SL"
    ELSE
       GraphOnPrice close coloured(0,0,0,0)
       GraphOnPrice close coloured(0,0,0,0)
    ENDIF
    graph XaOB
    graph XbOB
    graph XaOS
    graph XbOS
    graph LongOnMarket
    graph ShortOnMarket
    /////////////////////////////////////////////////////////////////////////////

    You may also want to add this indicator to your chart to highlight periods within OverBought and OverSold periods and plot a rectangle around MaxRange and MinRange:

    Offset = 1 * PipSize             //1   pip above MaxRange/below MinRange
    OB     = 70                      //70 - 30 OverBought & OverSold tresholds
    OS     = 100 - OB
    MyRSI  = Rsi[14](close)          //14  periods
    XbOS   = MyRsi Crosses Under OS
    XaOS   = MyRsi Crosses Over  OS
    XbOB   = MyRsi Crosses Under OB
    XaOB   = MyRsi Crosses Over  OB
    IF XbOS or XaOB THEN
       MaxRange = high
       MinRange = low
       Bar1     = BarIndex
    ENDIF
    IF XaOS OR XbOB THEN
       Bar2     = BarIndex[1]
       DrawRectangle(Bar1,MaxRange+Offset,Bar2,MinRange-Offset) coloured(0,0,255,20) bordercolor(255,0,0,255)
    ELSE
       MaxRange = max(MaxRange,high)
       MinRange = min(MinRange,low)
    ENDIF
    ONCE r = 0
    ONCE g = 0
    ONCE b = 0
    ONCE t = 0
    IF XaOB THEN
       r = 0
       g = 255                //GREEN
       b = 0
       t = 20
    ELSIF XbOS THEN
       r = 255                //RED
       g = 0
       b = 0
       t = 20
    ELSIF XbOB OR XaOS THEN
       r = 255                //WHITE
       g = 255
       b = 255
       t = 255
    ENDIF
    BackGroundColor(r,g,b,t)
    RETURN
    x-5.jpg x-5.jpg
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

How to build a RSI Range


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
imokdesign @imokdesign Participant
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by robertogozzi
4 years, 11 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 03/25/2021
Status: Active
Attachments: 3 files
Logo Logo
Loading...