Multi Time Frame not waiting candle close

Created at 19 Jun 2023, 09:16
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!
SU

sue.bugg

Joined 09.01.2021

Multi Time Frame not waiting candle close
19 Jun 2023, 09:16


Hi cTrader help team. I'm having trouble with a bit of code and hoping someone can help please. I posted this earlier, but it didn't appear on the forum. Trying again. 

Across multiple time frames. Daily, 4 hour, 1 hour, 5 minute. Everything is working on the 5 minute (and final) criteria. The issue is on the Daily, 4 hour & 1 hour. Doesn't seem to be waiting for candle to close before moving to next time frame criteria. Not sure if issue is in the private bool, timeframe section with _close.Last(1). Every variation I've tried doesn't work. Must be missing something to connect the Close with these time frames. 

What cBot should do. Market currently opens 07:00 my time. The example below is made up. 

  • Look at Daily. Criteria = Close above Cloud and Fast EMA above Slow EMA. Say 13/2/23 meets this criteria. Next daily candle opens 07:00 14/2/23
  • 14/2 look at 4 hour from 07:00. Criteria = Close above Cloud. 6 x 4 hour candles 14/2. 07:00 4 hour candle meets criteria. 07:00 candle closes 10:59, next 4 hour candle opens 11:00
  • 14/2 look at 1 hour from 11:00. Criteria = Close above Cloud. 4 x 1 hour candles 14/2 from 11:00 to 15:00. If criteria not met in this time, reverts back to the next 4 hour candle close. 11:00 Close below Cloud. Criteria not met. No trade. 12:00 Close above Cloud. Criteria met. 12:00 candle closes 12:59, next 1 hour candle opens 13:00
  • 14/2 look at 5 minute from 13:00. Criteria = Close above Cloud. 12 x 5 minute candles 14/2 from 13:00 to 14:00. If criteria not met in this time, reverts back to the next 1 hour candle close. From 13:00 to 13:30 all close below cloud. Criteria not met. No trade. 13:35 Close above Cloud. Criteria met. Open Trade 13:40

What cBot seems to be doing 

  • If criteria is met at any point of the current open candle, it is triggering. 
  • Say 10/2 (Friday), daily closes below cloud. Does not meet criteria. No trade should trigger 13/2 (Monday) as the first timeframe has not met the criteria. But at sometime during 13/2 the candle goes above the cloud on the Daily, so it thinks it has met the criteria. Doesn't seem to recognize close of Last(1)

I think I've captured all relevant parts of the code below. Sorry about the formatting, it pasted like this. Thank you

 

#region Private Variables

private DataSeries _high, _low, _open, _close;
private IchimokuKinkoHyo _ichimokuKinkoHyoDaily;
private IchimokuKinkoHyo _ichimokuKinkoHyoFourH;
private IchimokuKinkoHyo _ichimokuKinkoHyoHourly;
private IchimokuKinkoHyo _ichimokuKinkoHyoFiveM;
private ExponentialMovingAverage _fastEMADaily, _slowEMADaily;

#region Private Variables

Bars _dailyBars;
Bars _h4Bars;
Bars _hourlyBars;
Bars _m5Bars;

