Detect if Limit Order has been executed

Forums ProRealTime English forum ProOrder support Detect if Limit Order has been executed

Viewing 6 posts - 1 through 6 (of 6 total)
  • #11489

    Hello dear community!

    1st post here – so for the beginning i want to say thanks for building and feeding this site – there’s a lot of interesting things to find 😀

    i’m running into a little problem with a trading system. in theory some conditions are met and it should setup a limit order (that stays active for a while – that part works).

    the whole system should produce only one order each day, but at least in backtest there’s more and more orders. (i know about the problem with the miss-calculated results if a trade’s closed within one candle, but that’s a different thing).

    i suspect the following cause:

    as the limit order get’s auto-cancelled on bar close, i have to recreate it on the next iteration. so there’s actually 3 flags:

    • is my buycondition met
    • am i still within the timespan where i want to recreate the order
    • did one of the orders already execute before? (<- here’s the problem…)

    the flag if i got a order execution is implemented via “if longonmarket then set flag”

    but: the code only runs once on each bar’s close. so it happens that i create a order at one bar, which is executed within that bar and which runs into take profit or stop loss within that same bar. so on the next iteration i’m already flat again and the flag that i already got a order-execution will not be set.

    i hope this sounds clear…. here’s a example of the relevant lines:

    what do you think…? is the cause of the problem as i believe it is…? and how could i prevent that…?

    actually i’m missing a “order executed” event where the flag could be set.

    Thanks for your help! & Best Regards!, Martin.

    #11490

    Hello, thanks for your compliment about the website.

    I see 2 different names for the same variable (I guess?) into your code: ‘longtrigger’ and ‘longtriggered’, maybe a typo error of your forum post?

    What happens if you move the lines 3 to 5 to the end of the code?

    If I understand correctly your problem: you don’t have any flag set to 1 if the limit order is triggered and exited by profit or loss within the same bar? am I right?

    #11492

    Nicolas!

    Thanks for your reply!

    trigger/triggered is just a mistake from copying only parts of the code – double checked in the current code.

    moving lines 3-5 to the end makes no difference – over 3 months it’s the same – too high – number of average trades per day.

    and yes, you understand my problem correctly! the code only seems to iterate once on each candle. if the order placed in one iteration is going on market and flat again before the next iteration of the code runs, the *****onmarket statements will have no effect as i _was_ on market since previous code iteration, but i’m not any more.

    the only idea i have it to run the code e.g. in the 10-second chart, change all condition-calculations so they match the 5m timeframe (where i’m running in now) and hope to get the flag set in case a position is not closed within 10 seconds… but…. for one trade a day that’s pretty weird, isn’t it….?

     

    #11493

    Update…. Cumulateorders does not help either as i’m flat on the next code iteration.

    but using TradePrice seems to work a bit – at least there’s only _some_ double trades.

    ->

    gotta go now, but another interesting starter could be tradeindex (in conjunction with barindex and checking if the difference of both is just 1).

    but in both cases – tradeprice or tradeindex – i’m not really shure if they get updated “between” the iterations for the code.

    #11498

    Nothing will get update between 2 candlesticks closure.

    TRADEINDEX would do the trick. Just test at each candle if the last tradeindex is 1, if it’s true, then you have your flag and you can disallow trading.

    #11597

    Tradeindex does the trick indeed!

    Thanks!

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

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