Define value As Number = IndicatorValue(_indicatorKeys(symbolIndex))
Define BBL As Number = IndicatorValue(_BBLKeys(symbolIndex))
Define BBU As Number = IndicatorValue(_BBUKeys(symbolIndex))
If (BBL < value And value < BBL * (1 + _hitDistance)) Then
If (_enableShorting And PositionExists(C_OPEN, symbolIndex, C_SHORT)) Then
BrokerMarket(C_BUY_TO_COVER,symbolIndex, 0, C_DAY, "Near lower band.")
End If
If (Not PositionExists(C_OPEN, symbolIndex, C_LONG))
Define orderIndex As Number = BrokerMarket(C_BUY,symbolIndex, 0, C_DAY, "Near lower band.")
BrokerSetStopLossPercent(orderIndex, _stopLoss, True)
BrokerSetTakeProfitPercent(orderIndex, _takeProfit, True)
BrokerSetTrailingStopLoss(orderIndex, _isPercent, _trailingStop)
End If
ElseIf (BBU * (1 - _hitDistance) <= value And value <= BBU) Then
If (PositionExists(C_OPEN, symbolIndex, C_LONG))
BrokerMarket(C_SELL,symbolIndex, 0, C_DAY, "Near upper band.")
End If
If (_enableShorting And Not PositionExists(C_OPEN, symbolIndex, C_SHORT)) Then
Define orderIndex As Number = BrokerMarket(C_SELL_SHORT,symbolIndex, 0, C_DAY, "Near upper band.")
BrokerSetStopLossPercent(orderIndex, _stopLoss, True)
BrokerSetTakeProfitPercent(orderIndex, _takeProfit, True)
BrokerSetTrailingStopLoss(orderIndex, _isPercent, _trailingStop)
End If
End If
|