How to place single stop order for a limited time?
Forums › ProRealTime English forum › ProOrder support › How to place single stop order for a limited time?
- This topic has 5 replies, 2 voices, and was last updated 7 years ago by tob107.
-
-
07/04/2017 at 4:58 PM #39806
Hi,
I’d like to have a buy stop order in the market for a limited time, which is possible with the following simple code:
12345IF TIME >= Start AND TIME < End AND LongCounter = 0 THENBUY NbrContracts CONTRACTS AT XX STOPSET STOP pLOSS SLSET TARGET pPROFIT TPENDIFI’d like the order only to be executed once in that time, which I solved with:
123IF LongOnMarket THENLongCounter = 1ENDIFStill easy, right?
The tricky part is when I’m being stopped out on the same candle as the entry, so the code haven’t run again and realized that there’s already been an attempt at this trade which failed.
I looked in the handbook as well, which had the following example:
123456789101112131415161718ONCE NbBarLimit = 10MM20 = Average[20](close)MM50 = Average[50](close)// If MM20 crosses over MM50, we define 2 variables "MyLimitBuy" and "MyIndex" containingthe close price at that time and the index of the bar of the cross.IF MM20 CROSSES OVER MM50 THENMyLimitBuy = closeMyIndex = BarindexENDIFIF BarIndex >= MyIndex + NbBarLimit THENMyLimitBuy = 0ENDIF// Place an order at the price MyLimitBuy valid as long as this variable is greater than0 and we are not in a long position.// Remember: MyLimitBuy is greater than 0 for the 10 bars after the bar of the crossing.IF MyLimitBuy > 0 AND NOT LongOnMarket THENBUY 1 SHARES AT MyLimitBuy LIMITENDIFI haven’t really tried that one, since I suspect that the result will be the same as with my code.
So, any ideas how to place a single stop order for a limited time?
Cheers!
07/05/2017 at 7:33 PM #3992007/06/2017 at 9:13 AM #39933Your first code is good. While the time condition is still true, the pending order will be set at market and because this kind of order only last one candlestick, no new stop order will be set after the “End” time variable value.
If the trade triggered by the pending order opened and closed on the same bar, you can try to know an order has existed with POSITIONPERF, POSITIONPRICE, TRADEINDEX, TRADEPRICE ..
07/06/2017 at 8:44 PM #3997207/07/2017 at 9:06 AM #3999607/07/2017 at 12:51 PM #40023Yes, that was the plan, I just had to try it out last night to make sure it worked. I solved it like this, fairly simple and probably not the most sexy solution but it gets the job done:
123IF TIME = StartTrade THENTRD = TradeIndexENDIF123456// Conditions to enter long positionIF TIME >= StartTrade AND TIME < EndTrade AND LongCounter = 0 AND TradeIndex = TRD THENBUY NbrContracts CONTRACTS AT XX STOPSET STOP pLOSS SLSET TARGET pPROFIT TPENDIFSo basically:
-At one time only, when it’s start to trade, set TRD = TradeIndex
-Before adding another buy stop in the market, make sure that TradeIndex still equals TRD (since it has changed if a trade was taken)
I guess the LongCounter variable is now pretty useless, but I’ll just leave it there for now.
Thanks again!
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on