Trailing setup doesn't work
Forums › ProRealTime English forum › ProOrder support › Trailing setup doesn't work
- This topic has 8 replies, 3 voices, and was last updated 8 years ago by algotrader.
-
-
01/15/2017 at 8:00 PM #21201
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?
12345678910IF not longonmarket and (c1 OR c2) THENBuy 2 CONTRACT AT MARKETSET STOP pTRAILING 0ENDIFLongPositionValue = (close - tradeprice(1))*abs(COUNTOFPOSITION)/pointsize*pointvalueIF longonmarket and LongPositionValue >= 100 THENSET STOP pTRAILING 60ENDIFThanks for the help.
A01/15/2017 at 8:42 PM #21207Hi 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
01/17/2017 at 8:54 AM #21412Hi 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.
🙁01/17/2017 at 9:25 AM #2141501/17/2017 at 3:53 PM #21473Hi Nicolas
- It runs with no errors.. so yes it works on backtest.
- No rejected orders.
- 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)
01/17/2017 at 4:14 PM #21481Did 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?
01/17/2017 at 11:28 PM #21520Hi 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?
1LongPositionValue = (close - tradeprice(1))*abs(COUNTOFPOSITION)/pointsize*pointvalueYou see, for SA40:
Pointsize is always1
.
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?
01/18/2017 at 9:32 AM #21529GRAPH 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:
12//floating profitfloatingprofit = (((close-positionprice)*pointvalue)*countofposition)/pipsize //actual trade gains01/20/2017 at 9:49 AM #21802 -
AuthorPosts
Find exclusive trading pro-tools on