Replies

bjarman16
18 Apr 2023, 01:56

sorry this is the algo

 

using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
using System.Collections.Generic;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
    public class SupplyDemandRobot : Robot
    {
        [Parameter("Trade Volume", Group = "Basic Setup", DefaultValue = 10000)]
    public int TradeVolume { get; set; }
    [Parameter("Instance", DefaultValue = "Instance")]
        public string Instance { get; set; }

        private SupplyandDemand supplyAndDemand;

        protected override void OnStart()
        {
            supplyAndDemand = Indicators.GetIndicator<SupplyandDemand>(5, TimeFrame.Hour, "Red", "Lime", 20);
        }

        protected override void OnBar()
{
    // Check if price is in a supply or demand zone
    foreach (var zone in supplyAndDemand.sList)
    {
        // Check if current bar's high price is greater than zone's high price 
        // AND previous bar's high price was lower than zone's high price
        if (Bars.HighPrices.Last(1) > zone.high && Bars.HighPrices.Last(2) <= zone.high)
        {
            // Enter short trade as price entered a supply zone
            ExecuteMarketOrder(TradeType.Sell, Symbol, TradeVolume, Instance, null, null, null, "Supply Zone");
        }
    }

    foreach (var zone in supplyAndDemand.dList)
    {
        // Check if current bar's low price is lower than zone's low price 
        // AND previous bar's low price was higher than zone's low price
        if (Bars.LowPrices.Last(1) < zone.low && Bars.LowPrices.Last(2) >= zone.low)
        {
            // Enter long trade as price entered a demand zone
            ExecuteMarketOrder(TradeType.Buy, Symbol, TradeVolume, Instance, null, null, null, "Demand Zone");
        }
    }
}

    }
}


@bjarman16