defparam cumulateorders = false
startTradingTime = 090500
stopTradingTime = 210000
positionSize = 1
// TRADING HOURS
timeCondition = 0
IF(time >= startTradingTime) AND (time <= stopTradingTime) THEN
timeCondition = 1
ENDIF
AmountOfSigmas = 2
BollingerAmountOfPeriods = 20
BollingerBandsMeanAtCurrentClose = average[BollingerAmountOfPeriods,0](close)
standardDeviation = STD[BollingerAmountOfPeriods](close)
upperBollingerBand = BollingerBandsMeanAtCurrentClose + (AmountOfSigmas * standardDeviation)
lowerBollingerBand = BollingerBandsMeanAtCurrentClose - (AmountOfSigmas * standardDeviation)
AmountOfSigmascloseMean = 0.1
UpperBollingerCloseMean = BollingerBandsMeanAtCurrentClose + AmountOfSigmascloseMean*standardDeviation
LowerBollingerCloseMean = BollingerBandsMeanAtCurrentClose - AmountOfSigmascloseMean*standardDeviation
// Onboard Condition
CurrentValueAboveUpperBollinger = close > upperBollingerBand // BollingerUp[BollingerAmountOfPeriods](close)//upperBollingerBand //BollingerUp[BollingerAmountOfPeriods](close)
CurrentValueBelowLowerBollinger = close < lowerBollingerBand //BollingerDown[BollingerAmountOfPeriods](close)//lowerBollingerBand// BollingerDown[BollingerAmountOfPeriods](close) //
BuyShortCondition = CurrentValueAboveUpperBollinger AND timeCondition
BuyLongCondition = CurrentValueBelowLowerBollinger AND timeCondition
// EXIT CONDITION
sellLongCondition = close >= LowerBollingerCloseMean
sellShortCondition = close <= UpperBollingerCloseMean
sellstoplong = 40
sellstopshort = 40
IF BuyLongCondition AND NOT LONGONMARKET THEN
BUY positionSize PERPOINT AT MARKET
//SET STOP PLOSS sellstoplong
SET TARGET PROFIT (BollingerBandsMeanAtCurrentClose +AmountOfSigmascloseMean*standardDeviation)*pipsize // POINT WHERE IT SHOULD SELL
ENDIF
IF BuyShortCondition AND NOT SHORTONMARKET THEN
SELLSHORT positionSize PERPOINT AT MARKET
//SET STOP PLOSS sellstopshort
SET TARGET PROFIT (BollingerBandsMeanAtCurrentClose-AmountOfSigmascloseMean*standardDeviation)*pipsize // POINT WHERE IT SHOULD SELL
ENDIF