Hi All,
Need some help with 5 EMA statergy that Im developing. Made some attempts but doesnt yield correct results but i think im quite close.
Short Conditions
1. Timeframe is 5 minutes for short trades
2. Plot 5 EMA on candles.
3. candles which are above 5 EMA (shouldnt even be touching 5 EMA at all. We call these as alert candle.
4. It is perfectly possible to have more than 1 alert candle, in case the next candle becomes alert candle and we ignore the previous ones.
5. Candle which breaks alert candle low, We should take a short.
6. Stop Loss becomes one of the previous alert candles high. This could be last 3,4,5 candles
7. target is going to be 3X of Stop loss.
8. When we reach 80% of target we want to close 75% of position size and trail 25% with last 3 candles low
Long Conditions
1. Timeframe is 15 minutes for Long trades
2. Plot 5 EMA on candles.
3. candles which are below 5 EMA (shouldnt even be touching 5 EMA at all. We call these as alert candles.
4. It is perfectly possible to have more than 1 alert candle, in case the next candle becomes alert candle and we ignore the previous ones.
5. Candle which breaks alert candle High, We should take a short.
6. Stop Loss becomes one of the previous alert candles Low. This could be last 3,4,5 candles
7. target is going to be 3X of Stop loss.
8. When we reach 80% of target we want to close 75% of position size and trail 25% with last 3 candles High
There you go:
DEFPARAM CumulateOrders = False
//---------------------------------------------------
// Short Timeframe
//
Timeframe(5mn,UpdateOnClose)
Ema5mn5 = average[5,1](close)
ShortAlert = low > Ema5mn5
IF ShortAlert THEN
BreakLow = low
ENDIF
ShortTrigger = close < BreakLow
IF OnMarket THEN
ShortAlert = 0
BreakLow = 0
ShortTrigger = 0
ENDIF
IF ShortTrigger THEN
SELLSHORT 1 CONTRACT AT Market
StopPriceS = highest[3](high)
TargetSizeS = (StopPriceS - close) * 3
TargetPriceS = close - TargetSizeS
FirstExitS = close - (TargetSizeS * 0.8)
SET STOP Price StopPriceS
SET TARGET Price TargetPriceS
TrailStartS = 0
ENDIF
IF ShortOnMarket THEN
IF (close <= FirstExitS) AND (TrailStartS = 0) THEN
EXITSHORT abs(CountOfPosition) * 0.75 CONTRACTS AT Market
TrailStartS = lowest[3](low)
ENDIF
IF TrailStartS THEN
TrailStartS = lowest[3](low)
SET STOP Price TrailStartS
ENDIF
ENDIF
//---------------------------------------------------
// Long Timeframe
//
Timeframe(15mn,UpdateOnClose)
Ema15mn5 = average[5,1](close)
LongAlert = high < Ema15mn5
IF LongAlert THEN
BreakHigh = high
ENDIF
LongTrigger = close > BreakHigh
IF OnMarket THEN
LongAlert = 0
Breakhigh = 0
LongTrigger = 0
ENDIF
IF LongTrigger THEN
BUY 1 CONTRACT AT Market
StopPriceL = lowest[3](low)
TargetSizeL = (close - StopPriceL) * 3
TargetPriceL = close + TargetSizeL
FirstExitL = close + (TargetSizeL * 0.8)
SET STOP Price StopPriceL
SET TARGET Price TargetPriceL
TrailStartL = 0
ENDIF
IF LongOnMarket THEN
IF (close >= FirstExitL) AND (TrailStartL = 0) THEN
SELL abs(CountOfPosition) * 0.75 CONTRACTS AT Market
TrailStartL = highest[3](high)
ENDIF
IF TrailStartL THEN
TrailStartL = highest[3](high)
SET STOP Price TrailStartL
ENDIF
ENDIF
//---------------------------------------------------
//IF ShortOnMarket THEN
//GraphOnPrice StopPriceS coloured("Red")
//GraphOnPrice TrailStartS coloured("Blue")
//ELSIF LongOnMarket THEN
//GraphOnPrice StopPriceL coloured("Red")
//GraphOnPrice TrailStartL coloured("Blue")
//ENDIF
Thanks Guys this is really helpful, appreciate your help