//----------------------------------------------------------------------------------------- // Jul 19, 2017 Macd-Mfi DAX 5 min // // Version 2: modified to replace built-in MFI (Money Flow Index) with // external Twiggs Money Flow // (link https://www.prorealcode.com/prorealtime-indicators/twiggs-money-flow/) //----------------------------------------------------------------------------------------- DEFPARAM CumulateOrders = False DEFPARAM FlatBefore = 090000 //no trades before 09:00:00 DEFPARAM FlatAfter = 213000 //no trades after 21:30:00 ONCE nLots = 1 //number of LOTs traded ONCE TP = 53 //53 pips Take Profit ONCE SL = 14 //14 pips Stop Loss ONCE Macd1 = 22 //22 ONCE Macd2 = 32 //32 ONCE Macd3 = 9 //9 MacdVal = MACD[Macd1,Macd2,Macd3](close) MacdSignal = MACDline[Macd1,Macd2,Macd3](close) //MfiVal = MoneyFlow[9](close) //9 //ONCE MfiLimitBuy = 3200 //3200 //ONCE MfiLimitSell = -MfiLimitBuy MfiVal, ignored, ignored, ignored = CALL "Twiggs Money Flow"[2, 21] //2=Wma 21=bars ONCE MfiLimitBuy = -0.02 //-0.02 ONCE MfiLimitSell = -MfiLimitBuy //*************************************************************************************** IF LongOnMarket THEN IF MacdSignal CROSSES UNDER MacdVal THEN SELL AT MARKET //Exit LONGs when MACD reverses southwards ENDIF ENDIF IF ShortOnMarket THEN IF MacdSignal CROSSES OVER MacdVal THEN EXITSHORT AT MARKET //Exit SHORTs when MACD reverses northwards ENDIF ENDIF //************************ NICOLAS'trailing stop code ********************************* trailingstart = 1 //1 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-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 //*************************************************************************************** // LONG trades //*************************************************************************************** a1 = close > open //BULLish bar a2 = MacdSignal CROSSES OVER MacdVal //MACD goes North a3 = (MfiVal < MfiLimitBuy)// AND (MfiVal > MfiVal[1]) //< Mfi limit AND > previous IF a1 AND a2 AND a3 THEN BUY nLots CONTRACT AT MARKET ENDIF //*************************************************************************************** // SHORT trades //*************************************************************************************** b1 = close < open //BEARish bar b2 = MacdSignal CROSSES UNDER MacdVal //MACD goes South b3 = (MfiVal > MfiLimitSell)// AND (MfiVal < MfiVal[1]) //> Mfi limit AND < previous IF b1 AND b2 AND b3 THEN SELLSHORT nLots CONTRACT AT MARKET ENDIF // SET TARGET PPROFIT TP SET STOP PLOSS SL //GRAPH MfiVal AS "Mfi"