Trying to code RSI crossing cbot
Trying to code RSI crossing cbot
13 Apr 2023, 17:56
Hi,
I am trying to code a bot that opens a sell trade when RSI crosses from above 70, 2 bars ago, to below 70 in the previous bar. The reverse for buying and the 30 RSI level.
I have the following code building successfully but it does not execute trades:
MA = Indicators.MovingAverage(MarketSeries.Close, MAPeriod, MAType);
rsi = Indicators.RelativeStrengthIndex(Source, Periods);
protected override void OnBar()
{
if (rsi.Result.Last(2) > 70 && rsi.Result.Last(1) < 70 && Positions.FindAll(cBotLabel, TradeSymbol, TradeType.Buy).Length == 0)
{
OpenMarketOrder(TradeType.Sell, TradeSymbol, LotSize);
}
else if (rsi.Result.Last(2) < 30 && rsi.Result.Last(1) > 30 && Positions.FindAll(cBotLabel, TradeSymbol, TradeType.Sell).Length == 0)
{
OpenMarketOrder(TradeType.Buy, TradeSymbol, LotSize);
}
}
Could you please provide an example of what the correct code would be for this to work?
firemyst
01 Jun 2023, 05:52
You want to use "ExecuteMarketOrder", not "OpenMarketOrder"
@firemyst