Replies

mlcilia
27 Aug 2020, 12:16

RE: RE:

mlcilia said:

PanagiotisCharalampous said:

Hi mlcillia,

Why do you declare these variables as global?

        public double sumx = 0, sumx2 = 0, sumy = 0, sumxy = 0;

        public double m, b;

Best Regards,

Panagiotis 

Join us on Telegram

 

I declared them there from another script I wrote. I didn't take notice of it when copy this part of my old script over haha. Thanks for your feedback.

Do you have any suggestions around this particular section below:

            DateTime start = Server.Time.AddHours(-(Periods));
            Print("start = ", start);

            DateTime end = Server.Time.AddHours(-(1));
            Print("end = ", end);

If you run the CBOT you will notice the line drawn resets as the market closes and reopens at the end of a week and at the start of the following week. 

Figured this out too.

 

Did this:

            DateTime start, end;

            if (Server.Time.DayOfWeek == DayOfWeek.Monday)
            {
                start = Server.Time.AddHours(-(Periods)-48);
                Print("start = ", start);

                end = Server.Time.AddHours(-(1)-48);
                Print("end = ", end);
            }
            else
            {
                start = Server.Time.AddHours(-(Periods));
                Print("start = ", start);

                end = Server.Time.AddHours(-(1));
                Print("end = ", end);
            }


@mlcilia

mlcilia
27 Aug 2020, 11:29

RE:

PanagiotisCharalampous said:

Hi mlcillia,

Why do you declare these variables as global?

        public double sumx = 0, sumx2 = 0, sumy = 0, sumxy = 0;

        public double m, b;

Best Regards,

Panagiotis 

Join us on Telegram

 

I declared them there from another script I wrote. I didn't take notice of it when copy this part of my old script over haha. Thanks for your feedback.

Do you have any suggestions around this particular section below:

            DateTime start = Server.Time.AddHours(-(Periods));
            Print("start = ", start);

            DateTime end = Server.Time.AddHours(-(1));
            Print("end = ", end);

If you run the CBOT you will notice the line drawn resets as the market closes and reopens at the end of a week and at the start of the following week. 


@mlcilia

mlcilia
27 Aug 2020, 11:26

Nevermind, I figured it out. It was due to the declaration of sum variables not reseting back to 0. I moved them into the OnBar calculation.

Now the next issue is start and end values as the start of the week is monday and the end of the week is friday.


@mlcilia

mlcilia
19 Aug 2020, 10:56 ( Updated at: 21 Dec 2023, 09:22 )

RE:

PanagiotisCharalampous said:

Hi mlcilia,

The problem lies in this condition

Bars.HighPrices[index] > Bars.HighPrices[index + e]

You are looking for a future value which will always be null for future values. Therefore the code will never enter into this part of the code. It will only work for past values and this is why you get past values when you add an indicator. But if you leave the indicator on the chart for a while, you will see that the indicator behaves the same way. 

Best Regards,

Panagiotis 

Join us on Telegram

 

Thanks Panagiotis, will give this ago and hopefully it works :).


@mlcilia