protected override void OnStart()
        {
            // Put your initialization logic here

_dailyBars = MarketData.GetBars(TimeFrame.Daily);
_h4Bars = MarketData.GetBars(TimeFrame.Hour4);
_hourlyBars = MarketData.GetBars(TimeFrame.Hour);
_m5Bars = MarketData.GetBars(TimeFrame.Minute5);
_high = Bars.HighPrices;
_low = Bars.LowPrices;
_open = Bars.OpenPrices;
_close = Bars.ClosePrices;
_ichimokuKinkoHyoDaily = Indicators.IchimokuKinkoHyo(_dailyBars,9, 26, 52);
_ichimokuKinkoHyoFourH = Indicators.IchimokuKinkoHyo(_h4Bars,9, 26, 52);
_ichimokuKinkoHyoHourly = Indicators.IchimokuKinkoHyo(_hourlyBars,9, 26, 52);
_ichimokuKinkoHyoFiveM = Indicators.IchimokuKinkoHyo(_m5Bars,9, 26, 52);
_fastEMADaily = Indicators.ExponentialMovingAverage(SourceSeries, FastEMAPeriod);
_slowEMADaily = Indicators.ExponentialMovingAverage(SourceSeries, SlowEMAPeriod);



private bool CanTradeBuyDaily(BuyMethod method)
        {
            // Get the daily timeframe bars
               var bars = MarketData.GetBars(TimeFrame.Daily);


            // Check the relevant indicator conditions 
            if (_close.Last(1) > _ichimokuKinkoHyoDaily.SenkouSpanA.Last(27)
                && _close.Last(1) > _ichimokuKinkoHyoDaily.SenkouSpanB.Last(27)
                && _fastEMADaily.Result.Last(1) > _slowEMADaily.Result.Last(1))
                return true;
            else
                return false;
        }
        private bool CanTradeBuyFourHour(BuyMethod method)
        {
            // Get the 4 hour timeframe bars
            var bars = MarketData.GetBars(TimeFrame.Hour4);


            // Check the relevant indicator conditions 
            if (_close.Last(1) > _ichimokuKinkoHyoFourH.SenkouSpanA.Last(27)
                && _close.Last(1) > _ichimokuKinkoHyoFourH.SenkouSpanB.Last(27))
                return true;
            else
                return false;
        }
        private bool CanTradeBuyHourly(BuyMethod method)
        {
            // Get the hourly timeframe bars
            var bars = MarketData.GetBars(TimeFrame.Hour);


            // Check the relevant indicator conditions
            if (_close.Last(1) > _ichimokuKinkoHyoHourly.SenkouSpanA.Last(27)
                && _close.Last(1) > _ichimokuKinkoHyoHourly.SenkouSpanB.Last(27))
                return true;
            else
                return false;
        }
        private bool CanTradeBuyFiveMinute(BuyMethod method)
        {
            // Get the minute timeframe bars
            var bars = MarketData.GetBars(TimeFrame.Minute5);

            // Check the relevant indicator conditions 
            if (!(_close.Last(1) > _ichimokuKinkoHyoFiveM.SenkouSpanA.Last(27)
                && _close.Last(1) > _ichimokuKinkoHyoFiveM.SenkouSpanB.Last(27)))
                return false;

            return BuyPriceAction(method, bars);
        }

 


@sue.bugg
Replies

PanagiotisChar
19 Jun 2023, 09:42

Hi Sue, 

I don't think anybody is in a position to help you with such a complicated logic and just some parts of the code. If you think there is a bug in cTrader, try to simplify code and post a complete example that reproduces the problem. If you cannot figure out the correct code to implement your strategy, you can consider assigning the project to an experienced consultant.

Aieden Technologies

Need help? Join us on Telegram

 


@PanagiotisChar

sue.bugg
19 Jun 2023, 09:57 ( Updated at: 19 Jun 2023, 10:06 )

RE: full code

Hi PanagiotisChar

My apologies, I didn't think you would require full code. I was thinking the error was in the section I posted. Please see below full code. I hope you can help

Thanks

 

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

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class OriginalPAandMultiTimeFrameBuy : Robot
    {
        #region Parameters

        [Parameter()]
        public DataSeries SourceSeries { get; set; }

        [Parameter("Risk Per Trade (%)", DefaultValue = 0.2, Step = 0.1, Group = "Risk Management")]
        public double RiskPerTrade { get; set; }

        [Parameter("Spread", DefaultValue = 1.0, Group = "Risk Management")]
        public double Spread { get; set; }

        [Parameter("Take Profit", DefaultValue = 3.1, Group = "Risk Management")]
        public double TP { get; set; }

        [Parameter("Max Open Trades", DefaultValue = 1, Group = "Risk Management")]
        public int MaxOpenTrades { get; set; }

        [Parameter("Operation Type", Group = "Risk Management")]
        public OperationType OpType { get; set; }

        [Parameter("ATR Periods", DefaultValue = 12, Group = "ATR")]
        public int ATRPeriods { get; set; }

        [Parameter("ATR Multiplier", DefaultValue = 1.5, Step = 0.1, Group = "ATR")]
        public double ATRMultiplier { get; set; }

        [Parameter("ATR MA Type", Group = "ATR")]
        public MovingAverageType MAType { get; set; }

        [Parameter("Fast EMA", DefaultValue = 9, Group = "EMA")]
        public int FastEMAPeriod { get; set; }

        [Parameter("Slow EMA", DefaultValue = 21, Group = "EMA")]
        public int SlowEMAPeriod { get; set; }

        [Parameter("Use Trading Time", Group = "Trading Time")]
        public bool UseTradingTime { get; set; }

        [Parameter("Start Time", DefaultValue = "09:55", Group = "Trading Time")]
        public string StartTime { get; set; }

        [Parameter("Stop Time", DefaultValue = "21:05", Group = "Trading Time")]
        public string StopTime { get; set; }

        [Parameter("Timezone", Group = "Trading Time")]
        public Timezone UserTimeZone { get; set; }

        [Parameter("Email Address", Group = "Notifications")]
        public string EmailAddress { get; set; }

        [Parameter("Instance", DefaultValue = "MTF PartialWorking 5")]
        public string Instance { get; set; }

        #endregion Parameters

        #region Private Variables

        private AverageTrueRange _atr;
        private bool _tradeTriggered;
        private DataSeries _high, _low, _open, _close;
        private IchimokuKinkoHyo _ichimokuKinkoHyoDaily;
        private IchimokuKinkoHyo _ichimokuKinkoHyoFourH;
        private IchimokuKinkoHyo _ichimokuKinkoHyoHourly;
        private IchimokuKinkoHyo _ichimokuKinkoHyoFiveM;
        private ExponentialMovingAverage _fastEMADaily, _slowEMADaily;
        

        #endregion Private Variables

        #region Public Variables

        public enum OperationType
        {
            Alert,
            Trade,
            Both
        }

        public enum Timezone
        {
            UTC10,
            UTC11
        }

        public enum BuyMethod
        {
            Traditional,
            NonTraditional,
            Both
        }

        #endregion Public Variables

        #region Private Variables
        Bars _dailyBars;
        Bars _h4Bars;
        Bars _hourlyBars;
        Bars _m5Bars;
        #endregion

        protected override void OnStart()
        {
            // Put your initialization logic here
            _dailyBars = MarketData.GetBars(TimeFrame.Daily);
            _h4Bars = MarketData.GetBars(TimeFrame.Hour4);
            _hourlyBars = MarketData.GetBars(TimeFrame.Hour);
            _m5Bars = MarketData.GetBars(TimeFrame.Minute5);
            _atr = Indicators.AverageTrueRange(ATRPeriods, MAType);
            _high = Bars.HighPrices;
            _low = Bars.LowPrices;
            _open = Bars.OpenPrices;
            _close = Bars.ClosePrices;
            _ichimokuKinkoHyoDaily = Indicators.IchimokuKinkoHyo(_dailyBars,9, 26, 52);
            _ichimokuKinkoHyoFourH = Indicators.IchimokuKinkoHyo(_h4Bars,9, 26, 52);
            _ichimokuKinkoHyoHourly = Indicators.IchimokuKinkoHyo(_hourlyBars,9, 26, 52);
            _ichimokuKinkoHyoFiveM = Indicators.IchimokuKinkoHyo(_m5Bars,9, 26, 52);
            _fastEMADaily = Indicators.ExponentialMovingAverage(SourceSeries, FastEMAPeriod);
            _slowEMADaily = Indicators.ExponentialMovingAverage(SourceSeries, SlowEMAPeriod);

        }

        protected override void OnBar()
        {
            _tradeTriggered = false;
            if (RunningMode != RunningMode.Optimization)
                Chart.RemoveAllObjects();

            if (Positions.Count(x => x.Label == Instance) < MaxOpenTrades)
            {
                if (CanTradeBuyDaily(BuyMethod.Traditional) && CanTradeBuyFourHour(BuyMethod.Traditional) && CanTradeBuyHourly(BuyMethod.Traditional) && CanTradeBuyFiveMinute(BuyMethod.Traditional))
                {
                    if (!_tradeTriggered)
                        Print("BUY " + Symbol.Name);
                    if (!_tradeTriggered && (OpType == OperationType.Trade || OpType == OperationType.Both) && !ShutDown())
                    {
                        // Stop Loss based on ATR x #. Eg. ATR x 1.0, ATR x 1.5, ATR x 2.0, with ability for user to change
                        // Stop Loss = plus spread, with ability for user to change spread
                        // Stop Loss = round Up
                        // Stop Loss = ATR say 15, x 1.5 = 22.5, plus spread say 0.7 = 23.2, Round Up = 24 pip SL

                        var sl = Math.Ceiling((_atr.Result.Last(1) * ATRMultiplier / Symbol.PipSize) + Spread);

                        // Stop Loss based on ATR x #. Eg. ATR x 1.0, ATR x 1.5, ATR x 2.0, with ability for user to change
                        // Stop Loss = plus spread, with ability for user to change spread
                        // Stop Loss = round Up
                        // Stop Loss = ATR say 15, x 1.5 = 22.5, plus spread say 0.7 = 23.2, Round Up = 24 pip SL
                        // Stop(); stops the cBot from trading any further once a trade has entered

                        var tp = Math.Floor((sl * TP) - Spread);
                        var volume = GetVolume(sl);
                        ExecuteMarketOrder(TradeType.Buy, Symbol.Name, volume, Instance, sl, tp);
                        // Stop();
                    }

                    if (OpType == OperationType.Alert || OpType == OperationType.Both)
                    {
                        if (!IsBacktesting && !_tradeTriggered)
                        {
                            string message = string.Empty;
                            string nl = "\n";

                            message += "Symbol: " + Symbol.Name + nl;
                            message += "Time: " + Server.Time.ToShortTimeString() + nl;
                            message += "Price: " + this.Symbol.Bid.ToString() + nl;
                            message += "Signal: Buy" + nl;

                            Notifications.SendEmail(EmailAddress, EmailAddress, "BUY " + Symbol.Name, message);
                        }
                        if (RunningMode != RunningMode.Optimization)
                        {
                            Chart.DrawStaticText("Buy Text", "Buy", VerticalAlignment.Center, HorizontalAlignment.Center, Color.Green);
                            Chart.DrawVerticalLine("Buy", Bars.OpenTimes.Last(1), Color.Green);
                        }
                    }
                    _tradeTriggered = true;
                }
            }
        }
        private bool BuyPriceAction(BuyMethod method, Bars bars)
        {
            // Check the relevant method 
            switch (method)
            {
                case BuyMethod.Traditional:
                    return BuyTraditional(bars);
                case BuyMethod.NonTraditional:
                    return BuyNonTraditional(bars);
                case BuyMethod.Both:
                    return BuyBoth(bars);
            }

            return false;
        }

        private bool CanTradeBuyDaily(BuyMethod method)
        {

            // Get the daily timeframe bars
               var bars = MarketData.GetBars(TimeFrame.Daily);
                    

            // Check the relevant indicator conditions 
            if (_close.Last(1) > _ichimokuKinkoHyoDaily.SenkouSpanA.Last(27)
                && _close.Last(1) > _ichimokuKinkoHyoDaily.SenkouSpanB.Last(27)
                && _fastEMADaily.Result.Last(1) > _slowEMADaily.Result.Last(1))
                return true;
            else
                return false;
        }

        private bool CanTradeBuyFourHour(BuyMethod method)
        {

            // Get the 4 hour timeframe bars
            var bars = MarketData.GetBars(TimeFrame.Hour4);

            // Check the relevant indicator conditions 


            if (_close.Last(1) > _ichimokuKinkoHyoFourH.SenkouSpanA.Last(27)
                && _close.Last(1) > _ichimokuKinkoHyoFourH.SenkouSpanB.Last(27))
                return true;
            else
                return false;
        }
        private bool CanTradeBuyHourly(BuyMethod method)
        {

            // Get the hourly timeframe bars
            var bars = MarketData.GetBars(TimeFrame.Hour);

            // Check the relevant indicator conditions 
            

            if (_close.Last(1) > _ichimokuKinkoHyoHourly.SenkouSpanA.Last(27)
                && _close.Last(1) > _ichimokuKinkoHyoHourly.SenkouSpanB.Last(27))
                return true;
            else
                return false;
        }

        private bool CanTradeBuyFiveMinute(BuyMethod method)
        {

            // Get the minute timeframe bars
            var bars = MarketData.GetBars(TimeFrame.Minute5);

            // Check the relevant indicator conditions 
            if (!(_close.Last(1) > _ichimokuKinkoHyoFiveM.SenkouSpanA.Last(27)
                && _close.Last(1) > _ichimokuKinkoHyoFiveM.SenkouSpanB.Last(27)))
                return false;

            return BuyPriceAction(method, bars);
        }

        private bool BuyBoth(Bars bars)
        {

            if (BuyTraditional(bars))
                return true;

            if (BuyNonTraditional(bars))
                return true;

            return false;
        }

        private bool BuyNonTraditional(Bars bars)
        {
            if (bars.HighPrices.Last(2) > bars.HighPrices.Last(1) && bars.LowPrices.Last(2) < bars.LowPrices.Last(1) && bars.OpenPrices.Last(2) < bars.ClosePrices.Last(2) && bars.OpenPrices.Last(1) < bars.ClosePrices.Last(1))
                return true;

            if (bars.HighPrices.Last(2) < bars.HighPrices.Last(1) && bars.LowPrices.Last(2) > bars.LowPrices.Last(1) && bars.OpenPrices.Last(2) > bars.ClosePrices.Last(2) && bars.OpenPrices.Last(1) < bars.ClosePrices.Last(1))
                return true;

            if (bars.HighPrices.Last(3) > bars.HighPrices.Last(2) && bars.LowPrices.Last(3) > bars.LowPrices.Last(2) && bars.HighPrices.Last(1) > bars.HighPrices.Last(2) && bars.LowPrices.Last(1) > bars.LowPrices.Last(2) && bars.OpenPrices.Last(1) < bars.ClosePrices.Last(1))
                return true;

            return false;
        }

        private bool BuyTraditional(Bars bars)
        {

            if (bars.HighPrices.Last(2) > bars.HighPrices.Last(1) && bars.LowPrices.Last(2) < bars.LowPrices.Last(1) && bars.OpenPrices.Last(2) > bars.ClosePrices.Last(2) && bars.OpenPrices.Last(1) < bars.ClosePrices.Last(1))
                return true;

            if (bars.HighPrices.Last(2) < bars.HighPrices.Last(1) && bars.LowPrices.Last(2) > bars.LowPrices.Last(1) && bars.OpenPrices.Last(2) > bars.ClosePrices.Last(2) && bars.OpenPrices.Last(1) < bars.ClosePrices.Last(1))
                return true;

            return false;
        }

        protected override void OnTick()
        {
        }

        private double GetVolume(double pips)
        {
            // The volume is calculated based on the expected net loss if all SL levels trigger.
            var maxAmountRisked = Account.Balance * (RiskPerTrade / 100);
            return Symbol.NormalizeVolumeInUnits(maxAmountRisked / (pips * Symbol.PipValue), RoundingMode.Down);
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }

        private bool ShutDown()
        {
            TimeSpan tradingStarts;
            TimeSpan tradingStops;

            tradingStarts = TimeSpan.ParseExact(StartTime, "hh\\:mm", null);
            tradingStops = TimeSpan.ParseExact(StopTime, "hh\\:mm", null);

            var time = UserTimeZone == Timezone.UTC10 ? Server.Time.AddHours(10) : Server.Time.AddHours(11);
            if (tradingStarts < tradingStops)
            {
                if (time.TimeOfDay >= tradingStarts && time.TimeOfDay < tradingStops)
                {
                    //Print("cBot is shut down");
                    return false;
                }
            }
            else
            {
                if (!(time.TimeOfDay <= tradingStarts && time.TimeOfDay > tradingStops))
                {
                    //Print("cBot is shut down");
                    return false;
                }
            }

            return UseTradingTime;
        }
    }
}

 


@sue.bugg

pick
19 Jun 2023, 11:47

The first "obvious" issue I see in that code is that in "CanTradeBuyDaily", "CanTradeBuyFourHour", "CanTradeBuyHourly" and "CanTradeBuyFiveMinute" you're using "_close" for comparisons - which, at a quick glance, looks like it is always equal to the timeframe on which the bot is loaded. I see you've loaded the bars for the relevant timeframe for each method, but you're not using those bars? 


@pick

sue.bugg
19 Jun 2023, 12:27

RE:

pick said:

The first "obvious" issue I see in that code is that in "CanTradeBuyDaily", "CanTradeBuyFourHour", "CanTradeBuyHourly" and "CanTradeBuyFiveMinute" you're using "_close" for comparisons - which, at a quick glance, looks like it is always equal to the timeframe on which the bot is loaded. I see you've loaded the bars for the relevant timeframe for each method, but you're not using those bars? 

Yes, I am thinking that is the issue also, but when you say I’m not using the bars, that is the problem. I don’t know how to use them. When I do the following, (put them in the right section and repeat for 4hour & 1hour), I believe I’m just changing the name from _close to _closeDaily. I’m missing something to connect _closeDaily to the actual Daily bars

private DataSeries _closeDaily;

_closeDaily = Bars.ClosePrices;

