Trailing stop function to take profit during retracement

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #138818 quote
    boonetboonet
    Participant
    Senior

    Firstly, I would like to thank everyone for creating such an amazing community.
    I need a little coding help with the trailing stop algo –

    Scenario: Buy Long

    Preconditions:

    • BUY long 1 contract
    • Using the Trailing STOP function from snippet library
    • TrailingStart set to 200 pips
    • Trailing Step set to 15 pips

    During trade:

    • Profit reaches 175 pips
    • Starts to retrace to 100 pips

    I want to:

    • Take profit @ 100 pips
    • Open another BUY long trade immediately.

     

    Similiar flow for short SELL

    Is it a profitable approach?

    If yes, can you help me code this or direct me to relevant documentation?

     

    Thanks in advance.

    #145492 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    This should do, but couldn’t test it, nor check syntax errors, if any:

    Once TriggerPips  = 175 * pipsize
    Once CloseTrigger = 100 * pipsize
    Once TPflag       = 0 //will be set to 1 when TP reaches 175 pips
    If not OnMarket then
       TPflag    = 0
        MyProfit = 0
    Endif
    If LongOnMarket then
       MyProfit = Close - PositionPrice
    Elsif ShortOnMarket then
       MyProfit = PositionPrice - close
    Endif
    If MyProfit >= TriggerPips Then
      TPflag = 1
    Endif
    If TPflag And MyProfit <= CloseTrigger Then
       TPflag    = 0
       MyProfit = 0
       NewSL   = 0
       If LongOnMarket Then
          Sell at Market
          Buy 1 Contract at Market
       Elsif ShortOnMarket Then
          Exitshort at Market
          Sellshort 1 contract at Market
       Endif
    Endif
    swedshare, boonet, Monochrome, Nicolas and Kovit thanked this post
    #145507 quote
    boonetboonet
    Participant
    Senior

    Thanks @robertogozzi, will test it and let you know how it goes.
    Cheers.

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 function to take profit during retracement


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
boonet @boonet Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by boonetboonet
6 years ago.

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