Limiting accumulating orders & Fuse
Forums › ProRealTime English forum › ProOrder support › Limiting accumulating orders & Fuse
- This topic has 12 replies, 2 voices, and was last updated 1 year ago by robertogozzi.
-
-
02/20/2017 at 1:09 PM #25746
Hi all. This is following on from a discussion I had with @Raul. I thought I would post it as a new topic to get wider views. Two questions which could be of use/interest to all:
1) When we use the following in our strategies
1DEFPARAM CumulateOrders = true…is it possible to limit the number of orders that can be accumulated in a day? I’m thinking about minimising the risk of allowing orders to “uncontrollably” accumulate, for example in the instance of an unexpected macro event or natural disaster. It would be especially useful on fx strategies overnight. For example, if a strategy on average returns 3 trades a day I may want to limit number of trades in 1 day to let’s say 10. If you have wide stops (which occasionally I do) it is possible to accumulate orders without getting stopped out or the fuse(s) being triggered and then potentially getting a big loss at the end of the trading period when all positions are closed.
2) I have seen the suggestions for fuses on this site, in particular from https://www.prorealcode.com/documentation/quit/ and https://www.prorealcode.com/blog/learning/max-profit-loss-day-trading-strategy/.
Is it possible to have a “real time” fuse which works out your P&L midway during a trade(s) instead of when the position(s) is(are) closed. It can then stop a strategy if the loss is greater than x no matter how many positions are open. This is connected (but separate) to the first question.
In an ideal world you could have a situation where you could accumulate orders up to a maximum amount AND have a real time fuse for added safety.
Thanks
02/21/2017 at 10:17 AM #25833- About your first question, here is a code snippet that should meet your requirements (forum coding, not tested):
12345678910111213141516171819defparam cumulateorders=falsemaxorders = 10 //max orders per day//reset the count of orders each dayif intradaybarindex=0 thencount = 0endif//buy orderif buycondition and count<maxorders thenbuy 1 share at marketendif//counting ordersif onmarket and lastindex<>tradeindex thencount=count+1lastindex=tradeindexendif2. I think you already have what needed in this blog article? : https://www.prorealcode.com/blog/learning/max-profit-loss-day-trading-strategy/
02/21/2017 at 10:41 AM #25839Thanks Nicolas. I’ll look and test that bit of code. Quick query: I want to be able to accumulate orders (but up to the max of 10 in this example). Should the code be “defparam cumulateorders=false”. I’m just checking. I would have thought it should be “true” but with the rest of the code to limit it at 10 orders.
With regards to question 2, will the code calculate the max loss of the trading day (which is what I’m interested in) real time and mid way through a trade? I thought it only did this once a position was closed. Again just checking.
Thanks again for taking the time to take a look. Really appreciated.
02/21/2017 at 10:51 AM #25848Oh my bad, of course you have to set cumulateorders to “true”, good point!
and no .. as you know it already, proorder will only read once the code in a bar, we have to wait for MTF support to come in a near future.
1 user thanked author for this post.
02/21/2017 at 10:57 AM #25850No worries. That’s nothing compared to the mistakes I make.
Just so I’m clear, the code snippet in the fuse will recalculate at the end of each bar (completely understand this bit) and will take into account open positions? I know it is not strictly “real time” but it is as close as we can get at the moment. Therefore you don’t have to wait for your stop to be hit and close the position?
02/21/2017 at 11:24 AM #25862No, this code snippet will not take into account the current open positions..
You could give it a try with this one instead:
123456789fuse = 500 //max live loss in money//floating profitfloatingprofit = (((close-positionprice)*pointvalue)*countofposition)/pipsize //actual trade gains//THE FUSEif strategyprofit+floatingprofit<=-fuse thenQUITendifAgain, not tested, forum coding!
1 user thanked author for this post.
02/21/2017 at 11:32 PM #2599302/24/2017 at 6:39 PM #26294Hi Jonjon
Whilst it looks you have a solution, it’s possibly worth mentioning that when you set an autotrade up – the figure that you put in the box (see picture) will also limit the number of positions.
If you have set your coding to 10 but only enter 2 in this box – it will limit your accumulated trades to “2” etc…
02/24/2017 at 6:49 PM #2629706/14/2020 at 1:11 PM #13589106/14/2020 at 1:14 PM #13589201/24/2023 at 2:53 PM #208121Hello,lastindex <> tradeindex…puis quelques lignes plus bas lastindex = tradeindex ?! Pour moi qui ne suis pas codeur ni informaticien c’est assez déroutant. J’ai quelques rudiments en code et je peux programmer des petites choses simples avec PRT, mais là c’est ce genre de “logique” sur laquelle je bloque et qui fait que je n’avance pas. je pensais suivre en intégralité la formation proposée ici par Nicolas. J’espère que ces questions sont abordées en détail pour bien comprendre, car il faut se mettre à la place d’un non initié, c’est totalement contre intuitif. En effet, en maths à l’école on apprend depuis toujours que A = A + X n’est possible que si X = 0. MerciHello, lastindex <> tradeindex…then a few lines down lastindex = tradeindex?! For me, who am not a coder or a computer scientist, it’s quite confusing. I have some coding basics and I can program simple little things with PRT, but it’s this kind of “logic” that I’m stuck on and that’s stopping me moving forward. I thought I would follow the entire training offered here by Nicolas. I hope that these questions are addressed in detail to fully understand, because you have to put yourself in the shoes of an uninitiated person, it is totally counter-intuitive. Indeed, in math at school we have always learned that A = A + X is only possible if X = 0. Thank you
01/24/2023 at 7:08 PM #208148@Reg7
Only post in the language of the forum that you are posting in. For example English only in the English speaking forums and French only in the French speaking forums.
Thank you 🙂
-
AuthorPosts
Find exclusive trading pro-tools on