// Force indicator Strategy - GBPUSD timefrsme 4H
// Concept Indicator by jebus89
// Coding Indicator by Vonasi
// Strategy by Maurizio Angius
DEFPARAM CumulateOrders = false
DEFPARAM Preloadbars = 1000
//************************************************************************
// Indicator
//p = period used for the average
//AveType = 0 to 6 --- 0=SMA 1=EMA 2=WMA 3=Wilder 4=Triangular 5=End point 6=Time series
//STDstart = first STD of average to be used
//STDmax = maximum STD of average to be used
//STDstep = Step levels of STD used
STDstart = 0.1
STDmax= 10
STDstep = 0.1
if close > Average[p, AveType](close) then
a = STDstart
force = 0
while a <= STDmax
if close > Average[p, AveType](close) + a*std[p](close) then
force = force + 1
a = a + STDstep
else
break
endif
wend
endif
if close < Average[p, AveType](close) then
a = -STDstart
force = 0
while a >= -STDmax
if close < Average[p, AveType](close) + a*std[p](close) then
force = force - 1
a = a - STDstep
else
break
endif
wend
endif
ONCE NbBarLimit = 10
//************************************************************************
// Money Management
Capital = 1000
Risk = 0.01
StopLoss = SL
equity = Capital + StrategyProfit
maxrisk = equity * Risk
MinSize = 1
PositionSize = max(MinSize, (maxrisk/StopLoss))
//************************************************************************
// entry long condition
l1 = force[2] = 0
l2 = force[1] > force[2]
IF l1 and l2 THEN
MyLimitBuy = high
MyIndex = Barindex
ENDIF
IF BarIndex >= MyIndex + NbBarLimit THEN
MyLimitBuy = 0
ENDIF
IF MyLimitBuy > 0 AND NOT LongOnMarket THEN
BUY PositionSize CONTRACT AT MyLimitBuy STOP
Set Stop Loss abs(close - lowest[20](low))
SL = abs(close - lowest[20](low))/POINTSIZE
ENDIF
//************************************************************************
// entry short condition
s1 = force[2] = 0
s2 = force[1] < force[2]
IF s1 and s2 THEN
MyLimitSell = low
MyIndex = Barindex
ENDIF
IF BarIndex >= MyIndex + NbBarLimit THEN
MyLimitSell = 0
ENDIF
IF MyLimitSell > 0 AND NOT ShortOnMarket THEN
SELLSHORT PositionSize CONTRACT AT MyLimitSell STOP
Set Stop Loss abs(close - highest[20](high))
SL = abs(close - highest[20](high))/POINTSIZE
ENDIF
//************************************************************************
//trailing stop function
trailingstart = Tstart //trailing will start @trailinstart points profit
trailingstep = 5 //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
//************************************************************************