Sell at market instead of hitting guaranteed stop
Forums › ProRealTime English forum › ProOrder support › Sell at market instead of hitting guaranteed stop
- This topic has 61 replies, 6 voices, and was last updated 3 years ago by
PeterSt.
-
-
02/05/2022 at 4:21 PM #187603
I am still convinved you did not even test my code, which is doing exactly what you want. It places a pending STOP order if the current Price is ABOVE or BELOW the exit price, otherwise: a) the STOP has already been hit or b) you need to place a LIMIT order, but this is not a stop loss, it’s a profit target!
Oops, I did not read this prior to my last post. Okay …
It is all about your b) I was just talking about and that this just should work. But also :
It is all not so easy to follow and I tend to think that you are right. My hoopla is not necessary. Still I could wonder why I am using it all the time, manually. … While it is not even about that.
Roberto, for example :
123if longonmarket and close > longexit1 thensell at longexit1 stopendifThis is part of your suggested code. But this really will execute at the close of the bar. It is, however, easy to think that it will do what you want, from the perspective of manual trading, which is unrelated to the TimeFrame (!). I just put a Stop somewhere, and you would be right. But with the Strategy code you can’t put a stop “just somewhere” … unless you apply the Limit (price) somehow. Well, that is what I tried to do.
If I am incorrect so be it. I mean, if your example works after all, then indeed I did not try it myself. This would be because I would not be able to determine LongExit1 in this case. Besides, my mind tells me that it should not happen after the close of (mind you) the next bar. It should happen IN the next bar.
02/05/2022 at 4:41 PM #187608I am still convinved you did not even test my code, which is doing exactly what you want. It places a pending STOP order if the current Price is ABOVE or BELOW the exit price, otherwise: a) the STOP has already been hit or b) you need to place a LIMIT order, but this is not a stop loss, it’s a profit target!
Hello Roberto. Thank you for trying to help me.
Your code works technically but creates much worse results, because the position can get worse in a 75-minute bar if I have to wait for close to calculate the exit. Your suggested code is still based on my original “if longonmarket and close > longexit1″ which means it doesn’t do what I want it to do. How can I start this instruction without using “close” as the trigger for the exitshort and the sell?
I want to exit the trade when price hits my predefined stop position of ATR * 2. I can do this with “set stop loss”, but if I do that, I will have to pay the fee for guaranteed stops each time it is hit. I want to use the “set stop loss” command for a much bigger emergency stop, and use “exitshort” and “sell” to exit 99% of my losing trades. So I want “exitshort” and “sell” to trigger when price hits the ATR * 2 figure (that’s ATR * 2 at the START of the trade – it does not update during the trade), and I want this to happen during a bar, not on close. To put it another way, I want to treat it like a take profit target for a losing position, so it’s effectively a “take loss” target. Do you know how to do this?
02/05/2022 at 4:46 PM #187609Now we are all cross posting. 🙂
To put it another way, I want to treat it like a take profit target for a losing position, so it’s effectively a “take loss” target. Do you know how to do this?
Without a long-winded post this time :
12risk=100/slSellShort risk PERPOINT AT limitSTOP limit // Mind the limitSTOP.02/05/2022 at 5:23 PM #187611SellShort risk PERPOINT AT limitSTOP limit
That doesn’t work. To have two conflicting entry criterias next to each other was always going to be a problem. If I understand you correctly, you’re proposing that underneath my take profit criteria on a long trade, I would put a loss criteria underneath like this?
Code12BUY risk PERPOINT AT limitbuy limitSellShort risk PERPOINT AT sl limit02/05/2022 at 5:54 PM #187612Yes, like that.you’re proposing that underneath my take profit criteria on a long trade
That would not be Take Profit criteria (for the code example you just gave); that would be Buy criteria. But even Take Profit Criteria (Limit) would work together with the Buy Limit and Sell Short Limit. I do this some times (IB).
That doesn’t work. To have two conflicting entry criterias
They are not conflicting at all ? they would if the Limit keyword is omitted.
What is the (error-)message you receive from it ?02/05/2022 at 8:06 PM #187614The use of CLOSE in my code has nothing to do with waiting for the closing of the bar. Its purpose is just to make sure it’s a STOP order.
Pending orders last a whole bar and can get triggered while the new candle is forming.
02/05/2022 at 10:21 PM #187623The use of CLOSE in my code has nothing to do with waiting for the closing of the bar. Its purpose is just to make sure it’s a STOP order.
Pending orders last a whole bar and can get triggered while the new candle is forming.
Roberto,
Once I remove my original “set stop loss” and rely entirely on exiting trades using your code, I get incorrect results (see screengrab). As a reminder, here is the code in full.
Mike code123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103DEFPARAM CumulateOrders = FalseStarttime = 000000Limitentrytime = 220000Exclude=time >=020000 and time <=050000timeframe(225 minutes,updateonclose)if MACD[12,26,9](close) >0 thenmac4flag=1endifif MACD[12,26,9](close) <0 thenmac4flag=-1endifif close >ExponentialAverage[5](high) thenupperflag=1endifif close <ExponentialAverage[5](high) and close >ExponentialAverage[5](low) thenupperflag=0endifif close < ExponentialAverage[5](low) thenupperflag=-1endiftimeframe(75 minutes,default)Averagecrosslong= Average[8](close) CROSSES OVER Average[20](close)Averagecrossshort= Average[8](close) CROSSES under Average[20](close)ONCE crossflag=0ONCE avgflag=0if close > ExponentialAverage[5](high) thenavgflag=1endifif close < ExponentialAverage[5](low)thenavgflag=-1endiflongentry=0if avgflag=1 and averagecrosslong thencrossflag=1endifc2 = close > Average[50](close)longentry= c2limitbuy=ExponentialAverage[5](low)if not onmarket and crossflag=1 and longentry=1 and mac4flag=1 and upperflag=1 and time >=StartTime and time <LimitEntrytime and not exclude thensl=AverageTrueRange[14]*2tp=sl * 1.5slpricelong= close - sl//Set stop loss slrisk=100/slBUY risk PERPOINT AT limitbuy limitendifshortentry=0if avgflag=-1 and averagecrossshort thencrossflag=-1endifd2 = close < Average[50](close)shortentry= d2limitsell=ExponentialAverage[5](high)if not onmarket and crossflag=-1 and shortentry and mac4flag=-1 and upperflag=-1 and time >=StartTime and time <LimitEntrytime and not exclude thensl=AverageTrueRange[14]*2tp=sl * 1.5Set target profit tpslpriceshort = close + sl//Set stop loss slrisk=100/slSellshort risk PERPOINT AT limitsell limitendifif onmarket thencrossflag=0endifif longonmarket and close > slpricelong thensell at sl stopendifif shortonmarket and close < slpriceshort thenexitshort at sl stopendif02/06/2022 at 12:49 AM #187628@ Mike Boorman
Your code is executed at the end of each bar, suppose that at the end of a certain bar your conditions are true so you are LongOnMarket and Close > LongExit1 (LongExit1 = SLPrice = Close – ATR[14]*2) then Roberto’s code will place a STOP order on LongExit1.
This STOP order is a PENDING order that starts at the beginning of the new bar and is valid until the end of that bar. When the Close hits the pending Stop order IN this bar, it is executed (equivalent to a StopLoss).
If the Close does not touch the pending Stop order, it will be placed again every next bar (if your conditions are still true).
1 user thanked author for this post.
02/06/2022 at 7:12 AM #187631If the Close does not touch the pending Stop order, it will be placed again every next bar (if your conditions are still true).
Hi JS – Maybe you can rephrase that. Because it is there where it IMHO goes “wrong”. Why would a close not (or do) “touch” a pending stop order ? no such thing exists. And just saying : a pending stop order touching a close also does not exist. There is not even such a thing as a pending stop order unless
- It is a Market order placed in a closed market (and assumed that is allowed by the broker and settings);
- It is a Market Order waiting to get filled;
- It has a price limit attached to it, possibly even a time limit (kill end of day).
We are talking about #3 and nothing else that I can see. And this is the same as you putting a Stop Order manually, which has a price limit attached to it. There is nothing else for “pending stop” … (compare #1 and #2).
See the two subsequent attachments. I take it that you will agree that this is a Stop order. I place it at, well, a PRICE. Right ? at 1.14509. This makes it a Limit order to begin with.
This is not comparable at all to a Stop (without Limit) order in ProRealCode. That would make it a Market order, which for ProRealCode implies “Execute right at the start of the next bar” (when my code is handed to the broker system) and where it will wait to get filled. Net this means :If I place a Stop Order in my code, and I will do that when my whatever conditions are met, it WILL get filled, unless nobody wants to take my (market) price. But that not assumed, it will get filled during the execute of the next bar, most probably within tenths of seconds.
What I would want, no wait, what Mike wants (ne coincidentally heading for the very same), is that the order is only given to the exchange (yep) when a certain price is met. Thus, my code is handed to the broker, but it didn’t tell to sell (when Long). It only asks to sell when a price will be met. And if that does not happen in the next bar, then I happily own the stock (etc.) still. And THEN I might like to kill the Limit Order. Btw, manually I would kill in the middle of the bar (cross away at any random time), but with PRC that is not possible again. But beware, because with the same (so far according to Mike conflicting orders/techniques) I would be able to do that too. Admitted, all still theories.02/06/2022 at 7:39 AM #187636Something which would count for me surely :
If we don’t (and equally) fully understand how the PRT software interacts with the “candle system”, and when the code is executed and when it is executed again, and what can happen meanwhile within the time (of the candle) that our PRC code is not in control …
… then it is very hard to make something of this and discuss it.
but
Applying dozens of trades daily, which is not scalping at all, done in an environment which allows to learn the possibilities of PRT on one side and one of the broker systems on the other, and using a broker system with a plethora of possibilities to begin with and which is not IG …
… helps. Well, I think it does. 🙂Below the current possibilities of PRT, which is a subset of what IB allows. Well, partly, because PRT adds “soft” orders as well. And just saying : what a broker allows for is almost all “soft” only, but a platform has to comply to that. … Within that, trickery is possible because most comprises of elements and often several elements can be applied subsequently, without they know about each other. Example : a Limit order to Buy and a Limit order to SellShort at the very same time. Which executes first is to wait and see, but if the SellShort is fist and put above the Buy (Long) they will execute both if my expectation of the market is right (price drops, but at a certain level it will retrace). So I executed two orders while I wasn’t there (both Limit orders), both set in advance. I will end up with a Long, after having earned on the Short.
This latter is a part of my perception of the system as a whole. In the earlier post I told I could not do that in IG, probably because of wrong settings somewhere. But in IB I do this regularly, especially which all is swinging and I have nothing to do but having a bit of fun with certainty. Now, if you can’t copy this way of trading (or are sure it can’t exist) then don’t expect that I can make clear what, well, I like to make clear. 🙂
If you miss some trade buttons in IG settings, it does not mean that it can’t be done by PRC code.Ready to learn more, really …
PeterPS: JS, see the last line in the attachment. I deliberately copied that in. That looks like what you were saying. But is it what you referred to ? (again, ready to learn more)
02/06/2022 at 8:15 AM #187640Hi Peter,
You can see a pending STOP order as a temporary StopLoss that is valid for 1 bar.
Just like with a StopLoss, this pending stop order does not have to be hit immediately (preferably not at all) but if it has not been hit then it must be placed again because pending stop orders are only valid for 1 bar.
So, if at the end of a certain bar your conditions are true, then with this pending stop order you place a kind of temporary StopLoss which is valid for the new (next) bar.
02/06/2022 at 8:57 AM #18764102/06/2022 at 9:43 AM #187644@ Mike Boorman
Your code is executed at the end of each bar, suppose that at the end of a certain bar your conditions are true so you are LongOnMarket and Close > LongExit1 (LongExit1 = SLPrice = Close – ATR[14]*2) then Roberto’s code will place a STOP order on LongExit1.
This STOP order is a PENDING order that starts at the beginning of the new bar and is valid until the end of that bar. When the Close hits the pending Stop order IN this bar, it is executed (equivalent to a StopLoss).
If the Close does not touch the pending Stop order, it will be placed again every next bar (if your conditions are still true).
Okay, so what is it in the code that means that Roberto’s conditions are hit immediately for shorts (no trade of over one bar), and almost never hit for longs? (there’s a trade of over 1,000 bars, for example, which should only be 42). You can see from my screengrab the list of trades which shows the unreliable results. Three or four of those results do actually mirror what they were when I used the “set stop loss” command to execute the same exit conditions, but the great majority do not. Would you be so kind as to help me fix this so the stop order mirrors the stop loss more accurately?
Mike Code123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103DEFPARAM CumulateOrders = FalseStarttime = 000000Limitentrytime = 220000Exclude=time >=020000 and time <=050000timeframe(225 minutes,updateonclose)if MACD[12,26,9](close) >0 thenmac4flag=1endifif MACD[12,26,9](close) <0 thenmac4flag=-1endifif close >ExponentialAverage[5](high) thenupperflag=1endifif close <ExponentialAverage[5](high) and close >ExponentialAverage[5](low) thenupperflag=0endifif close < ExponentialAverage[5](low) thenupperflag=-1endiftimeframe(75 minutes,default)Averagecrosslong= Average[8](close) CROSSES OVER Average[20](close)Averagecrossshort= Average[8](close) CROSSES under Average[20](close)ONCE crossflag=0ONCE avgflag=0if close > ExponentialAverage[5](high) thenavgflag=1endifif close < ExponentialAverage[5](low)thenavgflag=-1endiflongentry=0if avgflag=1 and averagecrosslong thencrossflag=1endifc2 = close > Average[50](close)longentry= c2limitbuy=ExponentialAverage[5](low)if not onmarket and crossflag=1 and longentry=1 and mac4flag=1 and upperflag=1 and time >=StartTime and time <LimitEntrytime and not exclude thensl=AverageTrueRange[14]*2tp=sl * 1.5slpricelong= close - sl//Set stop loss slrisk=100/slBUY risk PERPOINT AT limitbuy limitendifshortentry=0if avgflag=-1 and averagecrossshort thencrossflag=-1endifd2 = close < Average[50](close)shortentry= d2limitsell=ExponentialAverage[5](high)if not onmarket and crossflag=-1 and shortentry and mac4flag=-1 and upperflag=-1 and time >=StartTime and time <LimitEntrytime and not exclude thensl=AverageTrueRange[14]*2tp=sl * 1.5Set target profit tpslpriceshort = close + sl//Set stop loss slrisk=100/slSellshort risk PERPOINT AT limitsell limitendifif onmarket thencrossflag=0endifif longonmarket and close > slpricelong thensell at sl stopendifif shortonmarket and close < slpriceshort thenexitshort at sl stopendif02/06/2022 at 9:45 PM #18770102/07/2022 at 6:18 AM #187710Oh boy, it only now appears that I can’t even read.
1sell at longexit1 stopwhy did I read this all the time as
1Set Stop Lossof any form ? I really have no clue. But stupid me, mea culpa, apologies, anything.
Massive thanks JS for holding on. Roberto, you too of course.No excuses, but I think I can see how I made the mistake of not reading well (and with that missing all explanations on top of it, like “when the stop is touched” etc. – grrr) :
- I saw Mike using the Limit;
- I am heading myself to using it (so I focused on that);
- In practice, with manual trading I may have used the Stop Loss maybe 5 times, while using Limit Orders all the time (what about 1000s).
If you’re still interested, Ad 3.:
Which for me confuses and obfuscates everything, because the Limit orders are exactly not working out for me on IG. So my focus was merely on how to let that work, instead of, well, READING ?
duhIn addition I don’t think I ever investigated the Sell at n Stop. But now I know …
🙂… And I suppose I can just as well use that, never mind it should work out the same as my proposed Limit. That is … Let’s first try to solve Mike’s problem. If I am not too much disturbing (stoorzender for JS).
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on