Time-based limit order
Forums › ProRealTime English forum › ProOrder support › Time-based limit order
- This topic has 3 replies, 2 voices, and was last updated 3 years ago by
robertogozzi.
-
-
08/13/2021 at 8:52 AM #175221
Hello all,
I would like to seek some advice on coding time-based limit order. For example if the buy condition is met, I do not want to buy right after the next candle. Instead, if the condition is met, and when the new candle starts, I want to put a buy limit on the previous candle to buy a 50% of the high and low. Say the condition is met, and at the start of the new candle, I look at the previous candle. The previous candle high is 15, and low is 5, and thus I would like to out a buy limit at 10, as shown in the code below
12345678//Find the mid point of the previous candleUBand = highest[1](high[1])LBand = lowest[1](low[1])ToBuyLevel = (UBand+LBand)/2If MyLongConditions And Not LongOnMarket ThenBuy 1 Contract At ToBuyLevel LimitEndIfBut if i want to make the buy limit order at 10 to be good for only the current candle + the next 4 candles only, how do I go about modifying the code to meet this criteria? Appreciate your advice. Thank you very much.
08/13/2021 at 9:30 AM #175223You cannot use use LIMIT or STOP randomly.
You need to use LIMIT orders when the entry price is more favourable than the current one (you want to BUY at a lower price or SELLSHORT at a higher one), while STOP orders are to be placed when the entry price is less favourable (you want to BUY at a higher or SELLSHORT at a lower one).
When placing pending orders you should also consider the minimum distance required by the broker for the instrument you are trading.
Anyway, your code to accomodate for a 5-bar (4 + current one) expiration is:12345678910//Find the mid point of the previous candleUBand = highest[1](high[1])LBand = lowest[1](low[1])ToBuyLevel = (UBand+LBand)/2ONCE Count = 0Count = Count -1If MyLongConditions And Not LongOnMarket AND Count >= 0 ThenBuy 1 Contract At ToBuyLevel LimitCount = 4EndIfThis version will compare the current price to the entry price (with a 10-pip distance):
123456789101112131415161718ONCE Distance = 10ONCE Count = 0//Find the mid point of the previous candleUBand = highest[1](high[1])LBand = lowest[1](low[1])ToBuyLevel = (UBand+LBand)/2Count = Count -1If MyLongConditions And Not LongOnMarket AND Count >= 0 ThenIF close > (ToBuyLevel + Distance) THENBuy 1 Contract At ToBuyLevel LIMITCount = 4ELSIF close < (ToBuyLevel - Distance) THENBuy 1 Contract At ToBuyLevel STOPCount = 4ELSEBuy 1 Contract At MARKET //you may want to comment out this line to skip entering At MARKETENDIFEndIfas to the SHORT size you will have to revert conditions for the STOP/LIMIT order decision.
1 user thanked author for this post.
08/13/2021 at 10:20 AM #175224Thank you Roberto,
Yes the buy limit is to buy at a better level compare to current market. Basically the strategy is if it is a long bodied green candle, I do not want to buy at the next candle which will open at the high, and thus would prefer to put a buy limit somewhere below, say 50 pct retracement of that candle. And the buy limit is good for the current candle + the next 4 candle.
But the code:
123456ONCE Count = 0Count = Count -1If MyLongConditions And Not LongOnMarket AND Count >= 0 ThenBuy 1 Contract At ToBuyLevel LimitCount = 4EndIfat the current candle is correct. But the Buy limit order is still good for the next candle, even tho the MyLongConditions is no longer valid. So even if the buy limit is not filled in the current candle, the buy limit supposed to be still live. But in the current code, because in the next candle, ifthe MyLongCondition is no longer valid, it will not continue to place the buy limit. Any thoughts?
08/13/2021 at 10:31 AM #175226I also spotted a logical error. Replace line 3 with this one:
1If ((MyLongConditions AND Count < 0) OR (summation[5](MyLongConditions) AND Count >= 0)) And Not LongOnMarket Then1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on