//PRC_AlphaTrend | Trading system
DEFPARAM CumulateOrders = false
defparam preloadbars = 10000
Defparam Flatbefore=080000
Defparam Flatafter=220000
ONCE A = 22.0
ONCE C = 2.0
ONCE M = 13.0
MHull = average[ M ,7](close)
Bullish = MHull > MHull[1] and MHULL[1] < MHULL[2]
Bearish = MHull < MHull[1] and MHULL[1] > MHULL[2]
AP = A //Common Period
coeff = C //Multiplier
if (MoneyFlowIndex[ap]>=50) then
magic=Low[0]-AverageTrueRange[ap](close)*coeff
endif
if (MoneyFlowIndex[ap]<50) then
magic=High[0]+AverageTrueRange[ap](close)*coeff
endif
if (MoneyFlowIndex[ap]>=50 and magic<magic[1]) then
magic=magic[1]
endif
if (MoneyFlowIndex[ap]<50 and magic>magic[1]) then
magic=magic[1]
endif
if magic>magic[1] then
Flag=1
elsif magic<magic[1]then
flag=0
endif
if NOT OnMarket and Bullish and magic>magic[1] and flag<>flag[1] then
Buy 0.2 contract at Market
EndIf
If NOT OnMarket and Bearish and magic<magic[1]and flag<>flag[1] then
SellShort 0.2 contract at Market
endif
SET STOP pLOSS 100
//SET TARGET pPROFIT 20
//trailing stop function
trailingstart = 50 //trailing will start @trailinstart points profit
trailingstep = 25 //trailing step to move the "stoploss"
//reset the stoploss value
IF NOT ONMARKET THEN
newSL=0
ENDIF
//manage long positions
IF LONGONMARKET THEN
//first move (breakeven)
IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
newSL = tradeprice(1)+trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
newSL = newSL+trailingstep*pipsize
ENDIF
ENDIF
//manage short positions
IF SHORTONMARKET THEN
//first move (breakeven)
IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN
newSL = tradeprice(1)-trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
newSL = newSL-trailingstep*pipsize
ENDIF
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF