RSI and Moving Average

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #10230 quote
    jbyrne
    Participant
    Average

    Hi, I want to be able to have my code buy/sell on a Moving average Cross but the stock must have been under 40/over 60 RSI in the last 3 candles. Any help as too how I can do this? M

    defparam preloadbars = 15
    defparam CUMULATEORDERS = false
    indicator2 = call "example5 : RSI"[14]
    brsi = (indicator2 < 40)
    
    indicator3 = call "example5 : RSI"[14]
    srsi = (indicator3 > 60)
    
    indicator1 = Average[9](close)
    
    once haclose=close
    once haopen=open
    
    if barindex>1 then
    haclose=(open+close+low+high)/4
    haopen=(haopen[1]+haclose[1])/2
    endif
    
    //buy condition
    cBuy = (haclose CROSSES OVER indicator1 and brsi)
    
    //sell condition
    cSell = (haclose CROSSES UNDER indicator1 and srsi)
    
    If cbuy then
    buy 5000 CASH at market
    endif
    
    If csell then
    sell at market
    endif
    
    if csell then
    sellshort 5000 CASH at market
    endif
    
    if cbuy then
    exitshort at market
    endif

    y code so far:

    #10268 quote
    Nicolas
    Keymaster
    Master

    To achieve this, we can make a loop in the past to see if the conditions were met in the last 3 candles. We can also make summation of the result of a condition that return 1 if its met, with the SUMMATION instruction.

    Please find below your strategy modified accordingly to your needs:

    defparam preloadbars = 15
    defparam CUMULATEORDERS = false
    
    // RSI COUNT CONDITIONS
    myRSI = RSI[14](close)
    // over 60 in the last 3 periods
    countS=0
    countS=Summation[3](myRSI[1]>60)
    // under 40 in the last 3 periods
    countB=0
    countB=Summation[3](myRSI[1]<40) 
    
    indicator1 = Average[9](close)
    
    once haclose=close
    once haopen=open
    
    if barindex>1 then
    haclose=(open+close+low+high)/4
    haopen=(haopen[1]+haclose[1])/2
    endif
    
    //buy condition
    cBuy = (haclose CROSSES OVER indicator1 and countB=3)
    
    //sell condition
    cSell = (haclose CROSSES UNDER indicator1 and countS=3)
    
    If cbuy then
    buy 5000 CASH at market
    endif
    
    If csell then
    sell at market
    endif
    
    if csell then
    sellshort 5000 CASH at market
    endif
    
    if cbuy then
    exitshort at market
    endif
    #10280 quote
    jbyrne
    Participant
    Average

    Thank you very much for your reply this was very helpful 🙂

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

RSI and Moving Average


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
jbyrne @jbyrne Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by jbyrne
9 years, 8 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 07/05/2016
Status: Active
Attachments: No files
Logo Logo
Loading...