# Indicators #50 EMA and 100 EMA ema50 = EMA(applyTo: close, period:50) ema100 = EMA(applyTo: close, period:100) #MACD and MACD signal. macd = MACD( applyTo: close, fastPeriod: 12, slowPeriod: 26 ) macdSignal = MACDSignal( applyTo: close, signalPeriod: 9, fastPeriod: 12, slowPeriod: 26 ) #Rule/Triggers, 10pips = 0.0010 in EUR/USD #Pip calculation pip10 = 10* ((1/100)/(open)) pip5 = 5 * ((1/100)/(open)) longEntryRule = open > (ema50 + pip10) longEntryRule2 = open > (ema100 + pip10) series longEntryRule3: once: 0 rest: CrossesUpwards(value: macd,crosses: macdSignal) #Final Long Entry Rule FinalLongEntryRule = longEntryRule and longEntryRule2 and ( longEntryRule3 or longEntryRule3[1] or longEntryRule3[2] or longEntryRule3[3] or longEntryRule3[4] ) #Setting initial Stop period = 5 InitialStop = open for distance from 1 to (period - 1) isNewLow = low[distance] < InitialStop InitialStop = low[distance] if isNewLow else InitialStop # Signals series StopRepeat: once: 0 rest: 1 if (FinalLongEntryRule and StopRepeat == 0) else StopRepeat series TakeProfit: once: 0 rest : ((open - InitialStop) * 2 + open) if ((FinalLongEntryRule) and StopRepeat == 1) else TakeProfit if (open > TakeProfit or open < InitialStop) update StopRepeat: 0 if (open <= TakeProfit or open >= InitialStop) update StopRepeat: 2 #Final Long Exit Rule FinalLongExitRule = open > TakeProfit or open < InitialStop enter long when FinalLongEntryRule exit long when FinalLongExitRule