Hello need some help with coding, too dumb for this….
– after entering a long/short position, the stop is placed for a long position (1 candles back low) and for short (1 candles back high)
– after setting up stop loss, it should set the take profit with an risk reward ratio of 1:1.5 for future candles
For example:
Long/short condition requirements are met then set stop loss 1 candle back at low and set take profit by risk reward ratio 1:1.5
- example #1 long -> entry price is 100 -> lowest price on last candle is 90, set stop loss there -> set from there target profit with RR of 1.5 which would be 15 at price of 115
- example #2 short -> entry price 100 -> highes price on last candle is 110, set stop loss there -> set target profit at with rr of 1.5 which would be 15 at price of 85
something like that…..
IF MyLongConditions AND Not OnMarket THEN
BUY 1 CONTRACT AT MARKET
NewSL = low[1]
SELL AT NewSL STOP
SET TARGET $PROFIT((tradeprice(0) - NewSL)*1.5)
ENDIF
//
IF MyShortConditions AND Not OnMarket THEN
SELLSHORT 1 CONTRACT AT MARKET
NewSL = high[1]
EXITSHORT AT NewSL STOP
SET TARGET $PROFIT((NewSL - tradeprice(0))*1.5)
ENDIF
There you go:
IF MyLongConditions AND Not OnMarket THEN
BUY 1 CONTRACT AT MARKET
SL = abs(close - low[1])
TP = SL * 1.5
SET TARGET PROFIT TP
SET STOP LOSS SL
ENDIF
//
IF MyShortConditions AND Not OnMarket THEN
SELLSHORT 1 CONTRACT AT MARKET
SL = abs(close - high[1])
SET TARGET PROFIT TP
SET STOP LOSS SL
ENDIF
it’s better to use SET TARGET PROFIT and SET STOP LOSS whenever possible, because pending orders expire each bar and need to be placed again till the trade is closed.
Thank you very much Roberto, works as intended, but my strategy needs more refinements.