Dear guys,
I am hoping to write a code for trading.
ema 50 x ema 200
accumulate order buy/sell on price break above / below or the previous candle (time frame)
stop at trailing.
i try very hard to find it. i hope you guys can help.
so many thanks
Please use the correct forum, I move the topic to the ProOrder support furum since you are talking about a strategy, while ProBuilder is devoted to indicators.
Thank you 🙂
What do you mean by “or the previous candle (time frame)“?
Hi.
Thank you for your reply.
What I mean is break previous price then entry order.
Thanks
To recap, you want to enter whenever there’s been a crossover of the two MA’s AND price breaks the price of the candle where the croccover occurred or the previous one?
Yes. Enter after ma cross.
Then accumulate order of contract after .
Etc. Add contract following the trend .
Condition is, price must break above or below. In order to enter . (Not the next bar)
With a trailing stop.
There you go, I tested it on DAX, 4h TF and it seems to work. Let me know if it’s doing what you wanted.
DEFPARAM CumulateOrders = true
ONCE CrossOver = 0
ONCE CrossUnder = 0
//---------------------------------------------------------------------
ONCE AvgType = 1 //1 = Ema
Ema50 = average[50,AvgType](close) //50
Ema200 = average[200,AvgType](close) //200
//---------------------------------------------------------------------
// check when faster EMA crosses over/under slower EMA
//
CrossUnder = Ema50 CROSSES UNDER Ema200
CrossOver = Ema50 CROSSES OVER Ema200
//---------------------------------------------------------------------
// enter a LONG trade
//
IF CrossOver AND Not LongOnMarket THEN
BUY 1 CONTRACT AT MARKET
ENDIF
//---------------------------------------------------------------------
// enter a SHORT trade
//
IF CrossUnder AND Not ShortOnMarket THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIF
//---------------------------------------------------------------------
// Accumulate LONG positions
//
IF LongOnMarket AND close > close[1] THEN
BUY 1 CONTRACT AT MARKET
ENDIF
//---------------------------------------------------------------------
// Accumulate SHORT positions
//
IF ShortOnMarket AND close < close[1] THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIF
//---------------------------------------------------------------------
// Trailing stop function
//by Nicolas https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function
//
trailingstart = 20 //20 trailing will start @trailinstart points profit
trailingstep = 20 //20 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-positionprice>=trailingstart*pipsize THEN
newSL = positionprice+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 positionprice-close>=trailingstart*pipsize THEN
newSL = positionprice-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
//---------------------------------------------------------------------