Filter for downtrend

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #158882 quote
    Oliviertrader2020
    Participant
    Average

    Hello, can someone help me create a filter :
    – which starts when a condition appears
    – which ends when another condition occurs.

    This filter will be included in a robot and will be used to take sales on a lower TF.

    The filter starts when :
    – the SMA7 > SMA20 AND the SMA7 turns down,

    The filter disappears when :
    – the SMA7 turns upwards

    I tried to create a code to accept trades only between these conditions but it doesn’t seem to work the way I want it to.

    Using graph it only shows the first condition and I can’t create an indicator that could color the background (with backgroundcolor) so I don’t realize where the error comes from.

    Maybe you should use a While loop but I haven’t found the solution.
    Here is the code:

    defparam cumulateorders = false
    
    
    SMA7 = Average[7](close)
    SMA20 = Average[20](close
    
    timeframe(daily)
    
    
    // ***************** FILTER START *******
    
    //  SMA7 > SMA20 
    C1 = (SMA7 > SMA20) 
    
    //  Downtrend start
    C2 = (SMA7[1] > SMA7[2]) AND (SMA7[1] > SMA7)
    
    
    // ***************** END OF FILTER *******
    
    //  End of Downtrendown
    C3 = (SMA7[1] < SMA7[2]) AND (SMA7[1] < SMA7)
    
    // ***************** 
    
    FILTERSTART = C1 AND C2
    
    ENDofFILTER = C3
    
    ONCE TradeOn = 0
    
    
    IF FILTERSTART AND Not OnMarket THEN
    TRADEON = 1
    Endif
    
    IF (TradeOn = 1) AND ENDofFILTER THEN
    TradeON = 0
    ENDIF
    
    
    timeframe(default)
    
    // Engulfing
    c4 = high>high[1] and close < low[1]
    
    ConditionsSell =  (TradeOn = 1) AND C4
    
    IF NOT ShortOnMarket AND ConditionsSell  THEN
    SELLSHORT 1 CONTRACTS AT MARKET
    ENDIF
    
    SET TARGET pPROFIT 50
    SET STOP pLOSS 20
    Filter-SMA7_SMA20.png Filter-SMA7_SMA20.png
Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.

Filter for downtrend


ProOrder: Automated Strategies & Backtesting

New Reply
Summary

This topic contains 1 voice and has 0 replies.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 01/22/2021
Status: Active
Attachments: 1 files
Logo Logo
Loading...