#50 EMA and 100 EMA
#Pairs: Any
#Indicator
#EMA(50) Indicator
ema50 = EMA(applyTo: close,
#EMA(100) Indicator
ema100 = EMA(applyTo: close,
#MACD and MACD
macd =
applyTo: close,
)
macdSignal =
applyTo: close,
)
#Rule/Triggers
#Pip calculation
#Pips calculation, 10pips = 0.0010 in (USD/USD)
pip10 =
pip5 =
longEntryRule
#Rule
longEntryRule1 = open > (ema50 + pip10)
longEntryRule2 = open >
longEntryRule3 = 0
series
once: 0
rest: CrossesUpwards(value:
#MACD crosses to positive within the last five bars, otherwise wait for the next
longEntryRule3 = longEntryRuleMacd or longEntryRuleMacd[1] or longEntryRuleMacd[2] or longEntryRuleMacd[3] or longEntryRuleMacd[4]
#Final Long Entry Rule
FinalLongEntryRule =
#Setting initial Stop
period = 5
series stopLoss:
once: open
rest: open
for distance from 1 to (period - 1)
if low[distance] < stopLoss update stopLoss: low[distance]
#Setting initial Stop
period = 5
series StopLoss:
once: open
rest: open
for distance from 1 to (period - 1)
if low[distance] < StopLoss update StopLoss:
# Signals
#StopRepeat is to protect Take profit and StopLoss base on open postions.
series StopRepeat:
once: 0
rest: 1 if (FinalLongEntryRule and (StopRepeat == 0)) else StopRepeat
series InitialStop:
once: open
rest: StopLoss if (StopRepeat == 1) else InitialStop
series TakeProfit:
once: 0
rest : ((open - InitialStop) * 2 + open) if (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 or open < (ema50-pip10)
enter long when FinalLongEntryRule
exit long when FinalLongExitRule