# 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
#Pip calculation
pip10 = open * 0.010
pip5 = open * 0.005
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
series StopLoss:
once: 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
Replies to Re: Re: Re: 5min Chart Strategy Script
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}