Trailing distance and start

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #180020 quote
    murre87murre87
    Participant
    Senior

    Help create following:

    TrailStart          = 0.1%          //0.1     Start trailing when 0,1% in profit
    Trailing distance   = 0.04%         //0.04    % distance from candleclose
    #180024 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    You can find one here https://www.prorealcode.com/topic/trailing-stop-and-breakeven-codes/#post-129187, but if you search the forum you can find more snippets.

    Look also at the snippet library suggested by Vonasi and regularly updated by GraHal https://docs.google.com/spreadsheets/d/1rgboqj7sVwsP9ZRhOduOefye48QMWC07jWVXCl-KJPU/edit#gid=0.

    #180032 quote
    murre87murre87
    Participant
    Senior

    Hi Roberto.

    I have searched and couldn’t find what I was searching for.

    Found how to start trail when 0.1% in profit, but cannot find how to keep the 0.04% distance from highest closed candle.

    #180036 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    What distance is it?

    #180037 quote
    murre87murre87
    Participant
    Senior

    For long

    0.04% distance from highest closed candle.

     

    For short

    0.04% distance from lowest closed candle.

    #180040 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Highest compared to what?

    #180041 quote
    murre87murre87
    Participant
    Senior

    Highest closed candle after trailing was started.

    Long: Start trailing when 0,1% in profit. Efter this sl moves (trails) with 0,04 % distance to highest price/bar/candle

     

    Short: Start trailing when 0,1% in profit. Efter this sl moves (trails) with 0,04 % distance to lowest price/bar/candle

    #180043 quote
    murre87murre87
    Participant
    Senior
    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    // Conditions to enter long positions
    indicator1 = ExponentialAverage[50](high)
    c1 = (low CROSSES OVER indicator1)
    
    Timeframe(4h)
    filter=RSI[14](close)
    timeframe(default)
    
    
    IF c1 AND filter<70 THEN
    BUY 1 CONTRACT AT MARKET
    SET STOP %LOSS 0.05
    ENDIF
    
    
    //Help with trail
    //TrailStart          = 0.1%          //0.1     Start trailing when 0,1% in profit
    //Trailing distance   = 0.04%         //0.04    stoploss resets and is placed 0,04 % distance to highest price/bar/candle
    
    //Long: Start trailing when 0,1% in profit. Efter this sl moves (trails) with 0,04 % distance to highest price/bar/candle
    //Short: Start trailing when 0,1% in profit. Efter this sl moves (trails) with 0,04 % distance to lowest price/bar/candle
    #180058 quote
    murre87murre87
    Participant
    Senior

    maybe it is easier to explain with picture

    sl.jpg sl.jpg
    #180114 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    What are the rules why both the green and red rectangle are drawn there?

    Which is the highest candle you want to refer to?

    0.04% needs to be calculated from which point?   up to… ?

    #180119 quote
    murre87murre87
    Participant
    Senior

    This might be better?

    TP: set up 0.1% from entry
    Work with SL: If the trend continues and the trade exceeds 0.06%, SL is moved up / down by 0.04% for at least the breakeven.
    If the trend continues and breaks TP 0.1, TP is moved 0.1%, so new TP becomes 0.2% from original entry and SL is moved up to 0.1%.
    After that, work with trailing SL 0.1% up / down until it is broken and then you take a profit.
    Clarification: only candle close so that you do not let go of wicks.
    #180209 quote
    murre87murre87
    Participant
    Senior

    Do u think this is possible to code Roberto 🙂

    #180211 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Yes, I’ll make it asap.

    #180215 quote
    murre87murre87
    Participant
    Senior

    U are a master!

    #180226 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    There you go:

    IF Not OnMarket THEN
       MyStop = 0
       Entry  = 0
    ENDIF
    
    IF close crosses over average[100,0](close) AND Not OnMarket THEN
       BUY 1 CONTRACT AT MARKET
       SET STOP %LOSS 1.0
       Entry = close
    ENDIF
     
    TP               = 1.0 / 100 //1.0%
    TrailStart       = 0.6 / 100 //0.6%
    Trailingdistance = 0.2 / 100 //0.2%
     
    IF OnMarket AND Not OnMarket[1] THEN
       Entry = TradePrice
    ENDIF
    
    IF OnMarket THEN
       IF MyStop = 0 THEN
          IF close >= (Entry + (Entry * TrailStart)) THEN
             MyStop = Entry + (Entry * Trailingdistance)
          ENDIF
       ELSE
          IF close >= (MyStop + (Entry * TP)) THEN
             MyStop = MyStop + (Entry * TP)
          ENDIF
       ENDIF
       IF MyStop > 0 THEN
          SELL AT MyStop STOP
       ENDIF
    ENDIF
    graphonprice Entry
    graphonprice Entry + (Entry * TP) coloured(0,0,255,255)
    graphonprice MyStop               coloured(255,0,0,255)

    I tested it on DAX, 15min.
    I changed percentages a little bit to ber able to test it better.

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

Trailing distance and start


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
murre87 @murre87 Participant
Summary

This topic contains 15 replies,
has 2 voices, and was last updated by murre87murre87
4 years, 11 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 10/20/2021
Status: Active
Attachments: 1 files
ProRealCode ProRealCode
Loading...