MTF Strategy 2 hrs and 2 min

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #174726 quote
    efahmyefahmy
    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 =====

    #176287 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    I can’t spot anything wrong.

    I can only suggest that you set a higher SL, as it seems a bit too small.

    Check IG’s website to know what the minimum SL is, to prevent your strategy when run in demo/real (not when backtesting) from being stopped.

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

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

MTF Strategy 2 hrs and 2 min


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
efahmy @efahmy Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by robertogozzirobertogozzi
5 years, 1 month ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 08/05/2021
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...