Trailing stop goes backwards

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #152303 quote
    PabloRodPabloRod
    Participant
    New

    Hello,

    I have this problem with my ‘algo’ and it is driving me crazy. I see in Demo and in real that very often the trailing stop goes backwards, and it is not supposed to do that. Once a new profit has been achieved it must stay at that position. My TS is defined as a moving trailing stop, just hidden behind the EMA(9) and moving along the price, in long and short trades.

    It moves back even after a candle has closed, discarded because the average price position in the current candle changes.

    To simplify the code:

    If TS
    ts1 = CLOSE – EMA9[0]
    SET STOP TRAILING ts1
    endif

    Is there any axplanation for this behavior?? I can change instead for a dynamic stop loss, but the trailing is the right tool for this purpose.

    Thanks in advance

    ———————

    my original code equivalent is this:

    if TS
    trailmargin = EMA9[0]*ts1MMA1/100
    ts1 = CLOSE – (MMA1[0]- trailmargin)
    SET STOP TRAILING TS1
    endif

    #152311 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Always use the ‘Insert PRT Code’ button when putting code in your posts to make it easier for others to read. Thank you 🙂

    Change your line to:

    ts1 = max(ts1,CLOSE – (MMA1[0]- trailmargin))

    so that it can only raise, never fall!

    #152387 quote
    PabloRodPabloRod
    Participant
    New

    Hello,

    Yes, now it is working right. The only (minor) issue comes when it opens a new candle. For an instant the calculation does not have a reference and it can go up or down with no sense, it only takes 0’1 sec to get a new price and also sometimes it is slightly below the previous TS, I think we cannot avoid this situation, only happens with a new candle.

    As a sequence when it should always go upwards in Nasdaq, these are the numbers: 12.392 – 12.396 – 12.402 – (!) 12.399 – 12.403 – 12.407 – (!) 12.405 – 12.408 – …

    Thanks for your help

Viewing 3 posts - 1 through 3 (of 3 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 stop goes backwards


Platform Support: Charts, Data & Broker Setup

New Reply
Author
author-avatar
PabloRod @pablorod Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by PabloRodPabloRod
5 years, 10 months ago.

Topic Details
Forum: Platform Support: Charts, Data & Broker Setup
Language: English
Started: 12/01/2020
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...