is it possible to set profit or stop loss if the trade is 3 bars in market ?
this doesn`t work
IF ONMARKET AND (BarIndex - TradeIndex) >= 3 THEN
SET TARGET PPROFIT 20
ENDIF
IF ONMARKET AND (BarIndex - TradeIndex) >= 3 THEN
SET STOP PLOSS 20
ENDIF
Yes it would be possible, could you change and test your code with:
IF ONMARKET AND (BarIndex - TradeIndex(1)) >= 3 THEN
SET TARGET PPROFIT 20
SET STOP PLOSS 20
ENDIF
Please let me know if it doesn’t work either.
Hi Nicolas,
thanks for reply.
In Backtest it doesn´t work, i´ll give it a try in live trading.
Do your orders are “on market” ones and not pending stop or limit ones?
The ordertyp is pending stop
Ok, but do you want your pending orders to have these TP/SL values after they have been placed for at least 3 bars or do you want the TP/SL to be set on these orders that have been triggered by price already (so now on market)?
My first idea was, ich used it first for better backtest Results.. So, that the trades are Minimum 2 candles in the market..second idea is, the Orders geht This Stop after they become triggerd.. Tanks for your Patient..
If I asked you the question about kind of trades you’d like to have this condition met, it’s because pending orders can’t have more than 1 bar old : they are deleted and re-placed at each bar (as long as you put them on).
Ok, so the code I gave you should work for orders at market. Without your whole code strategy, I can’t be sure why it doesn’t work, so you can share me your code and I’ll be glad to debug it! 🙂
Hmm I get a clue from someone already affected by this.
Setting takeprofit and stoploss must be made before 3 bar elapsed, so I suggest this code instead:
IF ONMARKET AND (BarIndex - TradeIndex(1)) >= 3 THEN
SET TARGET PPROFIT 20
SET STOP PLOSS 20
ELSE
SET TARGET PPROFIT 0
SET STOP PLOSS 0
ENDIF
Which should resolved the problem I believe.
thanks a lot .. i will test it.
and this is the code without all the filters, this works on dax 15 min ..
a = 39
b = 7
Upper1 = HIGHEST[a](HIGH[1])
Lower1 = LOWEST[a](LOW[1])
Tenkan = (Upper1 + Lower1) / 2
Upper2 = HIGHEST[b](HIGH[1])
Lower2 = LOWEST[b](LOW[1])
Kijun = (Upper2 + Lower2) / 2
asien = ( TIME < 080000 )
m = 8
HOCH1 = highest[m](high)
HOCH2 = highest[m](high)
if asien then
HOCH = HOCH2
else
HOCH = HOCH1
endif
ichi = Kijun crosses over Tenkan
buy1 = HOCH[1]
if ichi then
BUY 1 CONTRACT AT HOCH stop
endif
if ichi[1] then
BUY 1 CONTRACT AT buy1 stop
endif
IF (BarIndex - TradeIndex(1)) >= 3 THEN
SET TARGET PROFIT 20
SET STOP PLOSS 40
ENDIF
Thanks for the code. I spotted some kind of “mistakes”, but don’t take it bad.
1/ HOCH1 and HOCH2 are the same variable (they return the same value).
2/ You can’t buy at a stop level of HOCH because it is the actual highest high and it’s currently moving if the price goes up. You should refer to HOCH[1] instead.
3/ As I told you already in my previous post, you need to set up your stop order at each bar because IG delete pending order at each new bar (because of no expiration possible). So when you place your pending orders into a conditional statement like you made from line 28 to 30, your order only last 1 bar (because your condition ichi[1] only occurred one time) which maybe not sufficient for them to trigger.
4/ Replace lines 32 to 35 with the code snippet I gave you.
both solutions did not work.
whatever market entrance i try, direct trade openings with on market nor on stop buy orders.
Hello Guy I’m looking for a similar code which is: after 3 bars from market open / set stop at market entry . If you can give me any help thanks James.