Define value As Number = BarClose(symbolIndex)
Define DCL As Number = IndicatorValue(_DCLKeys(symbolIndex))
Define DCU As Number = IndicatorValue(_DCUKeys(symbolIndex))
Define DCLDistance As Number = 100 * (value - DCL) / DCL
Define DCUDistance As Number = 100 * (DCU - value) / value
If (DCLDistance > 0 And DCLDistance < _hitDistance) Then
If (_enableShorting And PositionExists(C_OPEN, symbolIndex, C_SHORT)) Then
BrokerMarket(C_BUY_TO_COVER,symbolIndex, 0, C_DAY, "Near lower channel.")
End If
If (Not PositionExists(C_OPEN, symbolIndex, C_LONG))
Define orderIndex As Number = BrokerMarket(C_BUY,symbolIndex, 0, C_DAY, "Near lower channel.")
BrokerSetStopLossPercent(orderIndex, _stopLoss, True)
BrokerSetTakeProfitPercent(orderIndex, _takeProfit, True)
BrokerSetTrailingStopLoss(orderIndex, _isPercent, _trailingStop)
End If
ElseIf (DCUDistance > 0 And DCUDistance < _hitDistance) Then
If (PositionExists(C_OPEN, symbolIndex, C_LONG))
BrokerMarket(C_SELL,symbolIndex, 0, C_DAY, "Near upper channel.")
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 channel.")
BrokerSetStopLossPercent(orderIndex, _stopLoss, True)
BrokerSetTakeProfitPercent(orderIndex, _takeProfit, True)
BrokerSetTrailingStopLoss(orderIndex, _isPercent, _trailingStop)
End If
End If
|