Bars.LoadMoreHistory(); cancels thread

Created at 15 Feb 2021, 15:04
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!
SH

Shares4us

Joined 01.04.2020

Bars.LoadMoreHistory(); cancels thread
15 Feb 2021, 15:04


@pangiotis
For some reason we do not want to use   Bars.LoadMoreHistoryAsync();
But the Bars.LoadMoreHistory(); keeps on killing  the current thread in an indicator.

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

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class Test : Indicator
    {
        int DoneBig = 3;

        protected override void Initialize()
        {
        }

        public override void Calculate(int index)
        {
         
            Chart.DrawStaticText("dif" , 
               Bars[index].OpenTime.Ticks + "\n" +
               Bars.OpenTimes.LastValue.Ticks + "\n" +
               Server.Time.Ticks,
               VerticalAlignment.Top,HorizontalAlignment.Right,"yellow");
            if(!IsLastBar) return;
 
            if(DoneBig==0)
                for(int i=0;i<3;i++)
                try
                {
                    Bars.LoadMoreHistory();
Print("loaded");               
                }catch(Exception ex)
                { 
                    Print(DoneBig, " ", ex.Message);
                }
            DoneBig--;

        }
    }
}

Best rgds


@Shares4us
Replies

PanagiotisCharalampous
15 Feb 2021, 15:10

Hi Shares4us,

I am not sure what is the question. Can you clarify?

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

Shares4us
15 Feb 2021, 15:16

RE:

it never reaches Print("loaded");
and that's where the indicator logic should start.

 


@Shares4us

PanagiotisCharalampous
16 Feb 2021, 10:10

Hi Shares4us,

This happens because every time bars are loaded on the chart, the indicator needs to he reinitialized and recalculated for the new bars arrived. Could you think of a different approach that would move the loading code into the Initialize() method?

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

Shares4us
16 Feb 2021, 14:33

RE:

Yes we can do that, but then you can not see if the indicator is started anymore (see other post about screenrefresh)
Print & UI handling will only fire after the initialization. You have a solution for that?

Possible solution would be to add a startdate as parameter in the GetBars / GetTicks methods so re-initialization is only needed once.

or add a 'ForceScreenUpdate' method that can be used everywhere (so also in initialize).

Best rgds, 

Ton


@Shares4us

Shares4us
16 Feb 2021, 14:33 ( Updated at: 16 Feb 2021, 15:10 )

RE:

double answer srry


@Shares4us

PanagiotisCharalampous
16 Feb 2021, 15:47

Hi Shares4us,

To offer you a better solution I need to understand what are you trying to achieve. Why do you need to load more bars the way you do it now?

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

Shares4us
16 Feb 2021, 16:23 ( Updated at: 16 Feb 2021, 17:14 )

RE:

need to load bars synchronously while the UI stays responsive

 


@Shares4us

PanagiotisCharalampous
16 Feb 2021, 16:43

Hi Shares4us,

Well in this case you need to use LoadMoreHistoryAsync().

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous