Strange if condition code error

Forums ProRealTime English forum ProOrder support Strange if condition code error

Viewing 15 posts - 1 through 15 (of 27 total)
  • #73838

    Hi.

    I have a problem I don’t understand (there is no logic to the problem and would work in other programming languages like vb or different c-versions).

    Below there is a very simple code to show the problem. Everything works fine except the second “trade” with the same code “tradecount = tradecount + 1” which worked fine in the first trade. I started with hard coding the tradecount (tradecount = 1 and then tradecount = 2), but it ended with the same problem that it only works in the first if-code.

    /Daniel

     

    #73841

    I think this post deals with your issue, it’s a question of ONMARKET https://www.prorealcode.com/topic/help-needed-with-code/#post-73833.

    #73843

    I had already tried with “Not OnMarket” earlier but with no change/improvement, don’t know if that what you meant? Well late now and I will check for answers later tomorrow when I’m back at home. Thanks.

    #73848

    Is your problem that the “tradecount” variable is not increasing? Because you are resetting it to zero, each day at 08h50 AM. I’m sure you know it, but just in case ..

    #73850

    You have:

    in your code. Only one position will be allowed to be open at any one time. Set it to TRUE to open extra positions.

    You will also need to add:

    to your first entry conditions and also set a tradecount to 1 when the first trade is opened and use that to allow the second trade to be opened and then cancel the flag once the position is opened

    If you want to keep adding more positions than just the two then you can do this:

    None of it tested and written after only half a cup of coffee!

    1 user thanked author for this post.
    #73965

    Late reply, been out all day + the world cup.

    Nicolas.

    No the tradecount variable works as I also mentioned in the comments in the code. The problem is that the second if statement is flawed (all if statements after the first one), first it works since the tradecount is 1 from Long 1 (otherwise the if statement wouldn’t go ahead), but instead of buying, which comes before the tradecount addon, the tradecount addon seem to be done first and when it’s done the Long 2 if statement aren’t correct anymore and the buy order isn’t done and it goes to the next if statement which I didn’t include in the code above.

    The third statement (Long 3) had tradecount = 2 and would buy if it had no tradecount addon (as in the Long 2 statement), if it had the tradecount addon it wouldn’t buy either (same problem). The third (Long 3) couldn’t be activated if the Long 2 statement wasn’t first correct and the addon was done, the problem seem to be within the ProOrder Interpreter/Compiler (bugged), because how can the addon be done but not the buy order on the previous line in the same accepted if statement? The if statement should do everything between then and endif (unless else and such) and then go to the next if statement, not go back to the beginning of the current if statement.

    To add to this, I had 4 contracts in Long 3 statement and after buying 1 contract in Long 1 (with a loss) and then Long 2 got activated, but not buying anything, the system would then go to Long 3 and buy 4 contracts instead (had buying 2 contracts in Long 2). And because of CumulateOrders = False I thought the next if statment wouldn’t get activated, but I guess it does, so I need to use “not onmarket”, I’ve tested with it though but with the same problem (addon is done but not the buy order before).

    Vonasi.

    The code wasn’t intended to open more positions until the previous one was done. I know how CumulateOrders work.

    I was playing around with entering once during the morning (1 contract) and if a win the system was done for the day (the firsttarget = 1 in the longonmarket if statement), but if a loss it would enter again once the conditions was correct, but this time with 2 contracts. But this didn’t work because of the compiler problems within ProOrder (as I see it).

    #73967

    Forgot to mention the clearing of the variables. The code

    was there as intended. Each day I want to clear the tradecount and the firsttarget because of the intention to only take 1 trade a day if the first trade was a win, hence reaching firsttarget 1, or Long 2 if a loss in the first trade (then I went on to test with Long 3 too when Long 2 didn’t work as intended).
    #73969

    The code wasn’t intended to open more positions until the previous one was done. I know how CumulateOrders work.

    Your description is very difficult to understand.

    The code in ProOrder is read from top to bottom at the close of each candle. If CUMULATEORDERS is set to FALSE then no additional positions will be opened at the close of a candle if a position is already open. So you can put any number of BUY instructions in your code within whatever IF THEN ENDIF statements you like but they will all be ignored. Other variable changes will not be ignored unless they are protected by an IF NOT ONMARKET.

    #73977

    The code wasn’t intended to open more positions until the previous one was done. I know how CumulateOrders work.

    Your description is very difficult to understand.

    The code in ProOrder is read from top to bottom at the close of each candle. If CUMULATEORDERS is set to FALSE then no additional positions will be opened at the close of a candle if a position is already open. So you can put any number of BUY instructions in your code within whatever IF THEN ENDIF statements you like but they will all be ignored. Other variable changes will not be ignored unless they are protected by an IF NOT ONMARKET.

    Hi again.  Yes the description in my first post wasn’t very good, I didn’t want to write to much text and thought the comments in the code would help as well.

    Then in your reply you once again write about opening additional positions which I just explained about in my previous two posts (and where clear about in the part below your nickname). Everything about the problem is in those two posts (06/21/2018 at 8:55 PM and 06/21/2018 at 9:02 PM). I also wrote that I’ve tried with IF NOT ONMARKET but it doesn’t change anything, it’s still the same problem.

    Here is the code as of now I’m testing with to get the system to buy the second time AFTER the first trade has been stopped out.

    Late now, time for zzz, will check more tomorrow.

    Thanks.

    #73990

    If you just want to limit it to three separate trades in a day then why make it so complicated? One entry IF THEN and a counter and a positionsize multiple will do it.

    I had to guess that you are working on the 5 minute chart for testing from the times used in your code.

     

    1 user thanked author for this post.
    #74077

    Vonasi.

    Thanks for optimizing the code, will definitely be able to use some parts of it (for the tests and in the future).

    About complicating things it’s because I want the possibility to use different positionsizes at the different trades. I might want to go with 1 contract in the first trade, then 2 and finally 2 again in the third trade. Or perhaps 1 contract in the first and second trade and 2 or maybe 4 contracts  in the third trade, that’s what I want to test out and play around with. That’s the reason I wanted to separate the trades. Is there a way to be able to do this?

    Though I still want to be able to understand why the separate if statements I posted 06/22/2018 at 12:20 AM didn’t work. They would work in any other big programming language, hence I feel there has to be som bugs in the ProOrder language.

    Thanks.
    /Daniel

    #74084

    Hi again.

    It was possible to solve with IF statements within your Long 1 version similar to the way I wanted to do it from the beginning. For testing purposes I bought 1 contract, then 4 contracts and finally 2 contracts and it worked. Now I have something to play around with. Still wonder why my version didn’t work, but happy there is another way to do this.

    Had to increase the maxtrades too from Vonasi’s latest post if someone wonder (didn’t include it to keep the code short).

    Thanks.

    #74086

    Ok I didn’t need to increase the maxtrades, I accidently wrote the wrong tradecount in the second and third statement (0, 2 and 3), should be like this:

    Thanks again.

    #74087

    This should do what you want for now until someone can explain why the other code does not work.

    1 user thanked author for this post.
    #74089

    I worked it out. It is the order that you put the conditions in. Long 3 must be first and Long 1 last. Each IF THEN was setting the conditions for the next ones conditions to be met. So not really a PRT bug – more of an operator error! 🙂

     

Viewing 15 posts - 1 through 15 (of 27 total)

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