I found this which is quite similar to what i use today. Roberto, could you help me code this? 😃
- having x TP
- y SL
- z trailing sl
Why do we think so complicated? Opening strategies
I had tried something similar a long time ago… maybe this will help you?
Explain what the strategy has to do, when should it enter LONG or SHORT?
yes ofc, sorry 🙂
- at dax open. wait for 5 min candle close, if it closes GREEN, go SHORT next candle open, TP open candles low + x points.
- If open 5m candle is RED, go LONG at next candle open. TP open candles high + x points.
- SL y points, BE stop z points, Trailing z points
also put some code i found for not getting slippage if possible to use in code as well.
😀
c100 = barindex = tradeindex
spread = 1.2
If longonmarket and c100 then
priceinlong = open + spread / 2
set stop ploss sl + (positionprice - priceinlong)
set target pprofit tp - (positionprice - priceinlong)
endif
If shortonmarket and c100 then
priceinshort = open – spread / 2
set stop ploss sl + (priceinshort - positionprice)
set target pprofit tp - (priceinshort - positionprice)
endif
This is the code:
DEFPARAM CumulateOrders = False
Timeframe(default)
DAXopen = 080000
//
Timeframe(5 minute,UpdateOnClose)
Green = close > open
Red = close < open
IF OpenTime = DAXopen THEN
IF Red THEN
BUY 1 CONTRACT AT MARKET
TP = (high - close) + 5*PipSize
SL = 20
SET TARGET PROFIT TP
SET STOP pLOSS SL
ELSIF Green THEN
SELLSHORT 1 CONTRACT AT MARKET
TP = (close - low) + 5*PipSize
SL = 20
SET TARGET PROFIT TP
SET STOP pLOSS SL
ENDIF
ENDIF
//
//************************************************************************
//trailing stop function
trailingstart = 20 //trailing will start @trailinstart points profit
trailingstep = 5 //trailing step to move the "stoploss"
//reset the stoploss value
IF NOT ONMARKET THEN
newSL=0
ENDIF
//manage long positions
IF LONGONMARKET THEN
//first move (breakeven)
IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
newSL = tradeprice(1)+trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
newSL = newSL+trailingstep*pipsize
ENDIF
ENDIF
//manage short positions
IF SHORTONMARKET THEN
//first move (breakeven)
IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN
newSL = tradeprice(1)-trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
newSL = newSL-trailingstep*pipsize
ENDIF
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
//************************************************************************
As to the code you posted, lines 5 and 11 which OPEN are referencing, the current one or the one when the trade was entered?
Hi.
Whats the the deafult Timeframe for the strategy?
It must be no higher than 5 minutes.
And 5 minutes must be a multiple of it, so 5 minutes or 1 minute are both fine.