MTF Strategy 2 hrs and 2 min

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #174730 quote
    efahmy
    Participant
    Average

    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 quote
    GraHal
    Participant
    Master

    It works / runs  okay for me on backtest.

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

    #174736 quote
    GraHal
    Participant
    Master

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

    #174741 quote
    robertogozzi
    Moderator
    Master

    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.

    GraHal thanked this post
    #174748 quote
    GraHal
    Participant
    Master

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

    Efa.jpg Efa.jpg Efa-MACD-DEMA-ST-DJI-M1-v1.itf
    #174751 quote
    efahmy
    Participant
    Average

    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 quote
    efahmy
    Participant
    Average

    This Code is for US500 not for DJ

    #174758 quote
    robertogozzi
    Moderator
    Master

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

    #174771 quote
    GraHal
    Participant
    Master

    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?

    timeframe(2 hour, updateonclose)
    
    MCD = MACD[12,26,9](close)
    #174774 quote
    robertogozzi
    Moderator
    Master

    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),

    GraHal thanked this post
    #174799 quote
    efahmy
    Participant
    Average

    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 quote
    robertogozzi
    Moderator
    Master

    Remove / PointSize from these lines:

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

    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 quote
    efahmy
    Participant
    Average

    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 quote
    robertogozzi
    Moderator
    Master

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

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

MTF Strategy 2 hrs and 2 min


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
efahmy @efahmy Participant
Summary

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

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