Strategy over buying (& selling) when testing in demo
Forums › ProRealTime English forum › ProOrder support › Strategy over buying (& selling) when testing in demo
- This topic has 9 replies, 3 voices, and was last updated 7 years ago by GraHal.
-
-
12/08/2016 at 8:35 PM #18096
Hi guys
I’ve been trying to put together a “dynamic” exit strategy which can be applied across strategies and products. I’ve been helped by a few of you so far (Nicolas on the calculation of the Value Areas and Henry on the difficult bit of the actual exit). The discussion about the exit is in the following link so I won’t repeat it here:
http://www.prorealcode.com/topic/how-to-code-target-and-stop/
The exit is almost there although I’m still in discussion with PRT as I’ve spotted a few anomalies which we’re trying to rectify. I’ve just been testing it in demo and encountered a problem with it over buying (and on another occasion over selling). It seems to happen when there is a partially executed entry. I’ve looked at the order list and clicked on the order status history.
I’ve pasted below the order tickets. Long entry 3 Dax:
Date Side Name Status Qty Qty exec Price 17:15:01 Buy DAX30 Only1216 Transmitted 3 17:15:01 Buy DAX30 Only1216 Pending 3 17:15:01 Buy DAX30 Only1216 Partially executed 3 2 11,185.50 17:15:01 Buy DAX30 Only1216 Executed 3 1 11,186.00 As a separate order (or ticket) is the following:
Date Side Name Status Qty Qty exec Price 17:15:01 Buy DAX30 Only1216 Transmitted 2 17:15:01 Buy DAX30 Only1216 Pending 2 17:15:01 Buy DAX30 Only1216 Executed 2 2 11,185.50 The result is that I buy 3 lots as I wanted, but then also an additional 2 lots = net position of 5. However the extra 2 lots are “naked” and unwanted (i.e. they do not fit with the exit targets and are not covered with the stops).
A similar thing happened previously on a sell order however in this instance the system partially executed 1 lot out of three to begin, and then over bought by 1 lot so the position was short 4.
I’m pasting the code below. The entry strategy sucks and doesn’t work. I’m not interested in this at the moment. As I said I’m just trying to get the exit sorted into a transferable “product” which can then be used by myself and anyone as they want.
Have any of you come across a similar problem / can you see where I’m going wrong? As always, any help much appreciated.
Thanks
Jon
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657// Excluding around Brexit referendum AND NFPIF ((Year = 16) AND (Month = 6) AND (Day = 20 OR Day = 21 OR Day = 22 OR Day = 23 OR Day = 24 OR Day = 27 OR Day = 28 OR Day = 29 OR Day = 30)) OR (Day<8 AND DayOfWeek=5) THENTradingDay = 0ELSETradingDay = 1ENDIF// Conditions to enter long positionsc1 = (close > open)c2 = (TradingDay = 1)//Caluculation of Value Areasmean = (Dhigh(0)+Dlow(0))/2valuezone = (DHigh(0)-DLow(0)) * 0.68//lowerVA = mean-valuezone/2upperVA = mean+valuezone/2c3 = (close > upperVA)indicator2 = ExponentialAverage[20](close)indicator3 = ExponentialAverage[40](close)c4 = (indicator2 > indicator3)//Position sizingIF ((DayOfWeek=1) OR (DayOfWeek=3)) THENPosSize = 6ELSEPosSize = 3ENDIF//Price targets & stopsTar1 = 10Tar2 = 20FxStp = 10TrStp = 3IF c1 AND c2 AND c3 AND c4 THENBUY PosSize SHARES AT MARKETsell (PosSize/3) share at close+(Tar1*pointsize) limitsell (PosSize/3) share at close+(Tar2*pointsize) limitset stop ploss FxStpENDIF// Stops and targetsIf LongOnMarket THENif countoflongshares=PosSize thensell (PosSize/3) share at tradeprice+(Tar1*pointsize) limitsell (PosSize/3) share at tradeprice+(Tar2*pointsize) limitelsif countoflongshares=((PosSize/3) * 2) thensell (PosSize/3) share at tradeprice(2)+(Tar2*pointsize) limitsell at tradeprice(2) stopset stop ploss 0elsif countoflongshares=(PosSize/3) thenset stop ptrailing TrStpENDIFENDIF12/09/2016 at 10:03 AM #18128Just to be clear before I dig into the code and try to understand .. Do you know that it is not possible to close partial position with the code in real trading? It does work in paper trading mode, but IG server will not accept it, like you do in your lines 40 & 41 for example.
12/09/2016 at 3:25 PM #18163Hi Nicolas
Thanks for the reply. No, I didn’t know that. I don’t intend to trade through IG though. For live trading I will definitely trade through Interactive Brokers and using v 10.3. Is this still possible?
I’ve been passing emails between PRT now for well over a month now and hadn’t heard this and I’m very appreciative that you highlighted it.
Thanks again.
12/09/2016 at 3:41 PM #18169ProOrder trading (automated systems) are only available through IG (IG or PRT-CFD), not with IB I’m sorry for you. Trading futures through Interactive Brokers would be a great news for everyone, but I don’t know when it will be available!
12/09/2016 at 4:12 PM #18171Thanks Nicolas for the heads-up.
I don’t think I’ve completely wasted my time. I just spoke with PRT and the person I spoke to said she hopes that IG will allow partial exits some time in 2017. No news on IB as you said. If I have to trade through IG with no partial exits then that’s not the end of the world as a short term solution. Longer term I am sure we would all then move to trade directly through a broker rather than a spread better.
In the mean time, would you mind glancing at the code at the moment? Forget about the exits as I will have to rethink that. For now any ideas why it may be overbuying / overselling would be appreciated.
Thanks
12/13/2016 at 12:27 PM #18444Hi Nicolas (& others)
Just wondering whether you had chance to consider this? Before working on revising the exit from a partial to a full exit it would be good to know if there was anything fundamentally wrong with the entry code causing the over buying/selling and thus resulting in naked positions.
Any help and advice much appreciated.
Thanks
12/13/2016 at 1:44 PM #18451Since it has a lot of “sell” instructions that can’t operate properly on servers, I believe your problem belongs to these lines. You should consider first removing all kind of exit (all “sell” instructions) from your code, you’ll have a clearer view of what to do next with a possible exit strategy.
About stacking orders, you may add this line at the beginning of your code, to prevent adding more orders than the first one:
1defparam cumulateorders=false1 user thanked author for this post.
12/13/2016 at 3:33 PM #18468As per usual many thanks for your reply Nicolas.
Can I confirm – as per your comment above, I can have partial exits if I’m paper trading? The problem is when I go to live trade with IG and their servers? The reason why I’m persisting is that I’ve seen a fair few strategies with partial exits. At the very least it would be good to paper trade such a strategy as a benchmark against what I would trade live (which would have full exits) if you see what I mean.
FYI – I just had a successful entry but in this instance I had a full fill (i.e. it bought the full 6 lots) at the open price rather than a partial fill. The problem definitely only seems to occur when there are partial fills.
Thanks for your cumulative orders line. I actually had it but did not copy it into this thread by accident.
01/25/2017 at 6:21 PM #22466@ Nicolas. This problem occurred again this morning when paper trading @Raul’s great 5min Dax strategy. The code I’m using and screenshot can be found here:
https://www.prorealcode.com/topic/5-min-mini1e-dax-spread-1/page/13/
The code is a lot easier than what I was using in this topic and has no partial exits. Have you come across this before / any suggestions as to what the problem could be? I’ve contacted PRT but there has been silence thus far.
Thanks
02/25/2017 at 11:24 AM #26331Have you tried phased entry? Instead of Buy 6 Lots, Buy 2 lots then if next bar still meets entry conditions Buy 2 Lots then repeat up to 6 Lots. Then you will be able to exit 2 Lots, exit 2 lots etc using a Live Bot.
I often use above tactic when manual trading. If I judge wrong / get in a bit too early and trade goes against me, then phased entry makes it easier to cut (reduced) losses and exit.
Just simple ideas, you’ve probably tried anyway, ‘bumps’ the topic up also 🙂
Cheers
GraHal -
AuthorPosts
Find exclusive trading pro-tools on