MTF Strategy 2 hrs and 2 min

Forums ProRealTime English forum ProOrder support MTF Strategy 2 hrs and 2 min

Viewing 14 posts - 1 through 14 (of 14 total)
  • #174730

    I have created this strategy based on 2 time frames MACD on 2 hrs and Supertrend on 2 mins, its not working with me, I believe it needs to be corrected, could you please help in adjusting it.

    // VARIABLES

    SL = 4

    stepfactor1 = 1

    stepfactor2 = 0.25

    RR = 2

    timeframe(2 hour, updateonclose)

    MCD = MACD[12,26,9](close)

    timeframe(2 minutes)

    DM = DEMA[14](close)

    PST = Supertrend[2,10]

    // Conditions to enter long positions

    IF MCD > 0 AND DM CROSSES OVER PST THEN

    BUY 1 CONTRACTS AT MARKET

    SET STOP   pLOSS   SL    //5

    TP = RR * SL

    SET TARGET pPROFIT TP   //10

    ENDIF

     

    // Conditions to exit long positions

    If DM CROSSES UNDER PST THEN

    SELL AT MARKET

    ENDIF

     

    // Conditions to enter short positions

    IF MCD < 0 AND DM CROSSES UNDER PST THEN

    SELLSHORT 1 CONTRACTS AT MARKET

    SET STOP   pLOSS   SL    //5

    TP = RR * SL

    SET TARGET pPROFIT TP   //10

    ENDIF

     

    // Conditions to exit short positions

    IF DM  CROSSES OVER PST THEN

    EXITSHORT AT MARKET

    ENDIF

     

    // Stops and targets : Enter your protection stops and profit targets here

    //====== Trailing Stop mechanism – start =====

     

     

    trailingstart = (stepfactor1 * SL ) / pointsize

    trailingstep = (stepfactor2 * SL ) / pointsize

     

    //resetting variables when no trades are on market

    if not onmarket then

    priceexit = 0

    endif

     

    //case LONG order

    if longonmarket then

     

    //first move (breakeven)

    IF priceexit=0 AND close-tradeprice(1) >= trailingstart*pointsize THEN

     

    priceexit = tradeprice(1) + trailingstep*pointsize

     

    ENDIF

    //next moves

    IF priceexit>0 THEN

    P2 = close-priceexit >= trailingstart*pointsize

     

    IF P2 THEN

    priceexit = priceexit + trailingstep*pointsize

    ENDIF

     

    ENDIF

    endif

     

    //case SHORT order

    if shortonmarket then

     

    //first move (breakeven)

    IF priceexit=0 AND tradeprice(1)-close >= trailingstart*pointsize THEN

     

    priceexit = tradeprice(1) – trailingstep*pointsize

     

    ENDIF

    //next moves

    IF priceexit>0 THEN

     

    P2 = priceexit-close >= trailingstart*pointsize

     

    IF P2 THEN

    priceexit = priceexit – trailingstep*pointsize

    ENDIF

     

    ENDIF

     

    endif

     

    //exit on trailing stop price levels

    if onmarket and priceexit>0 then

    EXITSHORT AT priceexit STOP

    SELL AT priceexit STOP

    endif

    //====== Trailing Stop mechanism – end =====

    #174731

    It works / runs  okay for me on backtest.

    Are you running it on Timeframe of 2 minutes or less?

    #174736

    You need to optimise your values for SL  … 4 points SL will mean it exits as soon as it entered on most trades.

    #174741

    It’s working for me, as well.

    What’s the issue you have detected?

    If you post instrument, TF, date and time of one or more incorrect trades, we might be of some help.

     

    1 user thanked author for this post.
    #174748

    I had a play with it while waiting for a trade to come right  … attached might get you going further on it?

     

    #174751

    I have tested it in real time and real money, it takes the conditions of the 2 mins only and ignore the conditions of the 2 hours?!!!

    the SL = 4 points not 4 ticks

    #174752

    This Code is for US500 not for DJ

    #174758

    For me conditions work fine, as requested (at least for the couple of entries I checked).

     

    #174771

    ignore the conditions of the 2 hours?!!!

    In your code below …

      • Conditions showing at the END of the 2 hour will be followed.
      • Conditions showing DURING the 2 hour bar will be ignored.

    Does above help at all?

     

     

    #174774

    Yes, UpdateOnClose only sets conditions when a bar closes.

    Use default, or nothing, to update conditions every 2 minutes (or any default TF you may want to use),

     

    1 user thanked author for this post.
    #174799

    It is working now, I added another condition to the 2 min which is the DRSI, but still the trailing stop loss system is not working don’t know why??

    ==============================================================================================================

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    // VARIABLES
    SL = 2.6
    stepfactor1 = 1
    stepfactor2 = 0.25
    RR = 2
    timeframe(2 hour, updateonclose)
    MCD = MACD[12,26,9](close)
    timeframe(2 minutes)
    myPRCDynamicRSI, myPRCDynamicRSI2, myPRCDynamicRSI3, myPRCDynamicRSI4 = CALL “PRC_DynamicRSI”[0.1, 0.1, 14, 60]
    DM = DEMA[14](close)
    PST = Supertrend[2,10]
    // Conditions to enter long positions
    IF MCD > 0 AND DM > PST AND myPRCDynamicRSI > myPRCDynamicRSI2 THEN
    BUY 1 CONTRACTS AT MARKET
    SET STOP pLOSS SL //5
    TP = RR * SL
    SET TARGET pPROFIT TP //10
    ENDIF

    // Conditions to exit long positions
    If DM Crosses under PST THEN
    SELL AT MARKET
    ENDIF

    // Conditions to enter short positions
    IF MCD < 0 AND DM < PST AND myPRCDynamicRSI < myPRCDynamicRSI2 THEN
    SELLSHORT 1 CONTRACTS AT MARKET
    SET STOP pLOSS SL //5
    TP = RR * SL
    SET TARGET pPROFIT TP //10
    ENDIF

    // Conditions to exit short positions
    IF DM CROSSES OVER PST THEN
    EXITSHORT AT MARKET
    ENDIF

    // Stops and targets: Enter your protection stops and profit targets here
    //====== Trailing Stop mechanism – start =====

    trailingstart = (stepfactor1 * SL ) / pointsize
    trailingstep = (stepfactor2 * SL ) / pointsize

    //resetting variables when no trades are on market
    if not onmarket then
    priceexit = 0
    endif

    //case LONG order
    if longonmarket then

    //first move (breakeven)
    IF priceexit=0 AND close-tradeprice(1) >= trailingstart*pointsize THEN

    priceexit = tradeprice(1) + trailingstep*pointsize

    ENDIF
    //next moves
    IF priceexit>0 THEN
    P2 = close-priceexit >= trailingstart*pointsize

    IF P2 THEN
    priceexit = priceexit + trailingstep*pointsize
    ENDIF

    ENDIF
    endif

    //case SHORT order
    if shortonmarket then

    //first move (breakeven)
    IF priceexit=0 AND tradeprice(1)-close >= trailingstart*pointsize THEN

    priceexit = tradeprice(1) – trailingstep*pointsize

    ENDIF
    //next moves
    IF priceexit>0 THEN

    P2 = priceexit-close >= trailingstart*pointsize

    IF P2 THEN
    priceexit = priceexit – trailingstep*pointsize
    ENDIF

    ENDIF

    endif

    //exit on trailing stop price levels
    if onmarket and priceexit>0 then
    EXITSHORT AT priceexit STOP
    SELL AT priceexit STOP
    endif
    //====== Trailing Stop mechanism – end =====

    #174805

    Remove / PointSize from these lines:

    I fear your system will be always stopped from autotrading, due to such  narrow values for SL, as they seem to be less than those required by IG.

     

    #174810

    Thanks mate, I have removed it, will run the strategy and see how it works.

    this SL is for US500 (S&P 500 cash market) 2.6 points, if you still see its very low, could you please suggest the best SL ?

    #174811

    You should optimize it, to fond the best possible one.

     

Viewing 14 posts - 1 through 14 (of 14 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login