if (_closeDaily.Last(1) > _ichimokuKinkoHyoDaily.SenkouSpanA.Last(27)

&& _closeDaily.Last(1) > _ichimokuKinkoHyoDaily.SenkouSpanB.Last(27)

 

If I use Ichimoku as example… In the bracket, the standard to put in is 9,26,52… But it accepted _dailyBars as additional entry. Which I think is what’s connecting it to the bars. The following works for Ichimoku

_ichimokuKinkoHyoDaily = Indicators.IchimokuKinkoHyo(_dailyBars,9, 26, 52);

 

If I do the following for the Close, it errors out and says “non invocable member, cannot be used like a method”

_closeDaily = Bars.ClosePrices(_dailyBars);

Basically, I don’t know how to connect the _closeDaily to the bars. Do you know what I’m missing?

Thankyou


@sue.bugg

pick
19 Jun 2023, 12:35

RE: RE:

sue.bugg said:

pick said:

The first "obvious" issue I see in that code is that in "CanTradeBuyDaily", "CanTradeBuyFourHour", "CanTradeBuyHourly" and "CanTradeBuyFiveMinute" you're using "_close" for comparisons - which, at a quick glance, looks like it is always equal to the timeframe on which the bot is loaded. I see you've loaded the bars for the relevant timeframe for each method, but you're not using those bars? 

Yes, I am thinking that is the issue also, but when you say I’m not using the bars, that is the problem. I don’t know how to use them. When I do the following, (put them in the right section and repeat for 4hour & 1hour), I believe I’m just changing the name from _close to _closeDaily. I’m missing something to connect _closeDaily to the actual Daily bars

private DataSeries _closeDaily;

_closeDaily = Bars.ClosePrices;

if (_closeDaily.Last(1) > _ichimokuKinkoHyoDaily.SenkouSpanA.Last(27)

&& _closeDaily.Last(1) > _ichimokuKinkoHyoDaily.SenkouSpanB.Last(27)

 

If I use Ichimoku as example… In the bracket, the standard to put in is 9,26,52… But it accepted _dailyBars as additional entry. Which I think is what’s connecting it to the bars. The following works for Ichimoku

_ichimokuKinkoHyoDaily = Indicators.IchimokuKinkoHyo(_dailyBars,9, 26, 52);

 

If I do the following for the Close, it errors out and says “non invocable member, cannot be used like a method”

_closeDaily = Bars.ClosePrices(_dailyBars);

Basically, I don’t know how to connect the _closeDaily to the bars. Do you know what I’m missing?

Thankyou

Have you tried using the bars you've already loaded like this?

private bool CanTradeBuyHourly(BuyMethod method)
{
	if (_hourlyBars.ClosePrices.Last(1) > _ichimokuKinkoHyoHourly.SenkouSpanA.Last(27)
		&& _hourlyBars.ClosePrices.Last(1) > _ichimokuKinkoHyoHourly.SenkouSpanB.Last(27))
		return true;
	else
		return false;
}

@pick

sue.bugg
19 Jun 2023, 12:52

RE: RE: RE:

pick said:

sue.bugg said:

pick said:

The first "obvious" issue I see in that code is that in "CanTradeBuyDaily", "CanTradeBuyFourHour", "CanTradeBuyHourly" and "CanTradeBuyFiveMinute" you're using "_close" for comparisons - which, at a quick glance, looks like it is always equal to the timeframe on which the bot is loaded. I see you've loaded the bars for the relevant timeframe for each method, but you're not using those bars? 

Yes, I am thinking that is the issue also, but when you say I’m not using the bars, that is the problem. I don’t know how to use them. When I do the following, (put them in the right section and repeat for 4hour & 1hour), I believe I’m just changing the name from _close to _closeDaily. I’m missing something to connect _closeDaily to the actual Daily bars

private DataSeries _closeDaily;

_closeDaily = Bars.ClosePrices;

if (_closeDaily.Last(1) > _ichimokuKinkoHyoDaily.SenkouSpanA.Last(27)

&& _closeDaily.Last(1) > _ichimokuKinkoHyoDaily.SenkouSpanB.Last(27)

 

If I use Ichimoku as example… In the bracket, the standard to put in is 9,26,52… But it accepted _dailyBars as additional entry. Which I think is what’s connecting it to the bars. The following works for Ichimoku

_ichimokuKinkoHyoDaily = Indicators.IchimokuKinkoHyo(_dailyBars,9, 26, 52);

 

If I do the following for the Close, it errors out and says “non invocable member, cannot be used like a method”

_closeDaily = Bars.ClosePrices(_dailyBars);

Basically, I don’t know how to connect the _closeDaily to the bars. Do you know what I’m missing?

Thankyou

Have you tried using the bars you've already loaded like this?

private bool CanTradeBuyHourly(BuyMethod method)
{
	if (_hourlyBars.ClosePrices.Last(1) > _ichimokuKinkoHyoHourly.SenkouSpanA.Last(27)
		&& _hourlyBars.ClosePrices.Last(1) > _ichimokuKinkoHyoHourly.SenkouSpanB.Last(27))
		return true;
	else
		return false;
}

You are an absolute champion. Thankyou so much. This appears to have worked. Incorrect trades have disappeared. I will test more thoroughly. But looking very good so far. Thanks again. Totally appreciate your help. 


@sue.bugg

pick
19 Jun 2023, 12:58

sue.bugg said:

You are an absolute champion. Thankyou so much. This appears to have worked. Incorrect trades have disappeared. I will test more thoroughly. But looking very good so far. Thanks again. Totally appreciate your help. 

No worries. Good luck with your bot!


@pick