How to keep a condition active for more than one bar

Forums ProRealTime English forum ProOrder support How to keep a condition active for more than one bar

Viewing 14 posts - 1 through 14 (of 14 total)
  • #61790

    Hi all,

    In this case:

    I am trying to set up a precondition to enable a trade. Before buying at level2up, closes has to crosses over level1up. The problem is that only works when it happens in the previous bar. When it happens several bars before, it doesn’t work.

    I assume that we have to include something to keep this precondition (level1up=1) active, until it reaches the buying STOP order.

    Any suggestions??? ,

    Many thanks in advance,

    Juan

    #61809

    Line 3 sets level1up to 1, but in line 2 you are comparing that value with close, which will rarely occurs and only on istruments ranging from just below 1.0000 to slightly higher. Eur/Usd will be unlikely to result in a true condition before some time!

    Maybe level1up in line 2 should be replaced with level2up?

    Anyway, your problem seats on line 9, since you immediately set it to ZERO, the next bars (unless another crossing occurs) conditions in line 7 will never be true again!

    1 user thanked author for this post.
    #61815

    Hi Roberto,

    Thanks for your answer, but I think there is a misunderstanding.

    I am building a grid system that already works. I have created horizontal levels, with 50 pips separation, called level1up, level2up, and so on. In order not to buy against trend, I want that the price, before reaching level2up, crosses level1up, to make sure the price is going up. In some cases when the price is going down and have a slight retrace and touch any of the levels from below, it goes LONG when the general trend is the opposite.

    So, right now, it works, I enable the buying STOP order at level2up when previously the price has surpassed level1up, but only works when that have occurred just one bar before. When the STOP order is executed, then I disable again the level1up to zero.

    So I would like to know, if I have to include something to keep level1up=1 active until it reaches level2up BUYING STOP order, in case that it happens more than 1 bar after crossing level1up.

    I hope it is clear now, but in any case thanks because you are always the first one to come to my rescue :))

    Regards,

    Juan

    #61827

    Just move line 9 somewhere else combined with a variable that determines WHEN the pending order has to be cancelled. This example cancels pending orders conditions after 10 bars:

     

     

    #61836

    Hi Roberto,

    Many thanks 🙂

    Juan

    #61839
    Leo

    If the order level is the same in several bars, my systems do not close and open the same orders, it just let them open.

    #61864

     

    #61865

    Hi Leo and Roberto,

    This is the code. Horizontal levels above and below the LEVELLER which is determined by the price around 080000. The levels are separated by 40 pips.

    If the price goes up only BUY LONG in the levels above ZERO (levelsup), and it has to be by crossing before a previous level. Example: If price is going up and going to cross level4up, I want that first has crossed over level3up, to avoid open LONG operations when the price is going south and touch any level in a small retrace.

    The same way with the SHORT operations. Only short operations in the South Hemisphere where Level ZERO is the equator.

    Right now, with this change proposed by Roberto, I can still see operation that are open without previously crossing the previous level.

    Any suggestions??? Any change or improvement is welcome.

    Thanks.

     

    #61866

    In order to better visualise the operations, you can download the indicator that draw the lines, so you can visualise the different levels.

    #61868

    in post 61865, I meant LEVELZERO instead of LEVELLER. F%&$*g autocorrector :))

    #61875

    In line 80 you write

    thus replacing the value it was assigned in line 62, but the next bar level1up, which is now 1, will be replaced again with the old value when it reaches 62, so later at line 120 the condition will be false even if in the previous bar a crossing had occurred.

    I think lines 53 through 73 should have different variable names.

     

    1 user thanked author for this post.
    #61876

    Damn!!! Well done Roberto. I didn´t realised about that. I will change the names I assigned the levels not to interfere with the variables level1up, etc.

    Thanks so much.

    #61896

    did you make the correction? how is the backtest? can you post the new code please?

    #61933

    Hi Raphaelopilski,

    I am attaching below the code with the changes but it is not what I am looking for. I will continue working until it does exactly what I want. In any case, thanks to everyone, especially to Roberto for his comments and ideas.

    If you use the indicator that I have provided before it will easier to visualise/identify any flaws of the operations and what it has to be improved.

    Regards,

    Juan

    2 users thanked author for this post.
Viewing 14 posts - 1 through 14 (of 14 total)

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