Sell at market instead of hitting guaranteed stop

Forums ProRealTime English forum ProOrder support Sell at market instead of hitting guaranteed stop

Viewing 15 posts - 1 through 15 (of 62 total)
  • #187554

    Hello everyone,

    Is there a way of coding an exit that becomes effective during a bar when price hits a certain level?

    I’m trying to find a way to code an exit that pretty much does the job of a stop, so I am then able to use the “STOP” command as a guaranteed stop which is set 100 points away as an emergency. This way I will avoid paying the guaranteed stop fees on the 60% of the trades I lose, but still have the reassurance that I’ll be covered if there’s a black swan event. On a 2-minute chart I am able to do this by calculating an exit/sell at market based on close hitting a certain level (see code below), but this falls down once I get to a longer timeframe because of how much price action there can be in one bar that lasts 75 minutes, for example.

    Is it possible to code an intra-bar exit?

     

     

     

    #187559

    There you go:

    In line 101 SHORTONMARKET should be used for short trades.

    #187560

    Sorry, I made a mistake copying the code. That isn’t the main problem here. With the working code, it will only exit on close. I want it to exit during a bar when price hits a certain level.

    #187564

    Did you try that or you are just guessing?

     

     

    #187566

    Hi Mike – I can’t be sure, but what I read in your description is that you want a Limit order in your exits. Thus, do similar as what you already do and can with entries, but now with exits.
    This is not 100% guaranteed for Stop, but I don’t think that is what you’re after really. You just don’t want the surprise of  having lost after the bar is finished (the longer the bar / TF the more the risk). N.b.: It is not 100% guaranteed when coming from gaps, when the price may jump over your limit – I assume that you know about this phenomenon.

    If I am correct on my assumption, it should be easier for you to code this yourself (it seems clear that you can do this) than that Roberto comes up with a snippet that doesn’t fit your needs, which also can’t be tested outside of the for you known situation for the particular instrument, on particular days and times, no ?

    Peter

    #187572

    Yes Roberto, I tried it. As I said, I copied the code mistakenly. Changing it to “shortonmarket” simply means that exiting shorts happens at the close of the bar, which I don’t want – that is my original problem. I want both longs and shorts to exit trades during a bar when they hit a certain level, but without using the “stop” command.

    #187574

    Hi Mike – I can’t be sure, but what I read in your description is that you want a Limit order in your exits. Thus, do similar as what you already do and can with entries, but now with exits.

    This is not 100% guaranteed for Stop, but I don’t think that is what you’re after really. You just don’t want the surprise of having lost after the bar is finished (the longer the bar / TF the more the risk). N.b.: It is not 100% guaranteed when coming from gaps, when the price may jump over your limit – I assume that you know about this phenomenon.

    If I am correct on my assumption, it should be easier for you to code this yourself (it seems clear that you can do this) than that Roberto comes up with a snippet that doesn’t fit your needs, which also can’t be tested outside of the for you known situation for the particular instrument, on particular days and times, no ?

    Peter

    Thanks for coming back on this Peter. I don’t understand how to use a limit order on exits. What would the syntax be?

    Currently there are only two ways I know to close trades. “set stop loss” is the obvious one, but because I want to use that command as an emergency stop that is almost never hit, I can’t use it for my everyday normal trading. The other one is “if longonmarket and close < longexit1 then sell at market”. That doesn’t work either because it uses “close” as the trigger, which as you correctly understood, will mean a massive slippage on a chart with a long timeframe. If I could replace “close” with a command that said “current price” then that would work, but as far as I know there is no command for that.

    How do I close a trade with the term “limit” on an instruction that begins with “if longonmarket and” or “if shortonmarket and”? (remember, I don’t want to use “close” to make this happen)

    #187575

    IG version

     

    If you are long and wants to exit  at a better price than current

    use sell at limit

    If you are long and wants to exit at a worse price than current

    use sell at stop

    1 user thanked author for this post.
    #187576

    IG version

    If you are long and wants to exit at a better price than current

    use sell at limit

    If you are long and wants to exit at a worse price than current

    use sell at stop

    Thanks Eric. But how do I execute that command without using the term “close”?

    The level I want my exit to be has already been derived in this way: “sl=AverageTrueRange[14]*2”

    I basically want to say “if longonmarket then sell at sl stop”, but I can’t say that because it’s incorrect syntax. What is the right way of saying this?

    #187578

    Thank you Eric. Sidenote : the other day I told I am going to use this myself, but I never did so far.
    So you, or someone else, use this for real with AutoTrading ?

    I ask, because with Manual Trading there’s the caveat of the Limit order for exit remaining after an other order for exit would occur. And in this example, this order order *will* be there (for example the normal Take Profit). With PRT IB – manually – I know perfectly what to do and what to look at, which also include settings for it (like kill all open orders for this instrument when one exits). But for IG I am at a loss of the possibilities *plus* that it works different than with IB. What I am saying is that manually (IG) I already don’t know how to deal with it. Example :

    The order day I put a Limit order for TP and when it was hit, it became a Short, the original Long still running. This is typically IG because it is possible (something with allowing Cumulate Orders – now Manually), but it is also the contrary of intuitivety.
    So next part of this example, and now related to the subject, what would one do for Strategy Code to explicitly kill that limit order, knowing that the main order has been exited. … Because if you don’t take care of that, it will keep being an order on its own, and at some stage it will be (or at least could be) filled.

    So or this must be a setting like PRT-IB has it (but no Autotrading with real brokers there), or we’d need to know how to kill that Limit order on its own.
    And notice that there can well be a difference between Backtesting (or even Demo) and Live, because it is a Broker thing and if PRT did not cover for these matters explicitly, it will just be loose running train orders …
    … And I have been in a situation indeed already (and have screenshots of it), that the Autotrading code quit because of an anomaly, while the platform did not allow for manual action. I had to sit it out … (until something filled at the broker).

    #187579

    I basically want to say “if longonmarket then sell at sl stop”, but I can’t say that because it’s incorrect syntax. What is the right way of saying this?

    Our posts crossed, but my hint would be this, for normal orders (many think that this won’t work, but it just does) :

    So what I am hinting at, is that you can use the syntax which works for “the other way around”. Not that I have the real ideas myself … 😉

    But the danger to begin with : my previous post just gave the example of the manual situation where this does NOT work out. So while this works for Autotrading, manually I’d have 5 Long and 10 Short together. Thus, two open positions. And I never change settings regarding this (while I know one exists for the (PRT- ?) IG platform) … Also, for Autotrading this is not related to DefParam CumulateOrders = true.

    #187580

    I know one exists for the (PRT- ?) IG platform)

    Yes you can do same as your code above in a manual trade, I’ve done it.

    As you say, it’s a bit scary in case it doesn’t work one time or we ‘fluff the settings or values‘ as we would be doing this in a fast trade / low TF’s … 5 secs in my case.

    #187593

    I basically want to say “if longonmarket then sell at sl stop”, but I can’t say that because it’s incorrect syntax. What is the right way of saying this?

    Our posts crossed, but my hint would be this, for normal orders (many think that this won’t work, but it just does) :

    So what I am hinting at, is that you can use the syntax which works for “the other way around”. Not that I have the real ideas myself … 😉

    But the danger to begin with : my previous post just gave the example of the manual situation where this does NOT work out. So while this works for Autotrading, manually I’d have 5 Long and 10 Short together. Thus, two open positions. And I never change settings regarding this (while I know one exists for the (PRT- ?) IG platform) … Also, for Autotrading this is not related to DefParam CumulateOrders = true.

    I’m still a bit confused 🙂

    I notice in your most recent reply you said about running two separate positions. But first of all you said I could use a ‘limit’ or ‘stop’ order to exit the market during a bar. Are these two separate solutions?

    #187595

    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!

     

    #187600
    You can just as well skip until the horizontal line more below.

    I’m still a bit confused 🙂

     

    Not you fault, Mike.
    I presented two different situations :

    1. The situation which should work with AutoTrading because other similar things work out in there too, but you need to be creative;
    2. The in fact same situation but of which I suggest that it works differently for Manual trading, and counter-intuitive on top of it.

    So my previous post was merely about NOT taking manual trading as an example, because I would not get to work the things manually which I use for a longer time with Autotrading. This, while we tend to use manual trading as an example.

    … And in additional I would not know how to do what you want with Autotrading (for exact commands) because I can’t even try them out manually.

    and (but this is a bit of a different subject)

    All what can be done with PRT-IB can not be done with PRT-IG, with as a best example a Trailing Buy.
    Not sufficiently confused yet ?
    Because I originate from PRT-IB *and* PRT was historically made for the IB environment, I know of things which work there, even for Backtesting (which *is* possible with PRT-IB (not Autotrading)) and thus I might try those things for PRT-IG Autotrading just the same. Regarding this, one has to know the difference between “broker commands” and soft-commands. The latter are pure PRT-Platform, and trailing is among that (nothing trails at the broker’s side). And it is the PRT-IB user interface which could teach me (us) these commands.


    Anyway what you would be looking for is the “other way around”

    which is from your own code. In my thinking, this would lead to your desired “stop limit” like this :

    We already know that the Buy as well as the SellShort … Limit works, because you use that yourself.
    We also already know that inverting the position works because I use that myself and which I talked about.
    … From all follows that the above should work – at least I don’t see why not, as long as your BUY with the Limit does what you want. It does not invert now, but the process really is the same. Hence :

    You already do the exact same, only in the opposite direction (SellShort – so what), and a Limit at either a Buy or SellShort works long gone, at least for me in PRT-IB. One crucial thing (and this is what I told about) : I would not be able to perform that code manually with PRT-IG, because I would be left with two separate positions – one of Risk qty Long and one of Risk qty Short.

    The pitfall in this case is that you can only test the combination. Thus what I am saying is : a Limit Buy manually will surely work (IG). A Limit SellShort will also surely work (IG). But a Limit SellShort (mind you, which is above the price !!) when a Long position is already open, will NOT work for me (IG ) without changing settings which are (for me) unknown.

    One last thing :

    could be exactly the wrong thing to do. Intuitively you may think that you don’t want to accumulate orders because because once you’re Long you want to protect yourself from more Long in case of coding errors, but 1 + -1 indeed is zero which is what you want. Side note : I already know that for normal Long and then 2x for going Short (thus invert) works regardless, but it looks to be a bug (??) and it may play against you when you want to use the Limit order(s).

    To keep in mind : In the above I talked about SellShort above the price, which would act as a Limit for Take Profit. In your case the SellShort has to be under the price so you sell at a lower price than your position, that acting as a Stop. But (!!!) leave out the Limit keyword, and you would be selling at a lower price instantly (we are all greedy for your low price you’re selling at !).

    Anything else ? … ahem, I hope I am correct on this all. And that I not double turned around matters; it is quite easy to think it out wrongly. 🙂

     

Viewing 15 posts - 1 through 15 (of 62 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login