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 ! 🙂
I think things have been lost in translation here. Yes, I tried your code. And it didn’t work properly because it produced zero results. I then changed the entry to £1 per point rather than a variable stake based on risk, and then like before, the results contained zero losses in five years. Your exits come from hitting profit targets, and in some cases that takes a year.
The point I was making was that your code contains no possibility to exit a losing trade, and I can see this simply from reading it (but I did try it anyway). You have four conditions which are based on Buy and Sellshort, which ENTER the market. Buy and Sellshort are not exits.