Avoiding repetition of operation under one condition

Forums ProRealTime English forum ProOrder support Avoiding repetition of operation under one condition

Viewing 10 posts - 1 through 10 (of 10 total)
  • #73501

    Dear all, I hope you are enjoying this nice weekend,

    I am working on a weekly grid strategy. Brief description: Every Monday at 09:00h, the close determines the levelZERO and marks 10 levels UP and 10 levels DOWN from level ZERO, with a 50 pips separation between each of them. Since it is a hedge strategy, I am developing two different codes (LONG and SHORT).

    At 09:00h, it buys and sells at level ZERO and continue buying and selling at every level. The strategy gets rid of the losing operations after 50 pips, and continue accumulating the winning. The strategy starts at 09:00h on Monday and close ALL operations when reaching the last level (level10up or level10dow) or on Friday at 21:00h.

    Obviously, it only works in trendy weeks. Nevertheless, before applying any filter to avoid lateral markets, I am having trouble with avoiding repetition of operations. Example: when the price touches level1up I want to launch a BUY and SELLSHORT, and I DO NOT want to launch any other order until it touches the next level up or down. In the current strategy, it buys and sells every time it touch the SAME level, accumulating several contracts at the same level. I have tried to avoid repetition after the first buying with level1up=0 and level1up=1, but it does not work.

    I am attaching only the LONG strategy, since the SHORT it is just the opposite. I am also attaching the indicator TRINQUETE weekly 50pips levels to visualise the levels clearly.

    Thanks so much in advance for any help,

    Juan

     

     

    #73512

    Maybe a separate bit of code so that if close crosses a level then a flag for that level is set and any flags for any other levels are cancelled to zero. Then only allow entry at a level if the flag for that level is zero? You may have to only let the flag be set if previous close was between levels either side.

    Just thinking off the top of my head – it may not be the answer!

    1 user thanked author for this post.
    #73516

    Hi Vonasi, Thanks for the idea.

    I am not sure if it will work. To set up the pending STOP order the close has to be between two levels, and setting up a flag will do IMO the same that the command to set up the STOP orders. Every time the close crosses the level, even without reaching the next level, it will open another order. I have tried to put something like this (just for the two first levels UP/DOWN of levelZERO):

    but, it doesn’t work. After the first initial buy at level ZERO, no order is launch again. I am trying that after the first buy at every level, we set up a variable in a way that no other order can be launch. Only after crossing to the next level, that variable is enable again, in case the price goes back to the previous level.

    Right now, the backtest shows the redundant orders at every level the ruin the strategy.

    Thanks anyway.

    #73521

    This was more the idea that I had in mind…. just off the top of my head as my platform is not open right now.

    #73523

    Thinking about it… why don’t you just use TRADEPRICE as your datum level and set orders to buy and sell 50 pips above and below this level?

    #73526

     

    #73529

    Hi Vonasi,

    Thanks, I am going to try both options. I really like the more simple and effective second one. Sometimes, someone else can bring more simple ideas to something I was complicating too much 🙂

    Thanks. I will post the code once it is finished, in case someone is interested in a grid (with hedge) strategy.

    Juan

     

    #73530

    Sometimes, someone else can bring more simple ideas to something I was complicating too much

    No problem – I was pleased with myself for coming up with a simple solution in the end as normally I take the code that was provided and never question it and just try to work with the original rather than start at the beginning again.

    This time I surprised myself especially as I was thinking about the problem after a couple of glasses wine!

    #73550

    You can add a FLAG variable for each level and set it to 1 when that level is hit, then ban opening trades on that level when that flag=1

     

     

    1 user thanked author for this post.
    #73568

    Hi Roberto,

    Thanks. In #73516 I did something similar, but somehow I did something wrong, since it didnt work. In any case, Vonasi’s approach is working. I am trying to put on the demo account but the orders are rejected due to negative stops (minor problem).

    Thanks to both.

    Juan

Viewing 10 posts - 1 through 10 (of 10 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login