//-------------------------------------------------------------------------
// Código principal : ALEX DAX OK
//-------------------------------------------------------------------------
REM No acumular órdenes
DEFPARAM CumulateOrders=False
REM Horario de operativa
DEFPARAM FlatBefore = 090000
DEFPARAM FlatAfter = 173000
REM Variables
mm = Exponentialaverage[8](close)
mm18 = Exponentialaverage[18](close)
uma = Highest[8](high)
umb = Lowest[8](low)
REM PARAMETERS
objetivo = 45*Pipsize
capital = 1000
risk = 0.05
REM MONEY MANAGEMENT
equity = capital+strategyprofit
maxrisk = round(equity*risk)
REM POSITION SIZE
PositionSize = abs(round((maxrisk/StopLoss)/PointValue))
REM LAST TOUCH WITH MM8 IN BULLISH MOVEMENT
IF High[1]>=mm[1] AND Low[1]<=mm[1] AND Low>mm THEN
ltp = mm[1]
if uma > mm THEN
uma = Highest[8](high)
ENDIF
IF (uma - ltp) > objetivo THEN
compra = 1
ENDIF
ENDIF
IF Low<mm then
compra = 0
uma = mm
ENDIF
REM LAST TOUCH WITH MM8 IN BEARISH MOVEMENT
IF High[1]>=mm[1] AND Low[1]<=mm[1] AND High<mm THEN
ltp = mm[1]
if umb < mm then
umb = Lowest[8](low)
endif
IF (ltp - close) > objetivo THEN
venta = 1
ENDIF
ENDIF
if high>mm then
venta = 0
umb = mm
endif
REM Anticipación a la media móvil en la entrada
plus = abs(mm - mm[1])
If compra = 1 then
BuyPrice = mm+plus
ELSE
BuyPrice = 0
ENDIF
IF venta = 1 THEN
SellPrice = mm-plus
ELSE
SellPrice = 0
ENDIF
REM LAST TRADE COUNT
LastTrade = BarIndex - TradeIndex
REM PROFIT Y STOPS
PipsProfit = 25
MinStop = 30
PresetStop = abs(mm-mm18)/PipSize
StopLoss = max(PresetStop,MinStop)
IF NOT OnMarket THEN
IF lasttrade>1 THEN
IF compra=1 THEN
BUY PositionSize SHARE AT BuyPrice LIMIT
SET STOP ploss StopLoss
SET TARGET pPROFIT PipsProfit
ENDIF
if venta=1 THEN
SELLSHORT PositionSize SHARE AT SellPrice LIMIT
SET STOP pLOSS StopLoss
SET TARGET pPROFIT PipsProfit
ENDIF
ENDIF
ENDIF