Magic Trend strategy

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #177707 quote
    murre87murre87
    Participant
    Senior

    Help Coding strategy

    //==========================================================================================================
    DEFPARAM CUMULATEORDERS = false
    DEFPARAM PRELOADBARS = 10000
    
    cciP = 20
    atrP = 14
    atrM = 1
    smaP = 5
    cciP   = max(1,min(999,cciP))
    atrP   = max(1,min(999,atrP))
    atrM   = max(0.0000001,min(999,atrM))
    smaP   = max(1,min(999,smaP))
    //
    IF BarIndex > max(cciP,atrP) THEN
    lastCCI = thisCCI
    thisCCI = CCI[cciP](typicalPrice)
    myATR   = AverageTrueRange[atrP](close)
    //
    temp1   = myATR * atrM
    upT     = low  - temp1
    downT   = high + temp1
    //
    temp2   = Average[smaP,0](myATR) * atrM
    buffDN  = high + temp2
    buffUP  = low  - temp2
    //
    IF (thisCCI >= 0) AND (lastCCI  < 0) THEN
    buffUP = buffDN[1]
    ENDIF
    IF (thisCCI <= 0) AND (lastCCI  > 0) THEN
    buffDN = buffUP[1]
    ENDIF
    IF (thisCCI >= 0) THEN
    IF (buffUP < buffUP[1]) THEN
    buffUP = buffUP[1]
    ENDIF
    ELSIF (thisCCI <= 0) THEN
    IF (buffDN > buffDN[1]) THEN
    buffDN = buffDN[1]
    ENDIF
    ENDIF
    IF thisCCI >= 0 THEN
    MagicTrend = buffUP
    ELSIF thisCCI <= 0 THEN
    MagicTrend = buffDN
    ENDIF
    ELSE
    thisCCI    = 0
    lastCCI    = 0
    myATR      = 0
    buffUP     = 0
    buffDN     = 0
    buffDN     = 0
    buffUP     = 0
    MagicTrend = 0
    ENDIF
    
    
    // Conditions to enter long positions
    IF buffUP=1 THEN
    BUY 1 CONTRACTS AT MARKET
    SET STOP %LOSS 1 //sl=1
    set target %profit 2 //TP=2
    ENDIF
    
    // Conditions to exit long positions
    If buffDN=1 THEN
    SELL AT MARKET
    SET STOP %LOSS 1 //sl=1
    set target %profit 2 //TP=2
    ENDIF

    Whats Wrong with this code?

    #177711 quote
    GraHalGraHal
    Participant
    Master

    Try below in place of your Lines 59 to 71 above …

    Lng = Close crosses over buffUp
    Sht = Close crosses under buffDn
     
    // Conditions to enter long positions
    IF Lng THEN
    BUY 1 CONTRACTS AT MARKET
    SET STOP %LOSS 1 //sl=1
    set target %profit 2 //TP=2
    ENDIF
     
    // Conditions to exit long positions
    If Sht THEN
    SELLShort AT MARKET
    SET STOP %LOSS 1 //sl=1
    set target %profit 2 //TP=2
    ENDIF
    murre87 thanked this post
    #206854 quote
    killerplatuzekillerplatuze
    Participant
    New

    Hi,

    i wont buy or sell by a crossover, only if the trend is change.

    If the trend goes down the i want have a sell signal, if the trend goes up i want have a buy signal.

    If the color from the trend switch from green to red sell, from red to green buy.

    I have no idea how to code this.

    thx for help.

    #206903 quote
    RazzRazz
    Participant
    Master

    Hello Killerplautze is just a simple code maybe it will help šŸ˜‰

     

    // Festlegen der Code-Parameter
    DEFPARAM CumulateOrders = False // Kumulieren von Positionen deaktiviert
    
    myMagicTrend = CALL "Magic Trend custom"[20, 9, 2, 5]
    Gruen = myMagicTrend > myMagicTrend[1]
    Rot = myMagicTrend < myMagicTrend[1]
    
    // Verhindert das Trading an bestimmten Wochentagen
    daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
    
    // Bedingungen zum Einstieg in Long-Positionen
    
    IF Gruen AND not daysForbiddenEntry THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    
    // Bedingungen zum Ausstieg von Long-Positionen
    
    IF Rot THEN
    SELL AT MARKET
    ENDIF
    
    // Bedingungen zum Einstieg in Short-Positionen
    
    IF Rot AND not daysForbiddenEntry THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    
    // Bedingungen zum Ausstieg aus Short-Positionen
    
    IF gruen THEN
    EXITSHORT AT MARKET
    ENDIF
    killerplatuze thanked this post
    #207193 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    i wont buy or sell by a crossover, only if the trend is change. If the trend goes down the i want have a sell signal, if the trend goes up i want have a buy signal. If the color from the trend switch from green to red sell, from red to green buy

    This IS exactly what a crossover does, as @GraHal coded.
    The code posted by @Razz , only checks when the Magic Trend rises or falls, not when a crossover occurs.

    GraHal thanked this post
Viewing 5 posts - 1 through 5 (of 5 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

Magic Trend strategy


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
murre87 @murre87 Participant
Summary

This topic contains 4 replies,
has 5 voices, and was last updated by robertogozzirobertogozzi
3 years, 8 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 09/16/2021
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...