Facebook
From Flying Agouti, 3 Years ago, written in Plain Text.
This paste is a reply to Re: Re: Re: 5min Chart Strategy Script from Funky Cat - go back
Embed
# Indicators
#50 EMA and 100 EMA
#5mins Chart Strategy
#Pairs: Any

#Indicator
#EMA(50) Indicator
ema50 = EMA(applyTo: close, period:50)
period: 50)

#EMA(100) Indicator
ema100 = EMA(applyTo: close, period:100)
period: 100)

#MACD and MACD signal. 
signal.
macd = MACD(
  applyTo: close,
  
MACD(applyTo: close, fastPeriod: 12,
  
12, slowPeriod: 26
)
26)
macdSignal = MACDSignal(
  applyTo: close,
  
MACDSignal(applyTo: close, signalPeriod: 9,
  
9, fastPeriod: 12,
  
12, slowPeriod: 26
)
#Rule/Triggers
#Pip calculation
26)


#Pips calculation, 10pips = 0.0010 in (USD/USD)
pip10 = open (10 * 0.010
01)/open
pip5 = open (5 * 0.005
longEntryRule 
01)/open

#Rule
longEntryRule1 
= open > (ema50 + pip10)
longEntryRule2 = open > (ema100 + pip10)
ema100
longEntryRule3 = 0

series longEntryRule3:
longEntryRuleMacd:
  once: 0
  rest: CrossesUpwards(value: macd,crosses: macdSignal)
macd, crosses: macdSignal)

#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 = longEntryRule longEntryRule1 and longEntryRule2 and ( longEntryRule3 or longEntryRule3[1] or longEntryRule3[2] or longEntryRule3[3] or longEntryRule3[4] )
longEntryRule3

#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: low[distance]
# 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
low[distance]