It looks like that you have coded flexible enough to be used in any way though. Once the profit taker has taken off half the quantity, what will happen with the remaining half quantity?
The stop loss is moved to break even using the average cost for the current position. Is that what you were asking? That's the second function at the bottom of the screenshot.
Maybe my imagination might be incorrect. I had the following mental image: suppose you have a long position and place your profit taker at, let's say, 5% above the buy price. If that price gets hit you take profit and sell half the position. The other half quantity remains. What exit/sell condition will you use? Will you allow it to fall down to break even (i.e. the buy price)? Or will you place some other profit taker order before selling the second half? By the way: selling half the quantity only works if you have an even quantity. Any odd quantity can't be divided in half. Maybe with spot forex this isn't an issue, but if you want to use the same code for e.g. futures contracts this might become an issue.
I forgot to add one more question. I see that the entry order is a limit order. What will happen if this limit order is not filled? Do you have any code to handle such a situation?
Love the questions you're asking The other half is going to be a trailing stop which is initially set to breakeven. There is nothing too intelligent here. And yes, it may fall down to breakeven but that's fine for me. Very good point. I'm sure I'll have to round it in some way in real life. Currently, still using my sim broker which doesn't care. I do not right now, but what I've done in the past is to set a timer (say 30 seconds) for an initial order that cancels the order if the limit is not hit in that time frame. With respect to stop limits, I have never done anything about it in the past, but I imagine that once a stop becomes active, I can do the same thing where I can convert it to a market order in 30 seconds. I expect that I'll only do this if it becomes a huge problem.
Here you have a "trading strategy" decision which you have now hardcoded in your software. As it is implicitly coded you may overlook this in the future (e.g. one year later). Making this somehow more visible in the code makes it easier to recognize. It is indeed possible to cancel an order, either by actively cancelling it, or having a "good until ..." parameter set to an appropriate time. However, I get the impression that the exit orders (stoploss, profit taker) are placed at the same time as the opening order. You would then need to cancel these orders as well, otherwise you might worst case end up with a short position where a long position was intended (or vice versa). I am using a slightly different approach here. At first I submit a limit entry order and monitor it for one minute. If it does not get filled I modify the limit price (I simply cross the bid/ask spread). Once I have confirmation that the order is filled do I submit the exit orders. I'm only familiar with IB, not with other brokers. IB allows certain parameters of an open order line to be modified (e.g. price, quantity). But it does not allow to change the order type (e.g. from limit to market order). If you want to change the order type you'll have to cancel the order and place a new one.
I agree, when I am trading other things, it will need to be pulled out. But again, I am trying to avoid designing up front. My understanding is that most systems cancel all child orders when the parent order is cancelled, at least that is the case with IB, so that is the assumption under which I'm operating and what my sim broker implements. I think I may have got the time-based management idea from you on another thread! This is a good thing to look out for, thanks.
Volume I began looking into volume today. Forex volume is a tricky beast because it isn't centralized. You can use currency futures as a good proxy but that would add a level of complexity I do not want at this time. I then realized after looking into `reqHistoricalTicks` from IB that in fact, IB doesn't give any volume data for Forex at all! I took a few walks and thought about the problem (artist rendering below) and thought about what is important. I figured what I think is really important is how often does price actually change during the bar. So that is what I did, the volume I use will be computed from the number of price changes per bar: I will leave this running overnight and see what the data looks like tomorrow. Artist rendering of me thinking
Just did a sanity check on AUDUSD volume and looks like picks up between 6-7pm Eastern which corresponds to 10-11am Sydney which is when their markets open. That's pretty much what I wanted to know though I will do more validation later. Good to know that it kinda sorta works:
hi nooby, thanks for sharing your journey. I wonder what kind of strategy you are running? What are the signals that lead to a position? Cheers!