LinkParticipant
Senior
I am in the market with an operation for several days.
I see that these days the conditions have been given several times to re-enter the market.
What I want is that if I am in the market and the conditions to enter are met, the operation is closed and a new operation is opened.
Thanks.
It makes no sense, as the reopening price will be the closing price of the old trade and there are no advantages.
Even overnight fees won’t change.
You can easily do this by exiting and reopening after 30 bars have elapsed:
IF MyLongConditions AND LongOnMarket AND ((BarIndex - TradeIndex) >= 30) THEN
SELL AT Market
BUY AT Market
ENDIF
or you could try “cumulative orders = true” to add to your position each time conditions are met
LinkParticipant
Senior
Please, no cumulative órders.
If onmarket aNd conditions then
Sell at market
Exitshort at market
It makes no sense, as the reopening price will be the closing price of the old trade and there are no advantages.
Even overnight fees won’t change.
You can easily do this by exiting and reopening after 30 bars have elapsed:
|
|
IF MyLongConditions AND LongOnMarket AND ((BarIndex – TradeIndex) >= 30) THEN
SELL AT Market
BUY AT Market
ENDIF
|
When you code “sell at market” and “buy at market” in the same bar, ProRealtime won’t do anything. At least not in a backtest, and I think neither in reality with IG. It will just leave the old position open, because in effect, nothing changes. No orders will be executed.
I think what was implied in the original question is : How do you get a new entry price for an old position on whose basis exits (trailing stops, target profits, and so on) are being calculated. Instead of taking “positionprice” for that purpose, you can remember the closing price of a certain bar as “newpositionprice” and do all exit calculations with this one from then on.
LinkParticipant
Senior
The position should be Closed, and start a new operation.
This will make the broker happy by paying more fees.
What is the point of closing a position and immediately opening a new one? You will just have to pay the spread to the broker each time just to be in exactly the same position as you were (except now holding at a worse price than you were before). This is why if a buy order and a sell order are sent to the broker at the same time by a strategy they just cancel each other out.
Maybe he wishes to lock in profit and start a new trade with a fresh stoploss.
Sounds like a rather expensive type of trailing stop.
PaulParticipant
Master
Close and reentry in same direction in the same bar can happen with cumulated orders and maintaining 1 position-size I believe.
Some code will run into a problem, because i.e. a trailingstop won’t reset unless it’s modified for this specific issue. I use it with these adjustments for backtesting only.
I just re-checked on demo today : When you close a position and re-open it again in the same bar, nothing happens. No orders are executed, and the old position is kept open with all stops and limits as they were before.
When you close a position and re-open it again in the same bar, nothing happens.
Yes – each order cancels out the other.
Maybe he wishes to lock in profit and start a new trade with a fresh stoploss.
Then just move the stop loss – it achieves exactly the same thing but without paying the spread.
‘set stoploss’ can’t be moved right? You’d have to code in a separate exit which only activates on bar close.
I mean I personally wouldn’t do that but I can see reasons for it