Detect if Limit Order has been executed
Forums › ProRealTime English forum › ProOrder support › Detect if Limit Order has been executed
- This topic has 5 replies, 2 voices, and was last updated 8 years ago by smartinick.
-
-
08/10/2016 at 11:52 AM #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:
1234567891011once longtrigger=0if longonmarket thenlongtriggered=1endifif (tradingsystemlongcondisionsmet and longtriggered=0) thenBUY PositionSize CONTRACT AT longlevel limitSET TARGET pPROFIT tpset stop ploss slendifwhat 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.
08/10/2016 at 12:40 PM #11490Hello, 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?
08/10/2016 at 1:02 PM #11492Nicolas!
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….?
08/10/2016 at 1:15 PM #11493Update…. 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.
->
123if TRADEPRICE(2)<>TRADEPRICE(1) thenlongtriggered=1endifgotta 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.
08/10/2016 at 3:47 PM #1149808/12/2016 at 9:37 AM #11597Tradeindex does the trick indeed!
Thanks!
-
AuthorPosts
Find exclusive trading pro-tools on