Stopping second trade if first completes quickly
Forums › ProRealTime English forum › ProOrder support › Stopping second trade if first completes quickly
- This topic has 9 replies, 3 voices, and was last updated 4 years ago by robertogozzi.
-
-
04/15/2019 at 7:56 PM #96535
Most of my strategies are for Wall Street, which can move very quickly. This means that sometimes a trade is triggered and completed quickly, sometimes within the time period I allow for a trade to trigger. I can’t seem to find a way to stop a second (or sometimes third) trade from setting up.
Eg After a hammer, I might allow 3 candles for a trade to trigger. Sometimes the trade will trigger and reach target within the first candle, but the conditions eg a hammer within the last 3 candles is still the case, so a second trade is now set up.
I’ve tried using ” Not Onmarket” but can’t seem to get it working how I’d like it to ie a maximum of one trade per set up.
I’m sure there is a very simple way of doing this, but I can’t seem to work it out, so any help would be much appreciated.
Many thanks in advance.
04/15/2019 at 8:35 PM #96536When the pattern is detected set a variable, say FLAG=1.
Add it to your conditions to enter a trade.
Clear that variable when 3, or whatever number you prefer, bars have elapsed or when you are OnMarket.
Should your trade enter and end within the same bar without updating the OnMarket status, you need to check if STRATEGYPROFIT is any different from STRATEGYPROFIT[1], if it is then a trade was entered and exited so you can clear the above mentioned variable.
1 user thanked author for this post.
04/15/2019 at 8:58 PM #96539Many thanks for your prompt reply.
I have already tried doing something along these lines, but without success so far. I’ll persevere, and maybe add the code here if I still can’t get it to work.
04/15/2019 at 9:07 PM #96540Sorry, perhaps I should add, I have tried using “Not Onmarket”, but the problem isn’t that it enters a second trade at the same time, but simply once I’m not longer “OnMarket” (ie when the first trade is finished), then a second trade may be entered because I’m no longer in a trade.
I don’t know how to use being “OnMarket” to keep the Flag at 0 when I’m no longer “OnMarket”, as I’m just using if-then-endif conditions to set up the trades.
04/15/2019 at 9:18 PM #96541Post your code, please.
04/16/2019 at 6:18 AM #96548Basic hammer/star code123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148//hammer 3min WS v2.02 CodeDEFPARAM FlatAfter = 205000DEFPARAM cumulateorders = falseresult = 0//Red Hammer signalif not shortonmarket thenif time > 143530 thenif low<low[1] thenif close<open thenif open-close>high-open thenif close-low>2*(high-close) thenif close-low>14.9 thenif low - .1 < lowest[5](low) thenresult = -1endifendifendifendifendifendifendifendif//Green Hammer signalif not shortonmarket thenif time > 143530 thenif low<low[1] thenif close>open thenif close-open>high-close thenif open-low>2*(high-open) thenif open-low>14.9 thenif low - .1 < lowest[5](low) thenresult = -1endifendifendifendifendifendifendifendif//Green star signalif not longonmarket thenif time > 143530 thenif high>high[1] thenif close>open thenif close-open>open-low thenif high-close>2*(close-low) thenif high-close>14.9 thenif high + .1 > highest[5](high) thenresult = 1endifendifendifendifendifendifendifendif//Red star signalif not longonmarket thenif time > 143530 thenif high>high[1] thenif close<open thenif open-close>close-low thenif high-open>2*(open-low) thenif high-open>14.9 thenif high + .1 > highest[5](high) thenresult = 1endifendifendifendifendifendifendifendif// Definition of the validity length of the orderonce NbBarLimit = 6// Conditions to enter long positionsif result= -1 thenMyStopBuy = 17+ closeMyIndex = Barindexendifif Barindex >= MyIndex + NbBarLimit thenMyStopBuy = 0endifIF NOT LongOnMarket and barindex-tradeindex >-1 AND MyStopBuy > 0 THENBUY 1 CONTRACTS AT MyStopBuy StopENDIF// Conditions to enter short positionsif result = 1 thenMyStopSell = close - 17MyIndex = Barindexendifif Barindex >= MyIndex + NbBarLimit thenMyStopSell = 0endifIF NOT ShortOnMarket and barindex-tradeindex >-1 AND MyStopSell > 0 THENSELLSHORT 1 CONTRACTS AT MyStopSell StopENDIF// Stops and targets : Enter your protection stops and profit targets hereSet Stop pLoss 53if time < 193000 thenSet Target pProfit 25elseset Target pProfit 15endifI appreciate it’s not very elegant; it was originally just for an indicator but has converted into automated trading quite well, apart from this issue with second trades.
04/16/2019 at 9:42 AM #9657004/16/2019 at 9:49 AM #96571You already have two flags: MyStopBuy and MyStopSell.
To reset them when OnMarket, add these lines at line 6:
123456If OnMarket THENMyStopBuy = 0MyStopSell = 0ElseMyProfit = STRATEGYPROFITEndifThe line activated by ELSE has the purpose of helping you detect a trade that has been triggered and closed within the same bar.
Below the above snippet of code add this one to clear the two variables in case a trade opened and closed within the same bar:
1234567If not OnMarket and Not OnMarket[1] thenIf MyProfit <> STRATEGYPROFIT ThenMyStopBuy = 0MyStopSell = 0MyProfit = STRATEGYPROFITEndifEndifYou check that you are not OnMarket now and were not the previous bar, yet STRATEGYPROFIT has changed.
1 user thanked author for this post.
04/16/2019 at 8:11 PM #96630Many thanks for the help.
I’ve removed that condition from lines 118 and 134, and have added in the 2 snippets of code, but the amended code will still trigger a second trade if the original trade opens and closes in the same candle.
04/16/2019 at 10:26 PM #96641You shouldn’t have removed those two conditions, otherwise the snippets of code are useless.
-
AuthorPosts
Find exclusive trading pro-tools on