Trailing Take Profit Linked to Equity

Forums ProRealTime English forum ProOrder support Trailing Take Profit Linked to Equity

Viewing 8 posts - 1 through 8 (of 8 total)
  • #237580

    Hello Team,

    I’m new to (PRT) and have been thoroughly enjoying learning and improving my skills on the platform.

    I’ve written a code for a strategy but would greatly appreciate your support and advice. My goal is to implement a trailing take profit that is tied to my equity, specifically based on the initial capital used to enter a position. However, as I am new to coding in PRT, I may have used incorrect keywords or syntax.

    What I am trying to achieve is to secure the gains made while in the market by establishing a trailing take profit system that locks in profits at specified increments (e.g., secure profits every $5,000). The idea is that as my profits increase, the trailing stop would adjust accordingly and ensure that profits are locked in and the position remains open. The position should only be exited when the profit falls below the trailing take profit level.

     

    Thank you for your assistance

    #237658

    Anyone can advise in this regards please

     

    Thank you

    #237665

    PositionPerf is NOT the current gains, it’s a multiplier to be applied to PositionPrice (the average opening price, same as the opening price when not accumulating positions),  so that PositionPrice * PositionPerf  is the base for the current gain (loss, if negative), but it must be additionally adjusted according to the value of each pip and to the size of the position, so that the complete formula is MyGain = PositionPrice * POSITIONPERF * PipValue * abs(CountOfPosition).

    This the amended code (I also changed several lines and got rid of some of them):

    Im not pretty sure it is exactly what you want, please test it and give me some feedback.

     

    1 user thanked author for this post.
    #237736

    Thanks Rbertogozzi for your feedback

    Kindly, I need some clarification before test it,  dose the (Pips = Trailingamount /PipValue/abs(CountOfPosition) work to ensure that profits are locked in and the position remains open?

    My idea is as long as the direction moving to my favor it secure the new profits and move to next trailing amount point. What I want is the position only be exited when the profit falls below the trailing take profit level which suppose to be updated each time profit increase by (5000$) .  The idea is similar to use dynamic take profit strategy but linked to amount of my equity instead of points or %.

     

    Correct me if I’m wrong please. I think should be  (Equity < Equitytrailing) in order to exit the position.

    Thanks a lot

    #237762

    Kindly, I need some clarification before test it, dose the (Pips = Trailingamount /PipValue/abs(CountOfPosition) work to ensure that profits are locked in and the position remains open?

    No, actually it converts the money into pips, because to me it seems to work better.

    Correct me if I’m wrong please. I think should be (Equity < Equitytrailing) in order to exit the position.

    When exactly do you want to exit?

     

     

    #237797

    Hi Rberto,

    The code is good so far but the result of testing the above code is , it give me a fixed target profit , while I intend to implement a dynamic one which secure the profit without exit the position and continue moving and exit the position only when profit drop below  trailing amount. In the current code the position exited through take profit when reach my trailing amount (after 250 points which is (20$ *250=5000$ in NASDAQ).

    I  tried to implement this code to get a dynamic take profit , but it doesn’t work well.

    // Trailing take profit
    IF ONMARKET Then
    Pips = Trailingamount / PipValue / abs(CountOfPosition)
    Equity = Capital + (PositionPrice * POSITIONPERF * PipValue * abs(CountOfPosition))
    if Equity – Pips > Pips THEN
    Equitytrailing = Equitytrailing + Pips
    ENDIF
    // Set target price based on trailing equity
    Set TARGET PRICE Equitytrailing
    ENDIF

    Any idea or enhancement?

     

    Thanks

    #237869

    This versions both seem to work as you expect.

    This is version 1  (normal, exiting as soon as the gain drops below equitytrailing:

    Version 2 is almost the same, I only changed line 25 to make sure profits never drops below 0, so that your trades will always be wins (but DrawDown increases and trades last much longer, so that you will incur in higher rollover):

     

     

     

    #237928

    Thank you, Roberto, for your outstanding efforts and support. I tested the code, and it works well. Here’s my feedback for potential users:

    The code is particularly effective in short time frames (1 minute), as it relies on the candlestick close for exiting positions. For instance, with an initial trailing amount of $1,500, the equity trailing activates when gains exceed this threshold, moving to $3,000 next. If current gains reach $3,700, Next step then becomes $4,500. However, if the price begins to dip below $3,000, the position won’t exit until the current candlestick closes, which could see gains drop to $2,000 or more. Therefore, quicker exits in small time frames could enhance performance significantly.

    If it will exit the position in the exact time when it touches the equity trailing which is (3000$) will be more safe

    Thanks once again, Roberto!

    2 users thanked author for this post.
Viewing 8 posts - 1 through 8 (of 8 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login