Trying to code RSI crossing cbot

Created at 13 Apr 2023, 17:56
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
MR

Mr4x

Joined 12.04.2019

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?


@Mr4x
Replies

firemyst
01 Jun 2023, 05:52

You want to use "ExecuteMarketOrder", not "OpenMarketOrder"


@firemyst