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 - 46 through 60 (of 62 total)
  • #188052

    Thanks for your efforts Peter. I’ve done some more work on this. I’ve modified the code from @robertogozzi so the exits are now 99% accurate to what they were originally (I moved the “slprice” instruction to the bottom of the code), but the problem remains that trades are hitting a real stop, which means I will be charged the fee for hitting a guaranteed stop 55% of the time.  How can the below code be modified so the “if longonmarket” and “if shortonmarket” instructions can sell or exitshort without it being a stop? I’m sure “sell at market” is the key here, but I can’t find a way to use “sell at market” without creating a condition that is dependent on the close of a bar (which means I might have up to 75 minutes of slippage on an exit price).

    see the annotated lines of the code at the bottom for what I’m attempting with “sell at market”

    #188059

    Hey Mike – A few days ago I was originally ready to hand you the code (which I still could do) but a lack of time did not permit that. So yes, I definitely have this working. But anecdotal is :

    What I learned from there I applied to my own code in order to check what it would bring. And surprise !! … I worked 3-4 hours on that because something with the Limit order itself seems not to work at all. This is the same Limit for entry you use, Mike. And from there I let it rest for a while. For you the same “issue” would occur, though this is hard to check or test.

    #188061

    Mike, here you are.

     

    1 user thanked author for this post.
    #188062

    ….How can the below code be modified so the “if longonmarket” and “if shortonmarket” instructions can sell or exitshort without it being a stop?

    you can’t, as when IG receives your exit from a losing position, it can’t be but a stoploss and charges you accordingly.

     

     

     

    #188068

    ….How can the below code be modified so the “if longonmarket” and “if shortonmarket” instructions can sell or exitshort without it being a stop?

    you can’t, as when IG receives your exit from a losing position, it can’t be but a stoploss and charges you accordingly.

     

    But that isn’t true. I’ve used code for two years that exits a losing position without hitting a guaranteed stop. It is this:

     

    You can definitely “sell at market” on a losing position without hitting a stop… I’m already doing it. The “set stop loss” above at 350 is never hit during normal trading – it is only there as an emergency. But I want to find a way to sell/exit during a bar. Maybe there is a way of doing a sell/exit on close on a lower timeframe? Like a 1 minute chart? But I’m not quite sure how I’d link an exit rule between two timeframes.

     

    #188072

    you can’t, as when IG receives your exit from a losing position, it can’t be but a stoploss and charges you accordingly.

    I can’t judge that, because my StopLoss never gets hit. 😉

    And you both didn’t miss my last post ?

    #188079

    But Peter, the code you’ve submitted has same problem as before. There are no losing trades!!

    This is not what I want. In a 5-year backtest, there is a long trade which earns 35 pips which lasts nearly two years. Not only is that a massive risk if the market keeps going down, but even if in the end it comes good and you close at a 35 pip profit, you’ve spent two years burning your margin for a tiny gain.

    The point of my system is that it’s day trading with small stops and small gains. It’s little nibbles in the market with a win rate of less than 50%. It works perfectly fine as a principle. I don’t want to avoid losing exits – I just simply want to avoid paying an extra commission for losing exits.

    #188083

    Yes, they are not PENDING stop orders.

    I probably misunderstood your question as I thought you wanted to use pending orders, instead of orders at market.

     

     

    #188089

    Yes, they are not PENDING stop orders.

    I probably misunderstood your question as I thought you wanted to use pending orders, instead of orders at market.

    Roberto,

    Is there a way to code an exit rule on a 1-minute timeframe to apply to an entry on a 30 or 75-minute timeframe?

    #188093

     

     

     

    But Peter, the code you’ve submitted has same problem as before. There are no losing trades!!

    Mike, then you have a setting different than I have. 100s of losing orders. Please look back in post 187856.

    https://www.prorealcode.com/topic/sell-at-market-instead-of-hitting-guaranteed-stop/page/3/#post-187856
    (this link probably won’t work, but you will find it on the previous page)

    The screenshots in there are from this very code (though in that post I compared the two lines of exit, Pending Stop vs Buy Limit).

    I can’t do more than tell you to work hard to get this working on your side. It really works over here (PRT-IG).
    Ask ahead if you want to know something.
    I assume you took care of that “/10000” I mention in the comment in the code. If that is wrong (not in balance of some kind), nothing may work.

    Please remember what I said earlier today : there seems to be something wrong with the Buy Limit lines from your code. Not that the commands are wrong, but the Limit orders don’t work out as should; not in my own code where I now applied the same.

     

    PS: Below is a repeat of a screenshot from that post on the previous page. That would be something like 200 losses.

     

    1 user thanked author for this post.
    #188112

    Yes Mike Boorman, you can use MTF (Multiple TimeFrame) support to use more than one TF:

    You will have to use a 1-minute chart to run this strategy. It can be also be less than 1 minute or even greater, BUT the higher timeframe (or timeframes) in your code MUST (ALL, if more than one) be a multiple of the TF on the chart (named default TF). In such case you cannot run this code on a 7-minute TF as both 30 and 75 are not multiples of 7.

    #188118

    But Peter, the code you’ve submitted has same problem as before. There are no losing trades!!

    Mike, then you have a setting different than I have. 100s of losing orders. Please look back in post 187856.

    https://www.prorealcode.com/topic/sell-at-market-instead-of-hitting-guaranteed-stop/page/3/#post-187856

    (this link probably won’t work, but you will find it on the previous page)

    The screenshots in there are from this very code (though in that post I compared the two lines of exit, Pending Stop vs Buy Limit).

    I can’t do more than tell you to work hard to get this working on your side. It really works over here (PRT-IG).

    Ask ahead if you want to know something.

    I assume you took care of that “/10000” I mention in the comment in the code. If that is wrong (not in balance of some kind), nothing may work.

    Please remember what I said earlier today : there seems to be something wrong with the Buy Limit lines from your code. Not that the commands are wrong, but the Limit orders don’t work out as should; not in my own code where I now applied the same.

    PS: Below is a repeat of a screenshot from that post on the previous page. That would be something like 200 losses.

    That’s weird!! On my side there are no losing trades.

    I eliminated the risk issue by just buying/selling at £1 per point. Dividing by 100 works fine for me but to make your code work I took it out.

    The only fault I noticed with the take profit was when we added in new rules for the exits on losing positions. So I moved the exits on losing positions down to the bottom of the code and put them inside “if longonmarket/shortonmarket” (which separated them from the take profit positions, which were calculated at entry) and then that worked fine. I notice you have done the same, so I’d be surprised if it’s that issue which is making my results go strange.

    Looking at your code, I just can’t see how there could ever be a losing trade, and I’d have said that even if I hadn’t generated my results. On the “longonmarket” conditions for example, the action that is taken when they are met is to “sellshort” (which is to buy a short position). And on “shortonmarket” the action is to “buy” (which I thought could only mean to open a long position?). Have I misunderstood what “sellshort” and “buy” mean? Can they be used to exit as well?

    #188120

    Yes Mike Boorman, you can use MTF (Multiple TimeFrame) support to use more than one TF:

    You will have to use a 1-minute chart to run this strategy. It can be also be less than 1 minute or even greater, BUT the higher timeframe (or timeframes) in your code MUST (ALL, if more than one) be a multiple of the TF on the chart (named default TF). In such case you cannot run this code on a 7-minute TF as both 30 and 75 are not multiples of 7.

    Is it possible to backtest more than 1 million bars? I had an idea that maybe it was, but my version of PRT won’t let me do more than 1 million.

    #188124

    1M units are only available on IG’s real accounts, not demo ones.

     

    #188128

    So I moved the exits on losing positions down to the bottom of the code and put them inside “if longonmarket/shortonmarket” (which separated them from the take profit positions, which were calculated at entry) and then that worked fine. I notice you have done the same

    Hi Mike,

    So it must be my conclusion that you did not try my code ?
    I copied back the whole code for a reason. I applied several changes in there. And if this is only a snippet of your larger code, then later you can see how to integrate it. OK ?

    On the “longonmarket” conditions for example, the action that is taken when they are met is to “sellshort” (which is to buy a short position). And on “shortonmarket” the action is to “buy” (which I thought could only mean to open a long position?). Have I misunderstood what “sellshort” and “buy” mean? Can they be used to exit as well?

    My earlier answers in this topic were exactly about that. Sadly I made mistakes myself (not reading accurately on the Pending Stop). And of you don’t understand, no worries, I see no others who understand (which does not mean they don’t exist). As I tried to explain – I use the IB version with its way larger possibilities for orders, so one learns the possibilities, which learning is not possible with the IG.
    Let me add that you can see during the evolvement of your topic, that I myself only had the idea that what now works should be possible. Thus, pure theory. However, springing from manual trading in PRT-IB. And now the theory is practice.

    On a not unimportant side note to myself, but possibly interesting for others :
    I use 1 the second timeframe. This allows for one month of history only (1M bars). If I, for example,  make 2 seconds of that, nothing works any more (all is consistent for the 1 second TF). But also, if I would make it 2 second (or a bit more) I will always be too slow with whatever action. Now look at your own 75 minute vs 225 minutes. You have the 75 for the exact same reason, BUT you are unsatisfied with the SL response. With my code, this response is “instantly” which a Set StopLoss also would do. In the end exactly what you asked for. But also in the end exactly what my solution will be to use more history (like 2 months).

    Now try my code and let me know what comes from it. Don’t forget about the  /10000 which you probably just have to remove. It is a bit tough for me to give you a consistent version because of the contract size on one hand, but the mistakes you provided in the code on the other (you used pips of profit/sl instead of their respective targets (see the Close + SL and Close – SL parts). Then nothing works but it coincidentally could with a smaller contract size. Might it help, the contract size I used was IIRC 10000 (AUD/USD Mini). And, the vagueness (for me !) is about the number of units being unknown (you calculate that). In aftermath, I think I could see that your TP’s were 10 times smaller than mine, implying that my contract size was 10x higher.

    Let me know ! 🙂

Viewing 15 posts - 46 through 60 (of 62 total)

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