Limiting accumulating orders & Fuse

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #25746 quote
    jonjon
    Participant
    Average

    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

     

    DEFPARAM 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

    #25833 quote
    Nicolas
    Keymaster
    Master
    1. About your first question, here is a code snippet that should meet your requirements (forum coding, not tested):
    defparam cumulateorders=false
    
    maxorders = 10 //max orders per day
    
    //reset the count of orders each day 
    if intradaybarindex=0 then 
     count = 0
    endif 
    
    //buy order
    if buycondition and count<maxorders then 
     buy 1 share at market 
    endif 
    
    //counting orders
    if onmarket and lastindex<>tradeindex then 
     count=count+1
     lastindex=tradeindex
    endif
    
    

    2. I think you already have what needed in this blog article? : https://www.prorealcode.com/blog/learning/max-profit-loss-day-trading-strategy/

    jonjon and soad41 thanked this post
    #25839 quote
    jonjon
    Participant
    Average

    Thanks 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.

    #25848 quote
    Nicolas
    Keymaster
    Master

    Oh 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.

    jonjon thanked this post
    #25850 quote
    jonjon
    Participant
    Average

    No 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?

    #25862 quote
    Nicolas
    Keymaster
    Master

    No, this code snippet will not take into account the current open positions..

    You could give it a try with this one instead:

    fuse = 500 //max live loss in money
    
    //floating profit
    floatingprofit = (((close-positionprice)*pointvalue)*countofposition)/pipsize //actual trade gains
    
    //THE FUSE
    if strategyprofit+floatingprofit<=-fuse then 
     QUIT
    endif
    

    Again, not tested, forum coding!

    jonjon thanked this post
    #25993 quote
    Raul Vg
    Participant
    Senior
    defparam cumulateorders=true
    
    //buy order 
    
    if countofposition<=5 then // Max. 5 orders
    
    if buycondition  then 
     buy 1 share at market 
    
    endif
    endif 
    jonjon and soad41 thanked this post
    #26294 quote
    Big Hug
    Participant
    Average

    Hi 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…

    #26297 quote
    jonjon
    Participant
    Average

    Thanks Big Hug. I forgot about that. I may use it in addition to one of the other solutions above for extra safety

    #135891 quote
    Fran55
    Participant
    Veteran

    How to limit daily loss on % of account and no operate to Next day???

    Need Code.

    Thanks!

    #135892 quote
    Fran55
    Participant
    Veteran

    No operate Before next day

    #208121 quote
    Reg7
    Participant
    Junior

    Hello,

    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. Merci

    Hello, 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

    #208148 quote
    robertogozzi
    Moderator
    Master

    @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 🙂

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

Limiting accumulating orders & Fuse


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
jonjon @jonjon Participant
Summary

This topic contains 12 replies,
has 2 voices, and was last updated by robertogozzi
3 years ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 02/20/2017
Status: Active
Attachments: 1 files
Logo Logo
Loading...