//Risk Management
PositionSize=1
// TIME RESTRICTIONS
TimeOfDayCriteria = TIME >= 153000 AND TIME <= 220000
LongCondition ,ShortCondition = CALL "OMX_HllMvAgInd"[25*12,50*12]
BBandCondition = CALL "PRC_BBands Stop"[20,2,1]
GraphonPrice BBandCondition as "BBand" coloured (0,0,255)
if showentrycondition then
GRAPH LongCondition as "longcondition" coloured (0,255,0)
GRAPH Shortcondition as "shortcondition" coloured (255,0,0)
endif
Bbandlongcondition = close > BBandCondition
Bbandshortcondition = close < BBandCondition
GRAPH BbandlongCondition as "longcondition" coloured (0,255,0)
GRAPH -Bbandshortcondition as "shortcondition" coloured (255,0,0)
DownPeriod = SAR[0.02,0.02,0.2] > CLOSE[0]
UpPeriod = SAR[0.02,0.02,0.2] < CLOSE[0]
If LongCondition AND UpPeriod THEN
Buy PositionSize CONTRACTS AT MARKET
//SET STOP PLOSS ABS(close - S1)
SET STOP %LOSS 2
ENDIF
IF ShortCondition AND DownPeriod THEN
SELLSHORT PositionSize CONTRACTS AT MARKET
SET STOP %LOSS 2
ENDIF
IF Shortonmarket AND Bbandlongcondition THEN
EXITSHORT AT MARKET
endif
IF longonmarket AND Bbandshortcondition THEN
EXITSHORT AT MARKET
endif
activtateTrailingStop = 1
IF activtateTrailingStop THEN
takeStdOverNCandles = 5*12*4// 4 Hours
SigmaClose = STD[takeStdOverNCandles](CLOSE)
trailingstart = SigmaClose*TrailSTA // 66%
trailingstep = SigmaClose*TrailSTE //33%
IF NOT ONMARKET THEN
newSL=0
ENDIF
IF LONGONMARKET THEN
IF newSL=0 AND CLOSE-TRADEPRICE(1)>=trailingstart*PIPSIZE THEN
newSL = TRADEPRICE(1)+trailingstep*PIPSIZE
ENDIF
// SHIFT TRAILING STOP
IF newSL>0 AND CLOSE-newSL>=trailingstep*PIPSIZE THEN
newSL = newSL+trailingstep*PIPSIZE
ENDIF
ENDIF
IF newSL>0 THEN
SELL AT newSL STOP
ENDIF
ENDIF