Define value As Number = IndicatorValue(_indicatorKeys(symbolIndex))
Define ENVL As Number = IndicatorValue(_ENVLKeys(symbolIndex))
Define ENVU As Number = IndicatorValue(_ENVUKeys(symbolIndex))
Define ENVLDistance As Number = 100 * (value - ENVL) / ENVL
Define ENVUDistance As Number = 100 * (ENVU - value) / value
If (ENVLDistance > 0 And ENVLDistance < _hitDistance) Then
If (_enableShorting And PositionExists(C_OPEN, symbolIndex, C_SHORT)) Then
BrokerMarket(C_BUY_TO_COVER,symbolIndex, 0, C_GTC, "Near lower envelope.")
End If
If (Not PositionExists(C_OPEN, symbolIndex, C_LONG))
Define orderIndex As Number = BrokerMarket(C_BUY,symbolIndex, 0, C_GTC, "Near lower envelope.")
BrokerSetStopLossPercent(orderIndex, _stopLoss, True)
BrokerSetTakeProfitPercent(orderIndex, _takeProfit, True)
BrokerSetTrailingStopLoss(orderIndex, _isPercent, _trailingStop)
End If
ElseIf (ENVUDistance > 0 And ENVUDistance < _hitDistance) Then
If (PositionExists(C_OPEN, symbolIndex, C_LONG))
BrokerMarket(C_SELL,symbolIndex, 0, C_GTC, "Near upper envelope.")
End If
If (_enableShorting And Not PositionExists(C_OPEN, symbolIndex, C_SHORT)) Then
Define orderIndex As Number = BrokerMarket(C_SELL_SHORT,symbolIndex, 0, C_GTC, "Near upper envelope.")
BrokerSetStopLossPercent(orderIndex, _stopLoss, True)
BrokerSetTakeProfitPercent(orderIndex, _takeProfit, True)
BrokerSetTrailingStopLoss(orderIndex, _isPercent, _trailingStop)
End If
End If
|