Moving average cross over on multiple timeframes, 1-3 risk reward

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #175094 quote
    josward1
    Participant
    New

    Hello i am new on here and have a moving average strategy i wish to put into an automated trading bot. It marrys up data on multiple timeframes.

    Im a trader rather than programmer so i need help to do this, although i need to understand the programming side so i can play around with parameters.

    The basic structure of the strategy is price to be above or below an SMA on the 4 hour and day timeframe and trade to be taken on a crossoveer of an SMA

    on a 15 min timeframe. with a 1-3 risk reward ratio and a trailing stop loss.

    I also want a condition on there where if the trigger candle is of a certaine (adjustable) size the trade will trigger on a pullback to 50% of this candle body

    Could somebody please advise on how and where to start with this? I am also in the process of reading the manual but unfortunately still cant work out

    where to start and the basic structure of how the programming should go.

    Thanks,

    Joe

    Meta Signals Pro thanked this post
    #175147 quote
    robertogozzi
    Moderator
    Master

    There you go:

    DEFPARAM CumulateOrders = false
    Timeframe(Daily,UpdateOnClose)
    SmaD   = average[100,0](close)
    //
    Timeframe(4h,UpdateOnClose)
    Sma4h  = average[100,0](close)
    //
    Timeframe(15 Minute,UpdateOnClose)
    Sma15m = average[100,0](close)
    //
    Timeframe(default)
    L1     = close > SmaD
    S1     = close < SmaD
    L2     = close > Sma4h
    S2     = close < Sma4h
    L3     = close CROSSES OVER  Sma15m
    S3     = close CROSSES UNDER Sma15m
    CondL  = L1 and L2 and L3 and Not OnMarket
    CondS  = S1 and S2 and S3 and Not OnMarket
    If CondL THEN
       BUY 1 Contract AT Market
    Elsif CondS THEN
       SELLSHORT 1 Contract AT Market
    ENDIF
    set stop   pLoss   100
    set target pProfit 300
    #175160 quote
    robertogozzi
    Moderator
    Master

    I forgot to add the trailing stop:

    DEFPARAM CumulateOrders = false
    Timeframe(Daily,UpdateOnClose)
    SmaD   = average[100,0](close)
    //
    Timeframe(4h,UpdateOnClose)
    Sma4h  = average[100,0](close)
    //
    Timeframe(15 Minute,UpdateOnClose)
    Sma15m = average[100,0](close)
    //
    Timeframe(default)
    L1     = close > SmaD
    S1     = close < SmaD
    L2     = close > Sma4h
    S2     = close < Sma4h
    L3     = close CROSSES OVER  Sma15m
    S3     = close CROSSES UNDER Sma15m
    CondL  = L1 and L2 and L3 and Not OnMarket
    CondS  = S1 and S2 and S3 and Not OnMarket
    If CondL THEN
       BUY 1 Contract AT Market
    Elsif CondS THEN
       SELLSHORT 1 Contract AT Market
    ENDIF
    set stop   pLoss   100
    set target pProfit 300
     
    //************************************************************************
    //trailing stop function
    //
    //by Nicolas
    //(https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/)
    //
    trailingstart = 20  //trailing will start @trailinstart points profit
    trailingstep  = 5   //trailing step to move the "stoploss"
     
    //reset the stoploss value
    IF NOT ONMARKET THEN
     newSL=0
    ENDIF
     
    //manage long positions
    IF LONGONMARKET THEN
    //first move (breakeven)
     IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
      newSL = tradeprice(1)+trailingstep*pipsize
     ENDIF
    //next moves
     IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
      newSL = newSL+trailingstep*pipsize
     ENDIF
    ENDIF
     
    //manage short positions
    IF SHORTONMARKET THEN
    //first move (breakeven)
     IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN
      newSL = tradeprice(1)-trailingstep*pipsize
     ENDIF
    //next moves
     IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
      newSL = newSL-trailingstep*pipsize
     ENDIF
    ENDIF
     
    //stop order to exit the positions
    IF newSL>0 THEN
     SELL AT newSL STOP
     EXITSHORT AT newSL STOP
    ENDIF
    #175358 quote
    josward1
    Participant
    New

    Hi thankyou for your quick response. This was the basic idea if my strategy,
    I have taken the basic structure of what you posted to adapt to my full strategy
    but it did not end up working, there are also a few faults with it i have
    tried a few different things to get it working but have typed it out below so you can
    see what i’m going for.

    DEFPARAM CumulateOrders = false
    Timeframe(Daily,UpdateOnClose)
    sma501d = Average[50](close)
    //
    sma901d = Average[90](close)
    //
    sma2001d = Average[200](close)
    //
    Timeframe(4h,UpdateOnClose)
    sma504h = Average[50](close)
    //
    sma904h = Average[90](close)
    //
    sma2004h = Average[200](close)
    //
    Timeframe(15 Minute,UpdateOnClose)
    sma5015m = Average[50](close)
    //
    sma9015m = Average[90](close)
    //
    sma20015m = Average[200]
    //
    ema3415m = ExponentialAverage[33](close)
    //
    ema5515m = ExponentialAverage[55](close)
    //
    Timeframe(default)
    L1 = sma501d > sma901d //I would like to adjust the distances between the moving averages in pips
    S1 = sma501d < sma901d L2 = sma901d > sma2001d
    S2 = sma901d < sma2001d L3 = sma504h > sma904h
    S3 = sma504h < sma904h L4 = sma904h > sma2004h
    S4 = sma904h < sma2004h L5 = sma5015m > sma9015m
    S5 = sma5015m < sma9015m L6 = sma9015m > sma20015m
    S6 = sma9015m < sma20015m L7 = close > sma501d
    S7 = close < sma501d L8 = close > sma901d
    S8 = close < sma901d L9 = close > sma2001d
    S9 = close < sma2001d L10 = close > sma504h
    S10 = close < sma504h L11 = close > sma904h
    S11 = close < sma904h L12 = close > sma2004h
    S12 = close < sma2004h L13 = close > sma9015m
    S13 = close < sma9015m L14 = close > sma20015m
    S14 = close < sma20015m L15 = close CROSSES OVER ema3415m and ema5515m and sma5015m [Crosses over all in same candle] // I need the trigger candle to have met this criteria within the close of one candle on default timeframe S15 = close CROSSES UNDER ema3415m and ema5515m and sma5015m [Crosses over all in same candle] // I need the trigger candle to have met this criteria within the close of one candle on default timeframe CondL = L1 and L2 and L3 and L4 and L5 and L6 and L7 and L8 and L9 and L10 and L11 and L12 and L13 and L14 and L15 Not OnMarket CondS = S1 and S2 and S3 and S4 and S5 and S6 and S7 and S8 and S9 and S10 and S11 and S12 and S13 and S14 and S15 Not OnMarket If CondL and condM THEN BUY 1 Contract AT Market Elsif CondS and CondT THEN SELLSHORT 1 Contract AT Market ENDIF set stop pLoss 10 set target pProfit 30 The strategy goes as follows: 1 day timeframe: 50 sma > 90sma
    90 sma > 200sma
    close > 50sma
    close > 90sma
    close > 200sma

    4 hour timeframe:
    50 sma > 90sma
    90 sma > 200sma
    close > 50sma
    close > 90sma
    close > 200sma

    15 min timeframe

    50 sma > 90sma
    90 sma > 200sma
    close crosses over ema3415m and 5515m and sma5015m (crosses all within same candle on closing basis)

    Buy 1-3 risk reward.

    1 day timeframe:
    50 sma < 90sma 90 sma < 200sma close < 50sma close < 90sma close < 200sma 4 hour timeframe: 50 sma < 90sma 90 sma < 200sma close < 50sma close < 90sma close < 200sma 15 min timeframe 50 sma < 90sma 90 sma < 200sma close crosses under ema3415m and 5515m and sma5015m (crosses all within same candle on closing basis) sell risk reward 1-3 I also need a condition putting on there where that if the signal candle exceeds 15 pips, the bot will only take a trade if the price retraces to 50% of this candle on the next candle only. Thankyou for your help kind regards

    #175359 quote
    josward1
    Participant
    New

    I apologize for the messy visual, i am new to this i tried to line this up as you would see it on the coding page
    please let me know if you have any questions regarding it. Thank you

    #175389 quote
    josward1
    Participant
    New

    I have attempted to order the programming i have for clearer reading. I hope this works

    DEFPARAM CumulateOrders = false
    Timeframe(Daily,UpdateOnClose)
    sma501d   = Average[50](close)
    //
    sma901d   = Average[90](close)
    //
    sma2001d  = Average[200](close)
    //
    Timeframe(4h,UpdateOnClose)
    sma504h  = Average[50](close)
    //
    sma904h  = Average[90](close)
    //
    sma2004h = Average[200](close)
    //
    Timeframe(15 Minute,UpdateOnClose)
    sma5015m = Average[50](close)
    //
    sma9015m = Average[90](close)
    //
    sma20015m = Average[200]
    //
    ema3415m  = ExponentialAverage[33](close)
    //
    ema5515m  = ExponentialAverage[55](close)
    //
    Timeframe(default)
    L1     = sma501d > sma901d           //I would like to be able to adjust the 
    S1     = sma501d < sma901d             distances between the moving averages in pips
    L2     = sma901d > sma2001d
    S2     = sma901d < sma2001d
    L3     = sma504h > sma904h
    S3     = sma504h < sma904h
    L4     = sma904h > sma2004h
    S4     = sma904h <  sma2004h
    L5     = sma5015m > sma9015m
    S5     = sma5015m < sma9015m
    L6     = sma9015m > sma20015m
    S6     = sma9015m < sma20015m
    L7     = close > sma501d
    S7     = close < sma501d
    L8     = close > sma901d
    S8     = close < sma901d
    L9     = close > sma2001d
    S9     = close < sma2001d
    L10    = close > sma504h
    S10    = close < sma504h
    L11    = close > sma904h
    S11    = close < sma904h
    L12    = close > sma2004h
    S12    = close < sma2004h
    L13    = close > sma9015m
    S13    = close < sma9015m
    L14    = close > sma20015m
    S14    = close < sma20015m
    L15    = close CROSSES OVER  ema3415m and ema5515m and sma5015m   
                   [Crosses over all in same candle on closing basis]   
    // I need the trigger candle to have met this criteria within the close of one
       candle on default time frame
    S15     = close CROSSES UNDER ema3415m and ema5515m and sma5015m  
                 [Crosses over all in same candle on closing basis]
    CondL   = L1 and L2 and L3 and L4 and L5 and L6 and L7 and L8 and L9 and L10
              and L11 and L12 and L13 and L14 and L15 Not OnMarket
    CondS  = S1 and S2 and S3 and S4 and S5 and S6 and S7 and S8 and S9 and S10  
             and S11 and S12 and S13 and S14 and S15 Not OnMarket
    If CondL and condM THEN
    BUY 1 Contract AT Market
    Elsif CondS and CondT THEN
    SELLSHORT 1 Contract AT Market
    ENDIF
    set stop   pLoss   10
    set target pProfit 30

    Then the condition  where if the trigger candle exceeds 15 pips (an adjustable value)

    the bot will take a trade if the price pulls back to 50% or more of the next candle Only.

     

    Thank you for your support

    #175394 quote
    josward1
    Participant
    New
    here is a clear description of the strategy in case above isn’t clear 1 day timeframe: 50 sma > 90sma 90 sma > 200sma close > 50sma close > 90sma close > 200sma 4 hour timeframe: 50 sma > 90sma 90 sma > 200sma close > 50sma close > 90sma close > 200sma

    15 min timeframe

    50 sma > 90sma 90 sma > 200sma close crosses over ema3415m and 5515m and sma5015m (crosses all within same candle on closing basis) Buy 1-3 risk reward.   and the opposite for a sell.
Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.

Moving average cross over on multiple timeframes, 1-3 risk reward


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
josward1 @josward1 Participant
Summary

This topic contains 6 replies,
has 2 voices, and was last updated by josward1
4 years, 6 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 08/11/2021
Status: Active
Attachments: No files
Logo Logo
Loading...