Distance between two SMAs

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #184439 quote
    phoentzs
    Participant
    Master

    The distance of 2 moving averages … if both are on top of each other … can I somehow code them in percent?

    For example:

    SMA20> SMA200

    And of that the distance in percent?

    #184444 quote
    robertogozzi
    Moderator
    Master

    There you go:

    PerCent = (Sma20 * 100 / Sma200) - 100
    phoentzs thanked this post
    #184448 quote
    phoentzs
    Participant
    Master

    And how exactly can I use this calculated number for long or short entries? My idea is to only enter into trades when the two SMAs are not too far apart.

    #184451 quote
    JS
    Participant
    Senior

    If PerCent > x then => Buy

    If PerCent < y then => SellShort

    x for example 0.5%

    y for example -0.5%

    Crossing MA’s at x = 0 or y = 0

    phoentzs thanked this post
    #184455 quote
    GraHal
    Participant
    Master

    distance in percent?

    Distance in  percent of what … the faster average / SMA20?

    So where SMA20 > SMA200 …

    ((SMA20-SMA200)/SMA20)*100

    phoentzs thanked this post
    #184456 quote
    JS
    Participant
    Senior

    Distance in percent of the Close

    PerCent is the same as:

    S1 = Average[20](Close)
    S2 = Average[200](Close)

    Dist = S1 – S2
    DistPerc = (Dist / Close) * 100

    #184463 quote
    phoentzs
    Participant
    Master

    I was always very good at math … I’m trying to understand which formula is better. I’ll just try it out. Thank you very much.

    GraHal thanked this post
    #184697 quote
    SnorreDK
    Participant
    Junior

    Hi. New to this forum. Such a great comunity.
    My firt try with an algo. Inspiration from Phoentzs

    Is this someting to build on or what do u think, Too much time in market? How to improve thos without curvefitting?

    // Wallstreet 1H - SMA Distance
    // SnorreDK @ prorealcode.com
    //2022-01-06
    
    //To do - Better entrys - more standard filters?
    //Try other trailing
    //****************************************** **************************************
    
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    ONCE sl = 1.5
    ONCE sl2 = 1.0
    ONCE A1 = 70.0
    ONCE A2 = 60.0
    ONCE tsm = 4.0
    ONCE tst = 4.6
    ONCE tst1 = 1.5
    ONCE st = 0.28
    ONCE A11 = 10.0
    ONCE A22 = 20.0
    ONCE y1 = -3.1
    positionsize = 1
    
    Timeframe(4h, updateonclose)
    AA=RSI[14](close)
    
    
    Timeframe(default)
    CB2 = (AA<A1 and AA>A11) //4H RSI filter
    CS2 = (AA<A2 and AA>A22)  //4H RSI filter
    
    
    S1 = Average[20](Close)
    S2 = Average[200](Close)
    Dist = S1 - S2
    DistPerc = (Dist / Close) * 100
    CB1 = DistPerc > y1
    CS1 = DistPerc < y1
    
    
    If not (DayOfWeek = 2) then
    If CB1 and CB2 and not shortonmarket then
    BUY positionsize contracts AT MARKET
    Endif
    
    If CS1 and CS2 and not longonmarket then
    SELLSHORT 1 CONTRACTS AT MARKET
    Endif
    endif
    
    
    //****************************************************************************************
    // trailing stop atr
    once trailingstoptype     = 1    // trailing stop - 0 off, 1 on
     
    once tsincrements = st          // typically between 0 and 0.25
    once tsminatrdist = tsm         // typically between 1 and 4
     
    once tsatrperiod    = 14         // ts atr parameter
    once tsminstop      = 12         // ts minimum stop distance, set to IG min value
     
    once tssensitivity        = 1    // [0]close;[1]high/low
     
    if trailingstoptype then
    if barindex=tradeindex then
    trailingstoplong     = tst   // ts atr distance, typically between 4 and 10
    trailingstopshort    = tst1   // ts atr distance, typically between 4 and 10
    else
    if longonmarket then
    if tsnewsl>0 then
    if trailingstoplong>tsminatrdist then
    if tsnewsl>tsnewsl[1] then
    trailingstoplong=trailingstoplong
    else
    trailingstoplong=trailingstoplong-tsincrements
    endif
    else
    trailingstoplong=tsminatrdist
    endif
    endif
    endif
    if shortonmarket then
    if tsnewsl>0 then
    if trailingstopshort>tsminatrdist then
    if tsnewsl<tsnewsl[1] then
    trailingstopshort=trailingstopshort
    else
    trailingstopshort=trailingstopshort-tsincrements
    endif
    else
    trailingstopshort=tsminatrdist
    endif
    endif
    endif
    endif
    tsatr=averagetruerange[tsatrperiod]((close/10)*pipsize)/1000
    //tsatr=averagetruerange[tsatrperiod]((close/1)*pipsize) // (forex)
    tgl=round(tsatr*trailingstoplong)
    tgs=round(tsatr*trailingstopshort)
    if not onmarket or ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) then
    tsmaxprice=0
    tsminprice=close
    tsnewsl=0
    endif
    if tssensitivity then
    tssensitivitylong=high
    tssensitivityshort=low
    else
    tssensitivitylong=close
    tssensitivityshort=close
    endif
    if longonmarket then
    tsmaxprice=max(tsmaxprice,tssensitivitylong)
    if tsmaxprice-tradeprice(1)>=tgl*pointsize then
    if tsmaxprice-tradeprice(1)>=tsminstop then
    tsnewsl=tsmaxprice-tgl*pointsize
    else
    tsnewsl=tsmaxprice-tsminstop*pointsize
    endif
    endif
    endif
    if shortonmarket then
    tsminprice=min(tsminprice,tssensitivityshort)
    if tradeprice(1)-tsminprice>=tgs*pointsize then
    if tradeprice(1)-tsminprice>=tsminstop then
    tsnewsl=tsminprice+tgs*pointsize
    else
    tsnewsl=tsminprice+tsminstop*pointsize
    endif
    endif
    endif
    if longonmarket then
    if tsnewsl>0 then
    sell at tsnewsl stop
    endif
    if tsnewsl>0 then
    if low crosses under tsnewsl then
    sell at market // when stop is rejected
    endif
    endif
    endif
    if shortonmarket then
    if tsnewsl>0 then
    exitshort at tsnewsl stop
    endif
    if tsnewsl>0 then
    if high crosses over tsnewsl then
    exitshort at market // when stop is rejected
    endif
    endif
    endif
    endif
    
    If shortonmarket then
    SET STOP %loss SL2
    endif
    If Longonmarket then
    SET STOP %loss SL
    endif
    SMA-Distance.png SMA-Distance.png
    #184764 quote
    phoentzs
    Participant
    Master

    Personally, I think it’s been on the market for a long time, maybe too long. I can see that the setup is modeled on my H4 breakout. This type of setup works very well for me. But my little timeframe is M1. At the moment I’m also working on a setup with RSI. But with RSI2 in the H4 as a reversal. Build it yourself with the timeframes like H4 breakout. But it is still in progress.

    #184930 quote
    SnorreDK
    Participant
    Junior

    Sorry. My aproach with sma-distance doesnt make any sense.

    MA20 and MA200 are close together buy signal ?, far apart buy signal ??

    it’s because distperc never goes above 3 or below -3 so the condition is always true

    unknown-43.png unknown-43.png
    #184935 quote
    phoentzs
    Participant
    Master

    I’ve put this type of calculation aside for now. Even if it would be nice to calculate it so easily, it somehow doesn’t work that way. I continue to use my classic pullbacks. So MACD pullback or RSI pullback in connection with the MAs. That works pretty well.

    #184946 quote
    JS
    Participant
    Senior
    S1 = Average[20](Close)
    S2 = Average[200](Close)
    Dist = S1 - S2
    DistPerc = (Dist / Close) * 100
    CB1 = DistPerc > y1
    CS1 = DistPerc < y1

    The distance between the MA’s can be positief or negatief and zero for the crossing of the MA’s
    For a Long signal use DistPerc > “Positief Value” (for example yl = 0.5)
    For a Short signal use DistPerc < "Negative Value" (for example ys = -0.5) In your code there is only a negative value y1 = -3.1

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

Distance between two SMAs


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
phoentzs @phoentzs Participant
Summary

This topic contains 11 replies,
has 5 voices, and was last updated by JS
4 years, 1 month ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 01/03/2022
Status: Active
Attachments: 2 files
Logo Logo
Loading...