// Initialize the RSI and MACD indicators
RSI = Indicators.RelativeStrengthIndex(Symbol.ClosePrices, 14);
MACD = Indicators.MacdCrossOver(Symbol.ClosePrices, 12, 26, 9);
}
protected override void OnTick()
{
// Get the current values of the RSI and MACD indicators
double rsi = RSI.Result.LastValue;
double macd = MACD.Result.LastValue;
// Check if the RSI is over the high threshold and the MACD has crossed
if (rsi > RSIThresholdHigh && macd > 0)
{
// RSI is over the high threshold and MACD has crossed, so execute a sell order
Trade.ExecuteMarketOrder(TradeType.Sell, Symbol, 1, "Sell using RSI and MACD");
Trade.StopLoss(StopLoss);
Trade.TakeProfit(TakeProfit);
}
// Check if the RSI is under the low threshold and the MACD has crossed
else if (rsi < RSIThresholdLow && macd < 0)
{
// RSI is under the low threshold and MACD has crossed, so execute a buy order
Trade.ExecuteMarketOrder(TradeType.Buy, Symbol, 1, "Buy using RSI and MACD");
Trade.StopLoss(StopLoss);
Trade.TakeProfit(TakeProfit);
}
}
}
}
deet
01 Jan 2023, 02:11 ( Updated at: 21 Dec 2023, 09:23 )
RE:
deet said:
@deet