No trade in a range

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #86341 quote
    fxbravofxbravo
    Participant
    Average

    Good morning gentlemen,

     

    I have an issue in my code.

    Here what I want the code do: when a stop loss is touched, a variable is set to 1 and a “range” is set too (+X and -X points at the Tradeprice(1) )

    Here, visually:

    -----Range Up (10020)
    .
    .
    - Tradeprice (10000)
    .
    .
    -----Range Down (9980)

    In ordrer to do that, I code this:

    // ForbidddenTradingRange
    
    NoTrade = 0
    
    if notrade = 1 then
    RangeNoTradeUp = Tradeprice(1)+20
    endif
    
    if notrade = 1 then
    RangeNoTradeDown = Tradeprice(1)-20
    endif
    
    
    // Long
    indicator1, ignored, ignored = CALL "Unicorn Color"(close)
    indicator2 = Average[30](close)
    c1 = (indicator1 CROSSES OVER indicator2)
    
    
    IF c1 and notrade=0 AND timeEnterBefore AND timeEnterAfter THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    
    // Close Long
    indicator3, ignored, ignored = CALL "Unicorn Color"(close)
    indicator4 = Average[30](close)
    c2 = (indicator3 CROSSES UNDER indicator4)
    
    IF c2 THEN
    SELL AT MARKET
    notrade=1
    ENDIF
    
    if close>RangeNoTradeUp or close<RangeNoTradeDown then
    NoTrade=0
    endif
    
    // Short
    indicator5, ignored, ignored = CALL "Unicorn Color"(close)
    indicator6 = Average[30](close)
    c3 = (indicator5 CROSSES UNDER indicator6)
    
    IF c3 and notrade=0 AND timeEnterBefore AND timeEnterAfter THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    
    // Close Short
    indicator7, ignored, ignored = CALL "Unicorn Color"(close)
    indicator8 = Average[30](close)
    c4 = (indicator7 CROSSES OVER indicator8)
    
    IF c4 THEN
    EXITSHORT AT MARKET
    notrade=1
    ENDIF
    
    if close>RangeNoTradeUp or close<RangeNoTradeDown then
    NoTrade=0
    endif 
    
    
    
    // SL and TP
    SET STOP pLOSS 20
    SET TARGET pPROFIT 20
    

     

    When I backtest it, some trade don’t respect the rule “Forbidden Traading Range”.

     

    I  think I miss something, but I don’t know what 😉

     

    Thank you for your help.

     

    I wish you a good day.

    #86350 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Start line 3 with ONCE, otherwise it will ALWAYS be false!

    #86358 quote
    VonasiVonasi
    Moderator
    Master

    Start line 3 with ONCE, otherwise it will ALWAYS be false!

    …or just delete line 3 as the value of NoTrade will always start at zero!

    #86375 quote
    fxbravofxbravo
    Participant
    Average

    Thanks you both!

     

    Have a good day 😉

Viewing 4 posts - 1 through 4 (of 4 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

No trade in a range


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
fxbravo @fxbravo Participant
Summary

This topic contains 3 replies,
has 3 voices, and was last updated by fxbravofxbravo
7 years, 11 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 12/05/2018
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...