Topics
Replies

deet
01 Jan 2023, 02:11 ( Updated at: 21 Dec 2023, 09:23 )

RE:

deet said:

it seem like i getting error that some code i am unable to accessible extension, however I do have cAlgo.API in my reference.

here the code, somewhat I unable to access from the reference

1)ClosePrices

2)ExecuteMarketOrder

3)StopLoss

4)TakeProfit


using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;



namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class RSIAndMACDRobot : Robot
    {
        [Parameter(DefaultValue = 30)]
        public int RSIThresholdLow { get; set; }

        [Parameter(DefaultValue = 70)]
        public int RSIThresholdHigh { get; set; }

        [Parameter(DefaultValue = 20)]
        public int StopLoss { get; set; }

        [Parameter(DefaultValue = 50)]
        public int TakeProfit { get; set; }

        private RelativeStrengthIndex RSI;
        private MacdCrossOver MACD;

        protected override void OnStart()
        {
            
            // 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