Stop / close Position on close bar or alert with trigger too close
Forums › ProRealTime English forum › ProOrder support › Stop / close Position on close bar or alert with trigger too close
- This topic has 14 replies, 4 voices, and was last updated 4 years ago by Ruven JR. Maerson.
-
-
11/21/2019 at 3:27 PM #113324
Hi guys,
it happens sooooooo often that i set a stop e.g. under a support with 20 or more points (depending on volume) below but then the price hits the stop and went then dircetly up for 100 points or more in seconds. I am wondering if i am the only one, who would like to have an option for a stop or a close position trigger in the alert on close bar not when hitting the line or price. Is there any option to achieve this???
I tried it with the alert trigger. It closes the position when i set the opposite order and not foreced open is activated, BUT it opens a new posistion. This is not what i want or am i doing sth. wrong?
I just want to close the position on close bar! Any options, or ideas?
Thank you for any help
11/21/2019 at 5:05 PM #113335To accomplisg that you need not use STET STOP LOSS, but use code, instead:
123456789101112MyStop = 20 * pipsize //20 pips SLIF Not OnMarket AND MyConditions THENBUY 1 CONTRACT AT MARKETEntryPrice = closeStopLoss = EntryPrice - MyStopSET TARGET pPROFIT 50ENDIFIF LongOnMarket THENIF close <= StopLoss THENSELL AT MARKETENDIFENDIFthis will only exit your trade AFTER a bar closes at or under your SL level. The only drawback is that it can be UNDER, the advantage is that your SL line may be hit, but a price retracement may spare you from a losing position if the prices later goes up again and hits your TP.
11/21/2019 at 5:09 PM #113336Well… not setting a SL may make your broker apply higher margin requirements for that trade, so you could use a huge fake SL before line 7, such as:
1SET STOP pLOSS 50011/21/2019 at 5:26 PM #113339Thank you robertogozzi for your code snipet. I will give it a try. I add this in automatic trading, yes?
11/21/2019 at 5:55 PM #11334411/21/2019 at 7:03 PM #11334811/21/2019 at 8:02 PM #113358Roberto’s code does not allow for gaps between the close and the open of the next candle which is the price you will actually be buying at. This code does:
123456789101112MyStop = 20 * pipsize //20 pips SLIF Not OnMarket AND MyConditions THENBUY 1 CONTRACT AT MARKETSET TARGET pPROFIT 50ENDIFIF LongOnMarket THENstoploss = tradeprice - mystopIF close <= StopLoss THENSELL AT MARKETENDIFENDIFYou have to be aware that by only closing a trade at the close of a candle (open of the next in reality) you are leaving yourself open to price blowing straight through your stop loss value and falling massively lower before you sell which could equal a very big loss compared to your stop loss value.
11/21/2019 at 8:38 PM #113361Roberto’s code does not allow for gaps between the close and the open of the next candle which is the price you will actually be buying at.
Yes Vonasi, but your code, in case the price drops will cost 20 more pips than the previous closing price. If there’s a 30-pip gap my code will make the trade lose 30 pips, your code may cost 50 pips!
11/21/2019 at 10:13 PM #113368Not sure that I understand your maths Roberto – then again I have had a couple of glasses of wine!
Your code would assume that if the close was at a price of 1000 then the stop should be set at 980 but if there was a 19 pip gap down and the next open was at 981 then you would buy at 981 and set a stop loss at 980. You will lose money pretty much every time! However with my code if the close price was 1000 and the next open that you bought at was 980 then the stop would be at 960 and you would benefit from a low buy price and have a stop loss at a sensible level from it. If the gap was a big gap up then your code would leave a very big drop to the stop loss value whereas mine would be just the expected 20 pips.
Note: My code assumes just one position open at a time.
11/21/2019 at 10:57 PM #113377Yes, but your LongOnMarket status would only be true at the closure of next candle, maybe too late to set a 20-pip SL.
11/21/2019 at 11:32 PM #113378The long on market status is from your original code. The first time either of our codes checks to see if it should sell in a loss is at the end of close of the bar that we bought at the open of. Your code sets a stop loss based on the close of the previous bar and mine sets it based on the actual price that we bought at.
Topic moved to ProOrder forum as I think that is a better place for it.
11/22/2019 at 12:27 AM #113380My code did not set an SL after checking LongOnMarket.
11/22/2019 at 9:31 AM #113392Your code calculates the SL level at the close of a bar, then enters at the open of the next bar and then checks to see if we are below the level at the close of that bar.
My code enters at the open of the next bar and then calculates the SL level and checks to see if we are below that level at the close of that bar.
The only difference is the time that the stop loss level is calculated so that mine can be calculated when we know what price we entered at whereas yours assumes that the open of the next candle is the same as the close of the one we decided to open a trade from.
11/22/2019 at 10:01 AM #11339411/22/2019 at 10:21 AM #113395For me and my usecases the probability to be stopped too early and having a rebound is much higher then losing some pips because of a gap or for e.g. a very fast rise. Everything has its risk, but of 10 stops i maybe have only 1 gap. With this ratio i can live very well 🙂 In case of a very fast rise, i will enhance the code with sth. watching when the traded volume is rising fast to make then a direct stop.
Thank you guy for your support!
-
AuthorPosts
Find exclusive trading pro-tools on