Define value As Number = IndicatorValue(_indicatorKeys(symbolIndex))
Define PCU As Number = IndicatorValue(_PCUKeys(symbolIndex))
Define PCL As Number = IndicatorValue(_PCLKeys(symbolIndex))
Define PCLDistance As Number = 100 * (value - PCL) / PCL
Define PCUDistance As Number = 100 * (PCU - value) / value
If (PCLDistance > 0 And PCLDistance < _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 (PCUDistance > 0 And PCUDistance < _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
|