Trailing setup doesn't work

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #21201 quote
    algotrader
    Participant
    Average

    Hello
    I’m trying to code a Trailing Stop the starts only if the strategy is in profit.

    I’ve even requested help from PRT support team.

    The improved code that they suggested does not work.
    What I mean by that is, the Trailing Stop is created, but it’s not moving at all.
    It just stuck there like a Stop Loss.

    The following is the code for executing the Trailing Stop.

    Can you spot the problem?

     

     

    IF not longonmarket and (c1 OR c2) THEN
    Buy 2 CONTRACT AT MARKET
    SET STOP pTRAILING 0
    ENDIF
    
    LongPositionValue = (close - tradeprice(1))*abs(COUNTOFPOSITION)/pointsize*pointvalue
    
    IF  longonmarket and LongPositionValue >= 100 THEN
    SET STOP pTRAILING 60
    ENDIF

     

     

    Thanks for the help.
    A

    Trail-Stop-not-moving-1.jpg Trail-Stop-not-moving-1.jpg Trail-Stop-not-moving-2.jpg Trail-Stop-not-moving-2.jpg
    #21207 quote
    Elsborgtrading
    Participant
    Veteran

    Hi Algotrader.

    There are a few strategies on the site that does what you want.

    it not an easy task to do the trailing stop

    Perhaps start here in the blog to see if you can use it

    Cheers Kasper

    #21412 quote
    algotrader
    Participant
    Average

    Hi Elsborgtrading
    Thanks, I am familiar with this post..

    There are 2 problems here
    1. This snippets supply by PRT support!! This is their suggestion.

    And it doesn’t work!

    If the creator of the software gives you a solution that doesn’t work..
    What else left out there??

    I find it disturbing. Wouldn’t you!?

     

    2. On that post, I am referring to ‘Risk related trailing stop’
    Unfortunately, it’s very basic, no details.
    Cannot really understand it.
    🙁

    #21415 quote
    Nicolas
    Keymaster
    Master
    1. Does it works on backtest?
    2. Are there some rejected orders or any error messages under the orders list window in the platform (CTRL+O)?
    3. What is average spread on this instrument?

    Thanks 🙂

    #21473 quote
    algotrader
    Participant
    Average

    Hi Nicolas

    1. It runs with no errors.. so yes it works on backtest.
    2. No rejected orders.
    3. South Africa 40 Cash. Spread is 16.

    As you can see on the attached images,
    The strategy execute the stop loss and the trailing.
    The price moved over 800 point in the favor direction,
    But the trailing did not move at all.

    (IG user with PRT V10.2)

    #21481 quote
    Nicolas
    Keymaster
    Master

    Did you GRAPH “longpositionvalue” on backtest if the calculation is correctly made?

    If spread is 16 points, it’s possible that the stoploss can’t move because the new calculated stoploss level is somewhere in the spread (seen this problem already with SAF index, that’s why I asked).

    It’s always painful to debug the internal trailing function of proorder language, I never use it in my own development and for customers, if you already known the posts I made in the blog, why don’t you use these snippets?

    #21520 quote
    algotrader
    Participant
    Average

    Hi Nicolas

    A. I never thought about that, Will give it a try. (Does GRAPH works on the V10.2?)
    B. So the solution here is to add the spread into the calculation? so if my minimum stop loss is at 60,
    so the new one should be 60+16=76?
    C. So I’m not the only one who struggle with implementing the trailing stop into a strategy, Haha, I’m in good hands..
    I do check your coding, the thing is you mainly code for FX so I need to tweak and change parameters to be compatible for SA40
    SA40 is very different. I have manage to run your breakeven code  successfully.

     

    Q: Would you say the code for calculating the strategy value is right?

    LongPositionValue = (close - tradeprice(1))*abs(COUNTOFPOSITION)/pointsize*pointvalue

    You see, for SA40:
    Pointsize is always 1`.
    `

    Pointvalue is always 2 (The micro contract is 2 rand per point).
    abs(CountOfPosition), I guess PRT puts the ‘abs’ here because if you go SHORT it’ll be -2.

    Other issue here is the TradePrice(1)
    The way I understand it, it refers to the previous order.
    However, I am always trading one order only, so as there is no previous trade,
    there is only the current trade. I guess I should use TradePrice(0)

    Formula will be calculated like this:
    LongPositionValue = (close – tradeprice(0))*abs(COUNTOFPOSITION)/pointsize*pointvalue
    LongPositionValue = (46080 – 46000)*abs(2)/1*2 = 80
    But that is wrong!
    it should be 320
    Seams like PRT support have a mistake here, it should be: (46080 – 46000)*abs(2)*1*2  = 320
    Is there a better way to calculate ‘PositionValue’?

    Either way, as you can see from the attached images, the strategy went far and beyond that
    And yet, it didn’t move the trailing stop in the favor direction at all.

    The main problem still lies in the ‘Trailing Stop’ coding more then anything else..

    What do you think?

    #21529 quote
    Nicolas
    Keymaster
    Master

    GRAPH is the only way to debug your code, it works only in backtest and yes it is compatible with 10.2 (it was introduced in 10.2). You may have already read my blog article about the GRAPH function.

    You should begin to debug the LongPositionValue state with GRAPH, before making any conclusion. Trust me, this is where to start 🙂

    I use this calculation myself, to find the floating profit:

    //floating profit
    floatingprofit = (((close-positionprice)*pointvalue)*countofposition)/pipsize //actual trade gains
    #21802 quote
    algotrader
    Participant
    Average

    Thank you, Nicolas

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.

Trailing setup doesn't work


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
algotrader @algotrader Participant
Summary

This topic contains 8 replies,
has 3 voices, and was last updated by algotrader
9 years, 1 month ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 01/15/2017
Status: Active
Attachments: No files
Logo Logo
Loading...