Why does printing this give me random number ?

Created at 04 Jan 2024, 22:20
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!
MI

mihlali700

Joined 22.12.2023

Why does printing this give me random number ?
04 Jan 2024, 22:20


can someone help me understand why printing the result of this will give me a different number every tick with a wild variation ?  

double HighValue = BarsDaily.HighPrices[barsDailyIndex];
               double LowValue = BarsDaily.LowPrices[barsDailyIndex];
               double CloseValue = BarsDaily.ClosePrices[barsDailyIndex];
               double PPValue = (HighValue + LowValue + CloseValue) / 3;
               double S1Value = (PPValue * 2) - HighValue;
               double S2Value = PPValue - (HighValue - LowValue);
               double S3Value = LowValue - 2 * (HighValue - PPValue);
               double R1Value = (PPValue * 2) - LowValue;
               double R2Value = PPValue + (HighValue - LowValue);
               double R3Value = HighValue + 2 * (PPValue - LowValue);
               
               var currentprice = Bars.ClosePrices[index-1];
               var PPPips = Math.Abs((currentprice - PPValue) / Symbol.PipSize);
               var S1Pips = Math.Abs((currentprice - S1Value) / Symbol.PipSize);
               var S2Pips = Math.Abs((currentprice - S2Value) / Symbol.PipSize);
               var S3Pips = Math.Abs((currentprice - S3Value) / Symbol.PipSize);
               var R1Pips = Math.Abs((currentprice - R1Value) / Symbol.PipSize);
               var R2Pips = Math.Abs((currentprice - R2Value) / Symbol.PipSize);
               var R3Pips = Math.Abs((currentprice - R3Value) / Symbol.PipSize);
               
               
               Print(PPPips);

@mihlali700
Replies

PanagiotisCharalampous
05 Jan 2024, 06:53

Hi there,

The close price changes on every tick therefore it is expected that the results would change. Can you explain to us what your expectation is?

Best regards,

Panagiotis


@PanagiotisCharalampous

mihlali700
05 Jan 2024, 14:36

RE: Why does printing this give me random number ?

PanagiotisCharalampous said: 

Hi there,

The close price changes on every tick therefore it is expected that the results would change. Can you explain to us what your expectation is?

Best regards,

Panagiotis

No I understand why it would be different at every tick but the way its different makes I unusable , I expect the numbers printing to be somewhat close to each other instead they are not, they are widely different with it even printing “NaN” 


@mihlali700

mihlali700
05 Jan 2024, 14:36

RE: Why does printing this give me random number ?

PanagiotisCharalampous said: 

Hi there,

The close price changes on every tick therefore it is expected that the results would change. Can you explain to us what your expectation is?

Best regards,

Panagiotis

No I understand why it would be different at every tick but the way its different makes I unusable , I expect the numbers printing to be somewhat close to each other instead they are not, they are widely different with it even printing “NaN” 


@mihlali700

PanagiotisCharalampous
06 Jan 2024, 08:23

RE: RE: Why does printing this give me random number ?

mihlali700 said: 

PanagiotisCharalampous said: 

Hi there,

The close price changes on every tick therefore it is expected that the results would change. Can you explain to us what your expectation is?

Best regards,

Panagiotis

No I understand why it would be different at every tick but the way its different makes I unusable , I expect the numbers printing to be somewhat close to each other instead they are not, they are widely different with it even printing “NaN” 

It's obviously a logical bug on your side but it's hard to tell by a code snippet. We are just guessing. You would need to provide more information in order to get more help. Post at least the following

  1. The full indicator code
  2. Screenshots of the values you get.
  3. The values you would expect to get instead and an explanation why you expect them.

 


@PanagiotisCharalampous

PanagiotisCharalampous
06 Jan 2024, 08:23

RE: RE: Why does printing this give me random number ?

mihlali700 said: 

PanagiotisCharalampous said: 

Hi there,

The close price changes on every tick therefore it is expected that the results would change. Can you explain to us what your expectation is?

Best regards,

Panagiotis

No I understand why it would be different at every tick but the way its different makes I unusable , I expect the numbers printing to be somewhat close to each other instead they are not, they are widely different with it even printing “NaN” 

It's obviously a logical bug on your side but it's hard to tell by a code snippet. We are just guessing. You would need to provide more information in order to get more help. Post at least the following

  1. The full indicator code
  2. Screenshots of the values you get.
  3. The values you would expect to get instead and an explanation why you expect them.

 


@PanagiotisCharalampous

mihlali700
06 Jan 2024, 08:38

RE: RE: RE: Why does printing this give me random number ?

PanagiotisCharalampous said: 

mihlali700 said: 

PanagiotisCharalampous said: 

Hi there,

The close price changes on every tick therefore it is expected that the results would change. Can you explain to us what your expectation is?

Best regards,

Panagiotis

No I understand why it would be different at every tick but the way its different makes I unusable , I expect the numbers printing to be somewhat close to each other instead they are not, they are widely different with it even printing “NaN” 

It's obviously a logical bug on your side but it's hard to tell by a code snippet. We are just guessing. You would need to provide more information in order to get more help. Post at least the following

  1. The full indicator code
  2. Screenshots of the values you get.
  3. The values you would expect to get instead and an explanation why you expect them.

 

What I'm trying to print out is the difference of pips between two prices , which is PPValue and the currentprice which gives Pppips but since it prints out like this I cant really nail down why theres a huge variance in the values printed 


Here is the full code :

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AutoRescale = false, AccessRights = AccessRights.None)]
    public class Pivots : Indicator
    {
        
        [Parameter(DefaultValue = 10)]
        public int AlertPips { get; set; }
        
        [Parameter("Pivot Calculation Method", DefaultValue = PivotCalculationMethod.Standard)]
        public PivotCalculationMethod CalculationMethod { get; set; }

        public enum PivotCalculationMethod
        {
        Standard,
        Fibonacci,
        Woodie,
         }

        private Bars BarsDaily;
        
        protected override void Initialize()
        {
           
        BarsDaily = MarketData.GetBars(TimeFrame.Daily);

        }

        public override void Calculate(int index)
        {
                switch (CalculationMethod)
                {
                    case PivotCalculationMethod.Standard:
                   //  Standard
                   Standardpivotformula(index);
                    break;
                    case PivotCalculationMethod.Fibonacci:
                    FibonacciPivotformula(index);
                    break;
                    case PivotCalculationMethod.Woodie:
                    // Woodie  forumla 
                    WoodiePivotFormula(index);
                    break;
                 }
        
        
        }
        
         private void DrawHorizontalLine(string name, DateTime startTime, double startY, DateTime endTime, double endY, Color color)
        {
            var trendLine = Chart.DrawTrendLine(name, startTime, startY, endTime, endY, color, 2, LineStyle.Solid);
            trendLine.IsInteractive = true;
        }
        
        private void Standardpivotformula(int index) 
        {
        
          if (Bars.OpenTimes[index].Date != Bars.OpenTimes[index - 1].Date)
            {
                var barsDailyIndex = BarsDaily.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
                // Find the start and end of the current day using Bars
                DateTime startOfDay = Bars.OpenTimes[index].Date;
                DateTime endOfDay = startOfDay.AddHours(23).AddMinutes(59).AddSeconds(59);

                // Calculate pivot points for the current day
                double HighValue = BarsDaily.HighPrices[barsDailyIndex];
                double LowValue = BarsDaily.LowPrices[barsDailyIndex];
                double CloseValue = BarsDaily.ClosePrices[barsDailyIndex];

                double PPValue = (HighValue + LowValue + CloseValue) / 3;
                double S1Value = (PPValue * 2) - HighValue;
                double S2Value = PPValue - (HighValue - LowValue);
                double S3Value = LowValue - 2 * (HighValue - PPValue);
                double R1Value = (PPValue * 2) - LowValue;
                double R2Value = PPValue + (HighValue - LowValue);
                double R3Value = HighValue + 2 * (PPValue - LowValue);
                
                var currentprice = Bars.ClosePrices[index-1];
                var PPPips = Math.Abs((currentprice - PPValue) / Symbol.PipSize);
                var S1Pips = Math.Abs((currentprice - S1Value) / Symbol.PipSize);
                var S2Pips = Math.Abs((currentprice - S2Value) / Symbol.PipSize);
                var S3Pips = Math.Abs((currentprice - S3Value) / Symbol.PipSize);
                var R1Pips = Math.Abs((currentprice - R1Value) / Symbol.PipSize);
                var R2Pips = Math.Abs((currentprice - R2Value) / Symbol.PipSize);
                var R3Pips = Math.Abs((currentprice - R3Value) / Symbol.PipSize);
                
                
                Print(PPPips);
                
                if ( PPPips <= AlertPips ) {
                
                Print("Price is above or below PPPis");
                
                }
               


                // Draw trendlines at pivot levels
                DrawHorizontalLine("PP Line", startOfDay, PPValue, endOfDay, PPValue, Color.Yellow);
                DrawHorizontalLine("S1 Line", startOfDay, S1Value, endOfDay, S1Value, Color.Red);
                DrawHorizontalLine("S2 Line", startOfDay, S2Value, endOfDay, S2Value, Color.Red);
                DrawHorizontalLine("S3 Line", startOfDay, S3Value, endOfDay, S3Value, Color.Red);
                DrawHorizontalLine("R1 Line", startOfDay, R1Value, endOfDay, R1Value, Color.Green);
                DrawHorizontalLine("R2 Line", startOfDay, R2Value, endOfDay, R2Value, Color.Green);
                DrawHorizontalLine("R3 Line", startOfDay, R3Value, endOfDay, R3Value, Color.Green);
            }
        
        
        }
        
        private void WoodiePivotFormula(int index) 
        {
          if (Bars.OpenTimes[index].Date != Bars.OpenTimes[index - 1].Date)
            {
                var barsDailyIndex = BarsDaily.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
                // Find the start and end of the current day using Bars
                DateTime startOfDay = Bars.OpenTimes[index].Date;
                DateTime endOfDay = startOfDay.AddHours(23).AddMinutes(59).AddSeconds(59);

                // Calculate pivot points for the current day
                double prevHigh = BarsDaily.HighPrices[barsDailyIndex - 1];
                double prevLow = BarsDaily.LowPrices[barsDailyIndex - 1];
                double todayOpen = BarsDaily.OpenPrices[barsDailyIndex];
                double prevRange = prevHigh - prevLow;

                double PPValue = (prevHigh + prevLow + (todayOpen * 2)) / 4;
                double R1Value = (PPValue * 2) - prevLow;
                double R2Value = PPValue + prevRange;
                double S1Value = (PPValue * 2) - prevHigh;
                double S2Value = PPValue - prevRange;
                double S3Value = (prevLow - 2 * (prevHigh - PPValue));
                double S4Value = (S3Value - prevRange);
                double R3Value = (prevHigh + 2 * (PPValue - prevLow));
                double R4Value = (R3Value + prevRange);


                // Draw trendlines at pivot levels
                DrawHorizontalLine("PP Line", startOfDay, PPValue, endOfDay, PPValue, Color.Yellow);
                DrawHorizontalLine("S1 Line", startOfDay, S1Value, endOfDay, S1Value, Color.Red);
                DrawHorizontalLine("S2 Line", startOfDay, S2Value, endOfDay, S2Value, Color.Red);
                DrawHorizontalLine("S3 Line", startOfDay, S3Value, endOfDay, S3Value, Color.Red);
                DrawHorizontalLine("R1 Line", startOfDay, R1Value, endOfDay, R1Value, Color.Green);
                DrawHorizontalLine("R2 Line", startOfDay, R2Value, endOfDay, R2Value, Color.Green);
                DrawHorizontalLine("R3 Line", startOfDay, R3Value, endOfDay, R3Value, Color.Green);
            }
            
        }
        
        
         public void FibonacciPivotformula(int index) 
            {
               if (Bars.OpenTimes[index].Date != Bars.OpenTimes[index - 1].Date)
            {
                var barsDailyIndex = BarsDaily.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
                double prevHigh = BarsDaily.HighPrices[barsDailyIndex - 1];
                double prevLow = BarsDaily.LowPrices[barsDailyIndex - 1];
                double prevClose = BarsDaily.ClosePrices[barsDailyIndex - 1];
                double prevRange = prevHigh - prevLow;

                double Pivot = (prevHigh + prevLow + prevClose) / 3;
                double R38 = Pivot + (prevRange * 0.382);
                double R61 = Pivot + (prevRange * 0.618);
                double R78 = Pivot + (prevRange * 0.786);
                double R100 = Pivot + (prevRange * 1.000);
                double R138 = Pivot + (prevRange * 1.382);
                double R161 = Pivot + (prevRange * 1.618);
                double R200 = Pivot + (prevRange * 2.000);
                double S38 = Pivot - (prevRange * 0.382);
                double S61 = Pivot - (prevRange * 0.618);
                double S78 = Pivot - (prevRange * 0.786);
                double S100 = Pivot - (prevRange * 1.000);
                double S138 = Pivot - (prevRange * 1.382);
                double S161 = Pivot - (prevRange * 1.618);
                double S200 = Pivot - (prevRange * 2.000);

                DateTime startOfDay = Bars.OpenTimes[index].Date;
                DateTime endOfDay = startOfDay.AddHours(23).AddMinutes(59).AddSeconds(59);

                // Draw trendlines at pivot levels
                DrawHorizontalLine("Pivot Line", startOfDay, Pivot, endOfDay, Pivot, Color.Yellow);
                DrawHorizontalLine("R38 Line", startOfDay, R38, endOfDay, R38, Color.Red);
                DrawHorizontalLine("R61 Line", startOfDay, R61, endOfDay, R61, Color.Red);
                DrawHorizontalLine("R78 Line", startOfDay, R78, endOfDay, R78, Color.Red);
                DrawHorizontalLine("R100 Line", startOfDay, R100, endOfDay, R100, Color.Green);
                DrawHorizontalLine("R138 Line", startOfDay, R138, endOfDay, R138, Color.Green);
                DrawHorizontalLine("R161 Line", startOfDay, R161, endOfDay, R161, Color.Green);
                DrawHorizontalLine("R200 Line", startOfDay, R200, endOfDay, R200, Color.Green);
                DrawHorizontalLine("S38 Line", startOfDay, S38, endOfDay, S38, Color.Red);
                DrawHorizontalLine("S61 Line", startOfDay, S61, endOfDay, S61, Color.Red);
                DrawHorizontalLine("S78 Line", startOfDay, S78, endOfDay, S78, Color.Red);
                DrawHorizontalLine("S100 Line", startOfDay, S100, endOfDay, S100, Color.Blue);
                DrawHorizontalLine("S138 Line", startOfDay, S138, endOfDay, S138, Color.Blue);
                DrawHorizontalLine("S161 Line", startOfDay, S161, endOfDay, S161, Color.Blue);
                DrawHorizontalLine("S200 Line", startOfDay, S200, endOfDay, S200, Color.Blue);
            }
            
            
            
            }
        
    }
}                                                              

@mihlali700

mihlali700
06 Jan 2024, 08:38

RE: RE: RE: Why does printing this give me random number ?

PanagiotisCharalampous said: 

mihlali700 said: 

PanagiotisCharalampous said: 

Hi there,

The close price changes on every tick therefore it is expected that the results would change. Can you explain to us what your expectation is?

Best regards,

Panagiotis

No I understand why it would be different at every tick but the way its different makes I unusable , I expect the numbers printing to be somewhat close to each other instead they are not, they are widely different with it even printing “NaN” 

It's obviously a logical bug on your side but it's hard to tell by a code snippet. We are just guessing. You would need to provide more information in order to get more help. Post at least the following

  1. The full indicator code
  2. Screenshots of the values you get.
  3. The values you would expect to get instead and an explanation why you expect them.

 

What I'm trying to print out is the difference of pips between two prices , which is PPValue and the currentprice which gives Pppips but since it prints out like this I cant really nail down why theres a huge variance in the values printed 


Here is the full code :

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AutoRescale = false, AccessRights = AccessRights.None)]
    public class Pivots : Indicator
    {
        
        [Parameter(DefaultValue = 10)]
        public int AlertPips { get; set; }
        
        [Parameter("Pivot Calculation Method", DefaultValue = PivotCalculationMethod.Standard)]
        public PivotCalculationMethod CalculationMethod { get; set; }

        public enum PivotCalculationMethod
        {
        Standard,
        Fibonacci,
        Woodie,
         }

        private Bars BarsDaily;
        
        protected override void Initialize()
        {
           
        BarsDaily = MarketData.GetBars(TimeFrame.Daily);

        }

        public override void Calculate(int index)
        {
                switch (CalculationMethod)
                {
                    case PivotCalculationMethod.Standard:
                   //  Standard
                   Standardpivotformula(index);
                    break;
                    case PivotCalculationMethod.Fibonacci:
                    FibonacciPivotformula(index);
                    break;
                    case PivotCalculationMethod.Woodie:
                    // Woodie  forumla 
                    WoodiePivotFormula(index);
                    break;
                 }
        
        
        }
        
         private void DrawHorizontalLine(string name, DateTime startTime, double startY, DateTime endTime, double endY, Color color)
        {
            var trendLine = Chart.DrawTrendLine(name, startTime, startY, endTime, endY, color, 2, LineStyle.Solid);
            trendLine.IsInteractive = true;
        }
        
        private void Standardpivotformula(int index) 
        {
        
          if (Bars.OpenTimes[index].Date != Bars.OpenTimes[index - 1].Date)
            {
                var barsDailyIndex = BarsDaily.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
                // Find the start and end of the current day using Bars
                DateTime startOfDay = Bars.OpenTimes[index].Date;
                DateTime endOfDay = startOfDay.AddHours(23).AddMinutes(59).AddSeconds(59);

                // Calculate pivot points for the current day
                double HighValue = BarsDaily.HighPrices[barsDailyIndex];
                double LowValue = BarsDaily.LowPrices[barsDailyIndex];
                double CloseValue = BarsDaily.ClosePrices[barsDailyIndex];

                double PPValue = (HighValue + LowValue + CloseValue) / 3;
                double S1Value = (PPValue * 2) - HighValue;
                double S2Value = PPValue - (HighValue - LowValue);
                double S3Value = LowValue - 2 * (HighValue - PPValue);
                double R1Value = (PPValue * 2) - LowValue;
                double R2Value = PPValue + (HighValue - LowValue);
                double R3Value = HighValue + 2 * (PPValue - LowValue);
                
                var currentprice = Bars.ClosePrices[index-1];
                var PPPips = Math.Abs((currentprice - PPValue) / Symbol.PipSize);
                var S1Pips = Math.Abs((currentprice - S1Value) / Symbol.PipSize);
                var S2Pips = Math.Abs((currentprice - S2Value) / Symbol.PipSize);
                var S3Pips = Math.Abs((currentprice - S3Value) / Symbol.PipSize);
                var R1Pips = Math.Abs((currentprice - R1Value) / Symbol.PipSize);
                var R2Pips = Math.Abs((currentprice - R2Value) / Symbol.PipSize);
                var R3Pips = Math.Abs((currentprice - R3Value) / Symbol.PipSize);
                
                
                Print(PPPips);
                
                if ( PPPips <= AlertPips ) {
                
                Print("Price is above or below PPPis");
                
                }
               


                // Draw trendlines at pivot levels
                DrawHorizontalLine("PP Line", startOfDay, PPValue, endOfDay, PPValue, Color.Yellow);
                DrawHorizontalLine("S1 Line", startOfDay, S1Value, endOfDay, S1Value, Color.Red);
                DrawHorizontalLine("S2 Line", startOfDay, S2Value, endOfDay, S2Value, Color.Red);
                DrawHorizontalLine("S3 Line", startOfDay, S3Value, endOfDay, S3Value, Color.Red);
                DrawHorizontalLine("R1 Line", startOfDay, R1Value, endOfDay, R1Value, Color.Green);
                DrawHorizontalLine("R2 Line", startOfDay, R2Value, endOfDay, R2Value, Color.Green);
                DrawHorizontalLine("R3 Line", startOfDay, R3Value, endOfDay, R3Value, Color.Green);
            }
        
        
        }
        
        private void WoodiePivotFormula(int index) 
        {
          if (Bars.OpenTimes[index].Date != Bars.OpenTimes[index - 1].Date)
            {
                var barsDailyIndex = BarsDaily.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
                // Find the start and end of the current day using Bars
                DateTime startOfDay = Bars.OpenTimes[index].Date;
                DateTime endOfDay = startOfDay.AddHours(23).AddMinutes(59).AddSeconds(59);

                // Calculate pivot points for the current day
                double prevHigh = BarsDaily.HighPrices[barsDailyIndex - 1];
                double prevLow = BarsDaily.LowPrices[barsDailyIndex - 1];
                double todayOpen = BarsDaily.OpenPrices[barsDailyIndex];
                double prevRange = prevHigh - prevLow;

                double PPValue = (prevHigh + prevLow + (todayOpen * 2)) / 4;
                double R1Value = (PPValue * 2) - prevLow;
                double R2Value = PPValue + prevRange;
                double S1Value = (PPValue * 2) - prevHigh;
                double S2Value = PPValue - prevRange;
                double S3Value = (prevLow - 2 * (prevHigh - PPValue));
                double S4Value = (S3Value - prevRange);
                double R3Value = (prevHigh + 2 * (PPValue - prevLow));
                double R4Value = (R3Value + prevRange);


                // Draw trendlines at pivot levels
                DrawHorizontalLine("PP Line", startOfDay, PPValue, endOfDay, PPValue, Color.Yellow);
                DrawHorizontalLine("S1 Line", startOfDay, S1Value, endOfDay, S1Value, Color.Red);
                DrawHorizontalLine("S2 Line", startOfDay, S2Value, endOfDay, S2Value, Color.Red);
                DrawHorizontalLine("S3 Line", startOfDay, S3Value, endOfDay, S3Value, Color.Red);
                DrawHorizontalLine("R1 Line", startOfDay, R1Value, endOfDay, R1Value, Color.Green);
                DrawHorizontalLine("R2 Line", startOfDay, R2Value, endOfDay, R2Value, Color.Green);
                DrawHorizontalLine("R3 Line", startOfDay, R3Value, endOfDay, R3Value, Color.Green);
            }
            
        }
        
        
         public void FibonacciPivotformula(int index) 
            {
               if (Bars.OpenTimes[index].Date != Bars.OpenTimes[index - 1].Date)
            {
                var barsDailyIndex = BarsDaily.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
                double prevHigh = BarsDaily.HighPrices[barsDailyIndex - 1];
                double prevLow = BarsDaily.LowPrices[barsDailyIndex - 1];
                double prevClose = BarsDaily.ClosePrices[barsDailyIndex - 1];
                double prevRange = prevHigh - prevLow;

                double Pivot = (prevHigh + prevLow + prevClose) / 3;
                double R38 = Pivot + (prevRange * 0.382);
                double R61 = Pivot + (prevRange * 0.618);
                double R78 = Pivot + (prevRange * 0.786);
                double R100 = Pivot + (prevRange * 1.000);
                double R138 = Pivot + (prevRange * 1.382);
                double R161 = Pivot + (prevRange * 1.618);
                double R200 = Pivot + (prevRange * 2.000);
                double S38 = Pivot - (prevRange * 0.382);
                double S61 = Pivot - (prevRange * 0.618);
                double S78 = Pivot - (prevRange * 0.786);
                double S100 = Pivot - (prevRange * 1.000);
                double S138 = Pivot - (prevRange * 1.382);
                double S161 = Pivot - (prevRange * 1.618);
                double S200 = Pivot - (prevRange * 2.000);

                DateTime startOfDay = Bars.OpenTimes[index].Date;
                DateTime endOfDay = startOfDay.AddHours(23).AddMinutes(59).AddSeconds(59);

                // Draw trendlines at pivot levels
                DrawHorizontalLine("Pivot Line", startOfDay, Pivot, endOfDay, Pivot, Color.Yellow);
                DrawHorizontalLine("R38 Line", startOfDay, R38, endOfDay, R38, Color.Red);
                DrawHorizontalLine("R61 Line", startOfDay, R61, endOfDay, R61, Color.Red);
                DrawHorizontalLine("R78 Line", startOfDay, R78, endOfDay, R78, Color.Red);
                DrawHorizontalLine("R100 Line", startOfDay, R100, endOfDay, R100, Color.Green);
                DrawHorizontalLine("R138 Line", startOfDay, R138, endOfDay, R138, Color.Green);
                DrawHorizontalLine("R161 Line", startOfDay, R161, endOfDay, R161, Color.Green);
                DrawHorizontalLine("R200 Line", startOfDay, R200, endOfDay, R200, Color.Green);
                DrawHorizontalLine("S38 Line", startOfDay, S38, endOfDay, S38, Color.Red);
                DrawHorizontalLine("S61 Line", startOfDay, S61, endOfDay, S61, Color.Red);
                DrawHorizontalLine("S78 Line", startOfDay, S78, endOfDay, S78, Color.Red);
                DrawHorizontalLine("S100 Line", startOfDay, S100, endOfDay, S100, Color.Blue);
                DrawHorizontalLine("S138 Line", startOfDay, S138, endOfDay, S138, Color.Blue);
                DrawHorizontalLine("S161 Line", startOfDay, S161, endOfDay, S161, Color.Blue);
                DrawHorizontalLine("S200 Line", startOfDay, S200, endOfDay, S200, Color.Blue);
            }
            
            
            
            }
        
    }
}                                                              

@mihlali700

mihlali700
06 Jan 2024, 08:38

RE: RE: RE: Why does printing this give me random number ?

PanagiotisCharalampous said: 

mihlali700 said: 

PanagiotisCharalampous said: 

Hi there,

The close price changes on every tick therefore it is expected that the results would change. Can you explain to us what your expectation is?

Best regards,

Panagiotis

No I understand why it would be different at every tick but the way its different makes I unusable , I expect the numbers printing to be somewhat close to each other instead they are not, they are widely different with it even printing “NaN” 

It's obviously a logical bug on your side but it's hard to tell by a code snippet. We are just guessing. You would need to provide more information in order to get more help. Post at least the following

  1. The full indicator code
  2. Screenshots of the values you get.
  3. The values you would expect to get instead and an explanation why you expect them.

 

What I'm trying to print out is the difference of pips between two prices , which is PPValue and the currentprice which gives Pppips but since it prints out like this I cant really nail down why theres a huge variance in the values printed 


Here is the full code :

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AutoRescale = false, AccessRights = AccessRights.None)]
    public class Pivots : Indicator
    {
        
        [Parameter(DefaultValue = 10)]
        public int AlertPips { get; set; }
        
        [Parameter("Pivot Calculation Method", DefaultValue = PivotCalculationMethod.Standard)]
        public PivotCalculationMethod CalculationMethod { get; set; }

        public enum PivotCalculationMethod
        {
        Standard,
        Fibonacci,
        Woodie,
         }

        private Bars BarsDaily;
        
        protected override void Initialize()
        {
           
        BarsDaily = MarketData.GetBars(TimeFrame.Daily);

        }

        public override void Calculate(int index)
        {
                switch (CalculationMethod)
                {
                    case PivotCalculationMethod.Standard:
                   //  Standard
                   Standardpivotformula(index);
                    break;
                    case PivotCalculationMethod.Fibonacci:
                    FibonacciPivotformula(index);
                    break;
                    case PivotCalculationMethod.Woodie:
                    // Woodie  forumla 
                    WoodiePivotFormula(index);
                    break;
                 }
        
        
        }
        
         private void DrawHorizontalLine(string name, DateTime startTime, double startY, DateTime endTime, double endY, Color color)
        {
            var trendLine = Chart.DrawTrendLine(name, startTime, startY, endTime, endY, color, 2, LineStyle.Solid);
            trendLine.IsInteractive = true;
        }
        
        private void Standardpivotformula(int index) 
        {
        
          if (Bars.OpenTimes[index].Date != Bars.OpenTimes[index - 1].Date)
            {
                var barsDailyIndex = BarsDaily.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
                // Find the start and end of the current day using Bars
                DateTime startOfDay = Bars.OpenTimes[index].Date;
                DateTime endOfDay = startOfDay.AddHours(23).AddMinutes(59).AddSeconds(59);

                // Calculate pivot points for the current day
                double HighValue = BarsDaily.HighPrices[barsDailyIndex];
                double LowValue = BarsDaily.LowPrices[barsDailyIndex];
                double CloseValue = BarsDaily.ClosePrices[barsDailyIndex];

                double PPValue = (HighValue + LowValue + CloseValue) / 3;
                double S1Value = (PPValue * 2) - HighValue;
                double S2Value = PPValue - (HighValue - LowValue);
                double S3Value = LowValue - 2 * (HighValue - PPValue);
                double R1Value = (PPValue * 2) - LowValue;
                double R2Value = PPValue + (HighValue - LowValue);
                double R3Value = HighValue + 2 * (PPValue - LowValue);
                
                var currentprice = Bars.ClosePrices[index-1];
                var PPPips = Math.Abs((currentprice - PPValue) / Symbol.PipSize);
                var S1Pips = Math.Abs((currentprice - S1Value) / Symbol.PipSize);
                var S2Pips = Math.Abs((currentprice - S2Value) / Symbol.PipSize);
                var S3Pips = Math.Abs((currentprice - S3Value) / Symbol.PipSize);
                var R1Pips = Math.Abs((currentprice - R1Value) / Symbol.PipSize);
                var R2Pips = Math.Abs((currentprice - R2Value) / Symbol.PipSize);
                var R3Pips = Math.Abs((currentprice - R3Value) / Symbol.PipSize);
                
                
                Print(PPPips);
                
                if ( PPPips <= AlertPips ) {
                
                Print("Price is above or below PPPis");
                
                }
               


                // Draw trendlines at pivot levels
                DrawHorizontalLine("PP Line", startOfDay, PPValue, endOfDay, PPValue, Color.Yellow);
                DrawHorizontalLine("S1 Line", startOfDay, S1Value, endOfDay, S1Value, Color.Red);
                DrawHorizontalLine("S2 Line", startOfDay, S2Value, endOfDay, S2Value, Color.Red);
                DrawHorizontalLine("S3 Line", startOfDay, S3Value, endOfDay, S3Value, Color.Red);
                DrawHorizontalLine("R1 Line", startOfDay, R1Value, endOfDay, R1Value, Color.Green);
                DrawHorizontalLine("R2 Line", startOfDay, R2Value, endOfDay, R2Value, Color.Green);
                DrawHorizontalLine("R3 Line", startOfDay, R3Value, endOfDay, R3Value, Color.Green);
            }
        
        
        }
        
        private void WoodiePivotFormula(int index) 
        {
          if (Bars.OpenTimes[index].Date != Bars.OpenTimes[index - 1].Date)
            {
                var barsDailyIndex = BarsDaily.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
                // Find the start and end of the current day using Bars
                DateTime startOfDay = Bars.OpenTimes[index].Date;
                DateTime endOfDay = startOfDay.AddHours(23).AddMinutes(59).AddSeconds(59);

                // Calculate pivot points for the current day
                double prevHigh = BarsDaily.HighPrices[barsDailyIndex - 1];
                double prevLow = BarsDaily.LowPrices[barsDailyIndex - 1];
                double todayOpen = BarsDaily.OpenPrices[barsDailyIndex];
                double prevRange = prevHigh - prevLow;

                double PPValue = (prevHigh + prevLow + (todayOpen * 2)) / 4;
                double R1Value = (PPValue * 2) - prevLow;
                double R2Value = PPValue + prevRange;
                double S1Value = (PPValue * 2) - prevHigh;
                double S2Value = PPValue - prevRange;
                double S3Value = (prevLow - 2 * (prevHigh - PPValue));
                double S4Value = (S3Value - prevRange);
                double R3Value = (prevHigh + 2 * (PPValue - prevLow));
                double R4Value = (R3Value + prevRange);


                // Draw trendlines at pivot levels
                DrawHorizontalLine("PP Line", startOfDay, PPValue, endOfDay, PPValue, Color.Yellow);
                DrawHorizontalLine("S1 Line", startOfDay, S1Value, endOfDay, S1Value, Color.Red);
                DrawHorizontalLine("S2 Line", startOfDay, S2Value, endOfDay, S2Value, Color.Red);
                DrawHorizontalLine("S3 Line", startOfDay, S3Value, endOfDay, S3Value, Color.Red);
                DrawHorizontalLine("R1 Line", startOfDay, R1Value, endOfDay, R1Value, Color.Green);
                DrawHorizontalLine("R2 Line", startOfDay, R2Value, endOfDay, R2Value, Color.Green);
                DrawHorizontalLine("R3 Line", startOfDay, R3Value, endOfDay, R3Value, Color.Green);
            }
            
        }
        
        
         public void FibonacciPivotformula(int index) 
            {
               if (Bars.OpenTimes[index].Date != Bars.OpenTimes[index - 1].Date)
            {
                var barsDailyIndex = BarsDaily.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
                double prevHigh = BarsDaily.HighPrices[barsDailyIndex - 1];
                double prevLow = BarsDaily.LowPrices[barsDailyIndex - 1];
                double prevClose = BarsDaily.ClosePrices[barsDailyIndex - 1];
                double prevRange = prevHigh - prevLow;

                double Pivot = (prevHigh + prevLow + prevClose) / 3;
                double R38 = Pivot + (prevRange * 0.382);
                double R61 = Pivot + (prevRange * 0.618);
                double R78 = Pivot + (prevRange * 0.786);
                double R100 = Pivot + (prevRange * 1.000);
                double R138 = Pivot + (prevRange * 1.382);
                double R161 = Pivot + (prevRange * 1.618);
                double R200 = Pivot + (prevRange * 2.000);
                double S38 = Pivot - (prevRange * 0.382);
                double S61 = Pivot - (prevRange * 0.618);
                double S78 = Pivot - (prevRange * 0.786);
                double S100 = Pivot - (prevRange * 1.000);
                double S138 = Pivot - (prevRange * 1.382);
                double S161 = Pivot - (prevRange * 1.618);
                double S200 = Pivot - (prevRange * 2.000);

                DateTime startOfDay = Bars.OpenTimes[index].Date;
                DateTime endOfDay = startOfDay.AddHours(23).AddMinutes(59).AddSeconds(59);

                // Draw trendlines at pivot levels
                DrawHorizontalLine("Pivot Line", startOfDay, Pivot, endOfDay, Pivot, Color.Yellow);
                DrawHorizontalLine("R38 Line", startOfDay, R38, endOfDay, R38, Color.Red);
                DrawHorizontalLine("R61 Line", startOfDay, R61, endOfDay, R61, Color.Red);
                DrawHorizontalLine("R78 Line", startOfDay, R78, endOfDay, R78, Color.Red);
                DrawHorizontalLine("R100 Line", startOfDay, R100, endOfDay, R100, Color.Green);
                DrawHorizontalLine("R138 Line", startOfDay, R138, endOfDay, R138, Color.Green);
                DrawHorizontalLine("R161 Line", startOfDay, R161, endOfDay, R161, Color.Green);
                DrawHorizontalLine("R200 Line", startOfDay, R200, endOfDay, R200, Color.Green);
                DrawHorizontalLine("S38 Line", startOfDay, S38, endOfDay, S38, Color.Red);
                DrawHorizontalLine("S61 Line", startOfDay, S61, endOfDay, S61, Color.Red);
                DrawHorizontalLine("S78 Line", startOfDay, S78, endOfDay, S78, Color.Red);
                DrawHorizontalLine("S100 Line", startOfDay, S100, endOfDay, S100, Color.Blue);
                DrawHorizontalLine("S138 Line", startOfDay, S138, endOfDay, S138, Color.Blue);
                DrawHorizontalLine("S161 Line", startOfDay, S161, endOfDay, S161, Color.Blue);
                DrawHorizontalLine("S200 Line", startOfDay, S200, endOfDay, S200, Color.Blue);
            }
            
            
            
            }
        
    }
}                                                              

@mihlali700

mihlali700
06 Jan 2024, 08:38

RE: RE: RE: Why does printing this give me random number ?

PanagiotisCharalampous said: 

mihlali700 said: 

PanagiotisCharalampous said: 

Hi there,

The close price changes on every tick therefore it is expected that the results would change. Can you explain to us what your expectation is?

Best regards,

Panagiotis

No I understand why it would be different at every tick but the way its different makes I unusable , I expect the numbers printing to be somewhat close to each other instead they are not, they are widely different with it even printing “NaN” 

It's obviously a logical bug on your side but it's hard to tell by a code snippet. We are just guessing. You would need to provide more information in order to get more help. Post at least the following

  1. The full indicator code
  2. Screenshots of the values you get.
  3. The values you would expect to get instead and an explanation why you expect them.

 

What I'm trying to print out is the difference of pips between two prices , which is PPValue and the currentprice which gives Pppips but since it prints out like this I cant really nail down why theres a huge variance in the values printed 


Here is the full code :

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AutoRescale = false, AccessRights = AccessRights.None)]
    public class Pivots : Indicator
    {
        
        [Parameter(DefaultValue = 10)]
        public int AlertPips { get; set; }
        
        [Parameter("Pivot Calculation Method", DefaultValue = PivotCalculationMethod.Standard)]
        public PivotCalculationMethod CalculationMethod { get; set; }

        public enum PivotCalculationMethod
        {
        Standard,
        Fibonacci,
        Woodie,
         }

        private Bars BarsDaily;
        
        protected override void Initialize()
        {
           
        BarsDaily = MarketData.GetBars(TimeFrame.Daily);

        }

        public override void Calculate(int index)
        {
                switch (CalculationMethod)
                {
                    case PivotCalculationMethod.Standard:
                   //  Standard
                   Standardpivotformula(index);
                    break;
                    case PivotCalculationMethod.Fibonacci:
                    FibonacciPivotformula(index);
                    break;
                    case PivotCalculationMethod.Woodie:
                    // Woodie  forumla 
                    WoodiePivotFormula(index);
                    break;
                 }
        
        
        }
        
         private void DrawHorizontalLine(string name, DateTime startTime, double startY, DateTime endTime, double endY, Color color)
        {
            var trendLine = Chart.DrawTrendLine(name, startTime, startY, endTime, endY, color, 2, LineStyle.Solid);
            trendLine.IsInteractive = true;
        }
        
        private void Standardpivotformula(int index) 
        {
        
          if (Bars.OpenTimes[index].Date != Bars.OpenTimes[index - 1].Date)
            {
                var barsDailyIndex = BarsDaily.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
                // Find the start and end of the current day using Bars
                DateTime startOfDay = Bars.OpenTimes[index].Date;
                DateTime endOfDay = startOfDay.AddHours(23).AddMinutes(59).AddSeconds(59);

                // Calculate pivot points for the current day
                double HighValue = BarsDaily.HighPrices[barsDailyIndex];
                double LowValue = BarsDaily.LowPrices[barsDailyIndex];
                double CloseValue = BarsDaily.ClosePrices[barsDailyIndex];

                double PPValue = (HighValue + LowValue + CloseValue) / 3;
                double S1Value = (PPValue * 2) - HighValue;
                double S2Value = PPValue - (HighValue - LowValue);
                double S3Value = LowValue - 2 * (HighValue - PPValue);
                double R1Value = (PPValue * 2) - LowValue;
                double R2Value = PPValue + (HighValue - LowValue);
                double R3Value = HighValue + 2 * (PPValue - LowValue);
                
                var currentprice = Bars.ClosePrices[index-1];
                var PPPips = Math.Abs((currentprice - PPValue) / Symbol.PipSize);
                var S1Pips = Math.Abs((currentprice - S1Value) / Symbol.PipSize);
                var S2Pips = Math.Abs((currentprice - S2Value) / Symbol.PipSize);
                var S3Pips = Math.Abs((currentprice - S3Value) / Symbol.PipSize);
                var R1Pips = Math.Abs((currentprice - R1Value) / Symbol.PipSize);
                var R2Pips = Math.Abs((currentprice - R2Value) / Symbol.PipSize);
                var R3Pips = Math.Abs((currentprice - R3Value) / Symbol.PipSize);
                
                
                Print(PPPips);
                
                if ( PPPips <= AlertPips ) {
                
                Print("Price is above or below PPPis");
                
                }
               


                // Draw trendlines at pivot levels
                DrawHorizontalLine("PP Line", startOfDay, PPValue, endOfDay, PPValue, Color.Yellow);
                DrawHorizontalLine("S1 Line", startOfDay, S1Value, endOfDay, S1Value, Color.Red);
                DrawHorizontalLine("S2 Line", startOfDay, S2Value, endOfDay, S2Value, Color.Red);
                DrawHorizontalLine("S3 Line", startOfDay, S3Value, endOfDay, S3Value, Color.Red);
                DrawHorizontalLine("R1 Line", startOfDay, R1Value, endOfDay, R1Value, Color.Green);
                DrawHorizontalLine("R2 Line", startOfDay, R2Value, endOfDay, R2Value, Color.Green);
                DrawHorizontalLine("R3 Line", startOfDay, R3Value, endOfDay, R3Value, Color.Green);
            }
        
        
        }
        
        private void WoodiePivotFormula(int index) 
        {
          if (Bars.OpenTimes[index].Date != Bars.OpenTimes[index - 1].Date)
            {
                var barsDailyIndex = BarsDaily.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
                // Find the start and end of the current day using Bars
                DateTime startOfDay = Bars.OpenTimes[index].Date;
                DateTime endOfDay = startOfDay.AddHours(23).AddMinutes(59).AddSeconds(59);

                // Calculate pivot points for the current day
                double prevHigh = BarsDaily.HighPrices[barsDailyIndex - 1];
                double prevLow = BarsDaily.LowPrices[barsDailyIndex - 1];
                double todayOpen = BarsDaily.OpenPrices[barsDailyIndex];
                double prevRange = prevHigh - prevLow;

                double PPValue = (prevHigh + prevLow + (todayOpen * 2)) / 4;
                double R1Value = (PPValue * 2) - prevLow;
                double R2Value = PPValue + prevRange;
                double S1Value = (PPValue * 2) - prevHigh;
                double S2Value = PPValue - prevRange;
                double S3Value = (prevLow - 2 * (prevHigh - PPValue));
                double S4Value = (S3Value - prevRange);
                double R3Value = (prevHigh + 2 * (PPValue - prevLow));
                double R4Value = (R3Value + prevRange);


                // Draw trendlines at pivot levels
                DrawHorizontalLine("PP Line", startOfDay, PPValue, endOfDay, PPValue, Color.Yellow);
                DrawHorizontalLine("S1 Line", startOfDay, S1Value, endOfDay, S1Value, Color.Red);
                DrawHorizontalLine("S2 Line", startOfDay, S2Value, endOfDay, S2Value, Color.Red);
                DrawHorizontalLine("S3 Line", startOfDay, S3Value, endOfDay, S3Value, Color.Red);
                DrawHorizontalLine("R1 Line", startOfDay, R1Value, endOfDay, R1Value, Color.Green);
                DrawHorizontalLine("R2 Line", startOfDay, R2Value, endOfDay, R2Value, Color.Green);
                DrawHorizontalLine("R3 Line", startOfDay, R3Value, endOfDay, R3Value, Color.Green);
            }
            
        }
        
        
         public void FibonacciPivotformula(int index) 
            {
               if (Bars.OpenTimes[index].Date != Bars.OpenTimes[index - 1].Date)
            {
                var barsDailyIndex = BarsDaily.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
                double prevHigh = BarsDaily.HighPrices[barsDailyIndex - 1];
                double prevLow = BarsDaily.LowPrices[barsDailyIndex - 1];
                double prevClose = BarsDaily.ClosePrices[barsDailyIndex - 1];
                double prevRange = prevHigh - prevLow;

                double Pivot = (prevHigh + prevLow + prevClose) / 3;
                double R38 = Pivot + (prevRange * 0.382);
                double R61 = Pivot + (prevRange * 0.618);
                double R78 = Pivot + (prevRange * 0.786);
                double R100 = Pivot + (prevRange * 1.000);
                double R138 = Pivot + (prevRange * 1.382);
                double R161 = Pivot + (prevRange * 1.618);
                double R200 = Pivot + (prevRange * 2.000);
                double S38 = Pivot - (prevRange * 0.382);
                double S61 = Pivot - (prevRange * 0.618);
                double S78 = Pivot - (prevRange * 0.786);
                double S100 = Pivot - (prevRange * 1.000);
                double S138 = Pivot - (prevRange * 1.382);
                double S161 = Pivot - (prevRange * 1.618);
                double S200 = Pivot - (prevRange * 2.000);

                DateTime startOfDay = Bars.OpenTimes[index].Date;
                DateTime endOfDay = startOfDay.AddHours(23).AddMinutes(59).AddSeconds(59);

                // Draw trendlines at pivot levels
                DrawHorizontalLine("Pivot Line", startOfDay, Pivot, endOfDay, Pivot, Color.Yellow);
                DrawHorizontalLine("R38 Line", startOfDay, R38, endOfDay, R38, Color.Red);
                DrawHorizontalLine("R61 Line", startOfDay, R61, endOfDay, R61, Color.Red);
                DrawHorizontalLine("R78 Line", startOfDay, R78, endOfDay, R78, Color.Red);
                DrawHorizontalLine("R100 Line", startOfDay, R100, endOfDay, R100, Color.Green);
                DrawHorizontalLine("R138 Line", startOfDay, R138, endOfDay, R138, Color.Green);
                DrawHorizontalLine("R161 Line", startOfDay, R161, endOfDay, R161, Color.Green);
                DrawHorizontalLine("R200 Line", startOfDay, R200, endOfDay, R200, Color.Green);
                DrawHorizontalLine("S38 Line", startOfDay, S38, endOfDay, S38, Color.Red);
                DrawHorizontalLine("S61 Line", startOfDay, S61, endOfDay, S61, Color.Red);
                DrawHorizontalLine("S78 Line", startOfDay, S78, endOfDay, S78, Color.Red);
                DrawHorizontalLine("S100 Line", startOfDay, S100, endOfDay, S100, Color.Blue);
                DrawHorizontalLine("S138 Line", startOfDay, S138, endOfDay, S138, Color.Blue);
                DrawHorizontalLine("S161 Line", startOfDay, S161, endOfDay, S161, Color.Blue);
                DrawHorizontalLine("S200 Line", startOfDay, S200, endOfDay, S200, Color.Blue);
            }
            
            
            
            }
        
    }
}                                                              

@mihlali700

mihlali700
06 Jan 2024, 08:38

RE: RE: RE: Why does printing this give me random number ?

PanagiotisCharalampous said: 

mihlali700 said: 

PanagiotisCharalampous said: 

Hi there,

The close price changes on every tick therefore it is expected that the results would change. Can you explain to us what your expectation is?

Best regards,

Panagiotis

No I understand why it would be different at every tick but the way its different makes I unusable , I expect the numbers printing to be somewhat close to each other instead they are not, they are widely different with it even printing “NaN” 

It's obviously a logical bug on your side but it's hard to tell by a code snippet. We are just guessing. You would need to provide more information in order to get more help. Post at least the following

  1. The full indicator code
  2. Screenshots of the values you get.
  3. The values you would expect to get instead and an explanation why you expect them.

 

What I'm trying to print out is the difference of pips between two prices , which is PPValue and the currentprice which gives Pppips but since it prints out like this I cant really nail down why theres a huge variance in the values printed 


Here is the full code :

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AutoRescale = false, AccessRights = AccessRights.None)]
    public class Pivots : Indicator
    {
        
        [Parameter(DefaultValue = 10)]
        public int AlertPips { get; set; }
        
        [Parameter("Pivot Calculation Method", DefaultValue = PivotCalculationMethod.Standard)]
        public PivotCalculationMethod CalculationMethod { get; set; }

        public enum PivotCalculationMethod
        {
        Standard,
        Fibonacci,
        Woodie,
         }

        private Bars BarsDaily;
        
        protected override void Initialize()
        {
           
        BarsDaily = MarketData.GetBars(TimeFrame.Daily);

        }

        public override void Calculate(int index)
        {
                switch (CalculationMethod)
                {
                    case PivotCalculationMethod.Standard:
                   //  Standard
                   Standardpivotformula(index);
                    break;
                    case PivotCalculationMethod.Fibonacci:
                    FibonacciPivotformula(index);
                    break;
                    case PivotCalculationMethod.Woodie:
                    // Woodie  forumla 
                    WoodiePivotFormula(index);
                    break;
                 }
        
        
        }
        
         private void DrawHorizontalLine(string name, DateTime startTime, double startY, DateTime endTime, double endY, Color color)
        {
            var trendLine = Chart.DrawTrendLine(name, startTime, startY, endTime, endY, color, 2, LineStyle.Solid);
            trendLine.IsInteractive = true;
        }
        
        private void Standardpivotformula(int index) 
        {
        
          if (Bars.OpenTimes[index].Date != Bars.OpenTimes[index - 1].Date)
            {
                var barsDailyIndex = BarsDaily.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
                // Find the start and end of the current day using Bars
                DateTime startOfDay = Bars.OpenTimes[index].Date;
                DateTime endOfDay = startOfDay.AddHours(23).AddMinutes(59).AddSeconds(59);

                // Calculate pivot points for the current day
                double HighValue = BarsDaily.HighPrices[barsDailyIndex];
                double LowValue = BarsDaily.LowPrices[barsDailyIndex];
                double CloseValue = BarsDaily.ClosePrices[barsDailyIndex];

                double PPValue = (HighValue + LowValue + CloseValue) / 3;
                double S1Value = (PPValue * 2) - HighValue;
                double S2Value = PPValue - (HighValue - LowValue);
                double S3Value = LowValue - 2 * (HighValue - PPValue);
                double R1Value = (PPValue * 2) - LowValue;
                double R2Value = PPValue + (HighValue - LowValue);
                double R3Value = HighValue + 2 * (PPValue - LowValue);
                
                var currentprice = Bars.ClosePrices[index-1];
                var PPPips = Math.Abs((currentprice - PPValue) / Symbol.PipSize);
                var S1Pips = Math.Abs((currentprice - S1Value) / Symbol.PipSize);
                var S2Pips = Math.Abs((currentprice - S2Value) / Symbol.PipSize);
                var S3Pips = Math.Abs((currentprice - S3Value) / Symbol.PipSize);
                var R1Pips = Math.Abs((currentprice - R1Value) / Symbol.PipSize);
                var R2Pips = Math.Abs((currentprice - R2Value) / Symbol.PipSize);
                var R3Pips = Math.Abs((currentprice - R3Value) / Symbol.PipSize);
                
                
                Print(PPPips);
                
                if ( PPPips <= AlertPips ) {
                
                Print("Price is above or below PPPis");
                
                }
               


                // Draw trendlines at pivot levels
                DrawHorizontalLine("PP Line", startOfDay, PPValue, endOfDay, PPValue, Color.Yellow);
                DrawHorizontalLine("S1 Line", startOfDay, S1Value, endOfDay, S1Value, Color.Red);
                DrawHorizontalLine("S2 Line", startOfDay, S2Value, endOfDay, S2Value, Color.Red);
                DrawHorizontalLine("S3 Line", startOfDay, S3Value, endOfDay, S3Value, Color.Red);
                DrawHorizontalLine("R1 Line", startOfDay, R1Value, endOfDay, R1Value, Color.Green);
                DrawHorizontalLine("R2 Line", startOfDay, R2Value, endOfDay, R2Value, Color.Green);
                DrawHorizontalLine("R3 Line", startOfDay, R3Value, endOfDay, R3Value, Color.Green);
            }
        
        
        }
        
        private void WoodiePivotFormula(int index) 
        {
          if (Bars.OpenTimes[index].Date != Bars.OpenTimes[index - 1].Date)
            {
                var barsDailyIndex = BarsDaily.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
                // Find the start and end of the current day using Bars
                DateTime startOfDay = Bars.OpenTimes[index].Date;
                DateTime endOfDay = startOfDay.AddHours(23).AddMinutes(59).AddSeconds(59);

                // Calculate pivot points for the current day
                double prevHigh = BarsDaily.HighPrices[barsDailyIndex - 1];
                double prevLow = BarsDaily.LowPrices[barsDailyIndex - 1];
                double todayOpen = BarsDaily.OpenPrices[barsDailyIndex];
                double prevRange = prevHigh - prevLow;

                double PPValue = (prevHigh + prevLow + (todayOpen * 2)) / 4;
                double R1Value = (PPValue * 2) - prevLow;
                double R2Value = PPValue + prevRange;
                double S1Value = (PPValue * 2) - prevHigh;
                double S2Value = PPValue - prevRange;
                double S3Value = (prevLow - 2 * (prevHigh - PPValue));
                double S4Value = (S3Value - prevRange);
                double R3Value = (prevHigh + 2 * (PPValue - prevLow));
                double R4Value = (R3Value + prevRange);


                // Draw trendlines at pivot levels
                DrawHorizontalLine("PP Line", startOfDay, PPValue, endOfDay, PPValue, Color.Yellow);
                DrawHorizontalLine("S1 Line", startOfDay, S1Value, endOfDay, S1Value, Color.Red);
                DrawHorizontalLine("S2 Line", startOfDay, S2Value, endOfDay, S2Value, Color.Red);
                DrawHorizontalLine("S3 Line", startOfDay, S3Value, endOfDay, S3Value, Color.Red);
                DrawHorizontalLine("R1 Line", startOfDay, R1Value, endOfDay, R1Value, Color.Green);
                DrawHorizontalLine("R2 Line", startOfDay, R2Value, endOfDay, R2Value, Color.Green);
                DrawHorizontalLine("R3 Line", startOfDay, R3Value, endOfDay, R3Value, Color.Green);
            }
            
        }
        
        
         public void FibonacciPivotformula(int index) 
            {
               if (Bars.OpenTimes[index].Date != Bars.OpenTimes[index - 1].Date)
            {
                var barsDailyIndex = BarsDaily.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
                double prevHigh = BarsDaily.HighPrices[barsDailyIndex - 1];
                double prevLow = BarsDaily.LowPrices[barsDailyIndex - 1];
                double prevClose = BarsDaily.ClosePrices[barsDailyIndex - 1];
                double prevRange = prevHigh - prevLow;

                double Pivot = (prevHigh + prevLow + prevClose) / 3;
                double R38 = Pivot + (prevRange * 0.382);
                double R61 = Pivot + (prevRange * 0.618);
                double R78 = Pivot + (prevRange * 0.786);
                double R100 = Pivot + (prevRange * 1.000);
                double R138 = Pivot + (prevRange * 1.382);
                double R161 = Pivot + (prevRange * 1.618);
                double R200 = Pivot + (prevRange * 2.000);
                double S38 = Pivot - (prevRange * 0.382);
                double S61 = Pivot - (prevRange * 0.618);
                double S78 = Pivot - (prevRange * 0.786);
                double S100 = Pivot - (prevRange * 1.000);
                double S138 = Pivot - (prevRange * 1.382);
                double S161 = Pivot - (prevRange * 1.618);
                double S200 = Pivot - (prevRange * 2.000);

                DateTime startOfDay = Bars.OpenTimes[index].Date;
                DateTime endOfDay = startOfDay.AddHours(23).AddMinutes(59).AddSeconds(59);

                // Draw trendlines at pivot levels
                DrawHorizontalLine("Pivot Line", startOfDay, Pivot, endOfDay, Pivot, Color.Yellow);
                DrawHorizontalLine("R38 Line", startOfDay, R38, endOfDay, R38, Color.Red);
                DrawHorizontalLine("R61 Line", startOfDay, R61, endOfDay, R61, Color.Red);
                DrawHorizontalLine("R78 Line", startOfDay, R78, endOfDay, R78, Color.Red);
                DrawHorizontalLine("R100 Line", startOfDay, R100, endOfDay, R100, Color.Green);
                DrawHorizontalLine("R138 Line", startOfDay, R138, endOfDay, R138, Color.Green);
                DrawHorizontalLine("R161 Line", startOfDay, R161, endOfDay, R161, Color.Green);
                DrawHorizontalLine("R200 Line", startOfDay, R200, endOfDay, R200, Color.Green);
                DrawHorizontalLine("S38 Line", startOfDay, S38, endOfDay, S38, Color.Red);
                DrawHorizontalLine("S61 Line", startOfDay, S61, endOfDay, S61, Color.Red);
                DrawHorizontalLine("S78 Line", startOfDay, S78, endOfDay, S78, Color.Red);
                DrawHorizontalLine("S100 Line", startOfDay, S100, endOfDay, S100, Color.Blue);
                DrawHorizontalLine("S138 Line", startOfDay, S138, endOfDay, S138, Color.Blue);
                DrawHorizontalLine("S161 Line", startOfDay, S161, endOfDay, S161, Color.Blue);
                DrawHorizontalLine("S200 Line", startOfDay, S200, endOfDay, S200, Color.Blue);
            }
            
            
            
            }
        
    }
}                                                              

@mihlali700

mihlali700
06 Jan 2024, 08:38

RE: RE: RE: Why does printing this give me random number ?

PanagiotisCharalampous said: 

mihlali700 said: 

PanagiotisCharalampous said: 

Hi there,

The close price changes on every tick therefore it is expected that the results would change. Can you explain to us what your expectation is?

Best regards,

Panagiotis

No I understand why it would be different at every tick but the way its different makes I unusable , I expect the numbers printing to be somewhat close to each other instead they are not, they are widely different with it even printing “NaN” 

It's obviously a logical bug on your side but it's hard to tell by a code snippet. We are just guessing. You would need to provide more information in order to get more help. Post at least the following

  1. The full indicator code
  2. Screenshots of the values you get.
  3. The values you would expect to get instead and an explanation why you expect them.

 

What I'm trying to print out is the difference of pips between two prices , which is PPValue and the currentprice which gives Pppips but since it prints out like this I cant really nail down why theres a huge variance in the values printed 


Here is the full code :

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AutoRescale = false, AccessRights = AccessRights.None)]
    public class Pivots : Indicator
    {
        
        [Parameter(DefaultValue = 10)]
        public int AlertPips { get; set; }
        
        [Parameter("Pivot Calculation Method", DefaultValue = PivotCalculationMethod.Standard)]
        public PivotCalculationMethod CalculationMethod { get; set; }

        public enum PivotCalculationMethod
        {
        Standard,
        Fibonacci,
        Woodie,
         }

        private Bars BarsDaily;
        
        protected override void Initialize()
        {
           
        BarsDaily = MarketData.GetBars(TimeFrame.Daily);

        }

        public override void Calculate(int index)
        {
                switch (CalculationMethod)
                {
                    case PivotCalculationMethod.Standard:
                   //  Standard
                   Standardpivotformula(index);
                    break;
                    case PivotCalculationMethod.Fibonacci:
                    FibonacciPivotformula(index);
                    break;
                    case PivotCalculationMethod.Woodie:
                    // Woodie  forumla 
                    WoodiePivotFormula(index);
                    break;
                 }
        
        
        }
        
         private void DrawHorizontalLine(string name, DateTime startTime, double startY, DateTime endTime, double endY, Color color)
        {
            var trendLine = Chart.DrawTrendLine(name, startTime, startY, endTime, endY, color, 2, LineStyle.Solid);
            trendLine.IsInteractive = true;
        }
        
        private void Standardpivotformula(int index) 
        {
        
          if (Bars.OpenTimes[index].Date != Bars.OpenTimes[index - 1].Date)
            {
                var barsDailyIndex = BarsDaily.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
                // Find the start and end of the current day using Bars
                DateTime startOfDay = Bars.OpenTimes[index].Date;
                DateTime endOfDay = startOfDay.AddHours(23).AddMinutes(59).AddSeconds(59);

                // Calculate pivot points for the current day
                double HighValue = BarsDaily.HighPrices[barsDailyIndex];
                double LowValue = BarsDaily.LowPrices[barsDailyIndex];
                double CloseValue = BarsDaily.ClosePrices[barsDailyIndex];

                double PPValue = (HighValue + LowValue + CloseValue) / 3;
                double S1Value = (PPValue * 2) - HighValue;
                double S2Value = PPValue - (HighValue - LowValue);
                double S3Value = LowValue - 2 * (HighValue - PPValue);
                double R1Value = (PPValue * 2) - LowValue;
                double R2Value = PPValue + (HighValue - LowValue);
                double R3Value = HighValue + 2 * (PPValue - LowValue);
                
                var currentprice = Bars.ClosePrices[index-1];
                var PPPips = Math.Abs((currentprice - PPValue) / Symbol.PipSize);
                var S1Pips = Math.Abs((currentprice - S1Value) / Symbol.PipSize);
                var S2Pips = Math.Abs((currentprice - S2Value) / Symbol.PipSize);
                var S3Pips = Math.Abs((currentprice - S3Value) / Symbol.PipSize);
                var R1Pips = Math.Abs((currentprice - R1Value) / Symbol.PipSize);
                var R2Pips = Math.Abs((currentprice - R2Value) / Symbol.PipSize);
                var R3Pips = Math.Abs((currentprice - R3Value) / Symbol.PipSize);
                
                
                Print(PPPips);
                
                if ( PPPips <= AlertPips ) {
                
                Print("Price is above or below PPPis");
                
                }
               


                // Draw trendlines at pivot levels
                DrawHorizontalLine("PP Line", startOfDay, PPValue, endOfDay, PPValue, Color.Yellow);
                DrawHorizontalLine("S1 Line", startOfDay, S1Value, endOfDay, S1Value, Color.Red);
                DrawHorizontalLine("S2 Line", startOfDay, S2Value, endOfDay, S2Value, Color.Red);
                DrawHorizontalLine("S3 Line", startOfDay, S3Value, endOfDay, S3Value, Color.Red);
                DrawHorizontalLine("R1 Line", startOfDay, R1Value, endOfDay, R1Value, Color.Green);
                DrawHorizontalLine("R2 Line", startOfDay, R2Value, endOfDay, R2Value, Color.Green);
                DrawHorizontalLine("R3 Line", startOfDay, R3Value, endOfDay, R3Value, Color.Green);
            }
        
        
        }
        
        private void WoodiePivotFormula(int index) 
        {
          if (Bars.OpenTimes[index].Date != Bars.OpenTimes[index - 1].Date)
            {
                var barsDailyIndex = BarsDaily.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
                // Find the start and end of the current day using Bars
                DateTime startOfDay = Bars.OpenTimes[index].Date;
                DateTime endOfDay = startOfDay.AddHours(23).AddMinutes(59).AddSeconds(59);

                // Calculate pivot points for the current day
                double prevHigh = BarsDaily.HighPrices[barsDailyIndex - 1];
                double prevLow = BarsDaily.LowPrices[barsDailyIndex - 1];
                double todayOpen = BarsDaily.OpenPrices[barsDailyIndex];
                double prevRange = prevHigh - prevLow;

                double PPValue = (prevHigh + prevLow + (todayOpen * 2)) / 4;
                double R1Value = (PPValue * 2) - prevLow;
                double R2Value = PPValue + prevRange;
                double S1Value = (PPValue * 2) - prevHigh;
                double S2Value = PPValue - prevRange;
                double S3Value = (prevLow - 2 * (prevHigh - PPValue));
                double S4Value = (S3Value - prevRange);
                double R3Value = (prevHigh + 2 * (PPValue - prevLow));
                double R4Value = (R3Value + prevRange);


                // Draw trendlines at pivot levels
                DrawHorizontalLine("PP Line", startOfDay, PPValue, endOfDay, PPValue, Color.Yellow);
                DrawHorizontalLine("S1 Line", startOfDay, S1Value, endOfDay, S1Value, Color.Red);
                DrawHorizontalLine("S2 Line", startOfDay, S2Value, endOfDay, S2Value, Color.Red);
                DrawHorizontalLine("S3 Line", startOfDay, S3Value, endOfDay, S3Value, Color.Red);
                DrawHorizontalLine("R1 Line", startOfDay, R1Value, endOfDay, R1Value, Color.Green);
                DrawHorizontalLine("R2 Line", startOfDay, R2Value, endOfDay, R2Value, Color.Green);
                DrawHorizontalLine("R3 Line", startOfDay, R3Value, endOfDay, R3Value, Color.Green);
            }
            
        }
        
        
         public void FibonacciPivotformula(int index) 
            {
               if (Bars.OpenTimes[index].Date != Bars.OpenTimes[index - 1].Date)
            {
                var barsDailyIndex = BarsDaily.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
                double prevHigh = BarsDaily.HighPrices[barsDailyIndex - 1];
                double prevLow = BarsDaily.LowPrices[barsDailyIndex - 1];
                double prevClose = BarsDaily.ClosePrices[barsDailyIndex - 1];
                double prevRange = prevHigh - prevLow;

                double Pivot = (prevHigh + prevLow + prevClose) / 3;
                double R38 = Pivot + (prevRange * 0.382);
                double R61 = Pivot + (prevRange * 0.618);
                double R78 = Pivot + (prevRange * 0.786);
                double R100 = Pivot + (prevRange * 1.000);
                double R138 = Pivot + (prevRange * 1.382);
                double R161 = Pivot + (prevRange * 1.618);
                double R200 = Pivot + (prevRange * 2.000);
                double S38 = Pivot - (prevRange * 0.382);
                double S61 = Pivot - (prevRange * 0.618);
                double S78 = Pivot - (prevRange * 0.786);
                double S100 = Pivot - (prevRange * 1.000);
                double S138 = Pivot - (prevRange * 1.382);
                double S161 = Pivot - (prevRange * 1.618);
                double S200 = Pivot - (prevRange * 2.000);

                DateTime startOfDay = Bars.OpenTimes[index].Date;
                DateTime endOfDay = startOfDay.AddHours(23).AddMinutes(59).AddSeconds(59);

                // Draw trendlines at pivot levels
                DrawHorizontalLine("Pivot Line", startOfDay, Pivot, endOfDay, Pivot, Color.Yellow);
                DrawHorizontalLine("R38 Line", startOfDay, R38, endOfDay, R38, Color.Red);
                DrawHorizontalLine("R61 Line", startOfDay, R61, endOfDay, R61, Color.Red);
                DrawHorizontalLine("R78 Line", startOfDay, R78, endOfDay, R78, Color.Red);
                DrawHorizontalLine("R100 Line", startOfDay, R100, endOfDay, R100, Color.Green);
                DrawHorizontalLine("R138 Line", startOfDay, R138, endOfDay, R138, Color.Green);
                DrawHorizontalLine("R161 Line", startOfDay, R161, endOfDay, R161, Color.Green);
                DrawHorizontalLine("R200 Line", startOfDay, R200, endOfDay, R200, Color.Green);
                DrawHorizontalLine("S38 Line", startOfDay, S38, endOfDay, S38, Color.Red);
                DrawHorizontalLine("S61 Line", startOfDay, S61, endOfDay, S61, Color.Red);
                DrawHorizontalLine("S78 Line", startOfDay, S78, endOfDay, S78, Color.Red);
                DrawHorizontalLine("S100 Line", startOfDay, S100, endOfDay, S100, Color.Blue);
                DrawHorizontalLine("S138 Line", startOfDay, S138, endOfDay, S138, Color.Blue);
                DrawHorizontalLine("S161 Line", startOfDay, S161, endOfDay, S161, Color.Blue);
                DrawHorizontalLine("S200 Line", startOfDay, S200, endOfDay, S200, Color.Blue);
            }
            
            
            
            }
        
    }
}                                                              

@mihlali700

mihlali700
06 Jan 2024, 08:38

RE: RE: RE: Why does printing this give me random number ?

PanagiotisCharalampous said: 

mihlali700 said: 

PanagiotisCharalampous said: 

Hi there,

The close price changes on every tick therefore it is expected that the results would change. Can you explain to us what your expectation is?

Best regards,

Panagiotis

No I understand why it would be different at every tick but the way its different makes I unusable , I expect the numbers printing to be somewhat close to each other instead they are not, they are widely different with it even printing “NaN” 

It's obviously a logical bug on your side but it's hard to tell by a code snippet. We are just guessing. You would need to provide more information in order to get more help. Post at least the following

  1. The full indicator code
  2. Screenshots of the values you get.
  3. The values you would expect to get instead and an explanation why you expect them.

 

What I'm trying to print out is the difference of pips between two prices , which is PPValue and the currentprice which gives Pppips but since it prints out like this I cant really nail down why theres a huge variance in the values printed 


Here is the full code :

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AutoRescale = false, AccessRights = AccessRights.None)]
    public class Pivots : Indicator
    {
        
        [Parameter(DefaultValue = 10)]
        public int AlertPips { get; set; }
        
        [Parameter("Pivot Calculation Method", DefaultValue = PivotCalculationMethod.Standard)]
        public PivotCalculationMethod CalculationMethod { get; set; }

        public enum PivotCalculationMethod
        {
        Standard,
        Fibonacci,
        Woodie,
         }

        private Bars BarsDaily;
        
        protected override void Initialize()
        {
           
        BarsDaily = MarketData.GetBars(TimeFrame.Daily);

        }

        public override void Calculate(int index)
        {
                switch (CalculationMethod)
                {
                    case PivotCalculationMethod.Standard:
                   //  Standard
                   Standardpivotformula(index);
                    break;
                    case PivotCalculationMethod.Fibonacci:
                    FibonacciPivotformula(index);
                    break;
                    case PivotCalculationMethod.Woodie:
                    // Woodie  forumla 
                    WoodiePivotFormula(index);
                    break;
                 }
        
        
        }
        
         private void DrawHorizontalLine(string name, DateTime startTime, double startY, DateTime endTime, double endY, Color color)
        {
            var trendLine = Chart.DrawTrendLine(name, startTime, startY, endTime, endY, color, 2, LineStyle.Solid);
            trendLine.IsInteractive = true;
        }
        
        private void Standardpivotformula(int index) 
        {
        
          if (Bars.OpenTimes[index].Date != Bars.OpenTimes[index - 1].Date)
            {
                var barsDailyIndex = BarsDaily.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
                // Find the start and end of the current day using Bars
                DateTime startOfDay = Bars.OpenTimes[index].Date;
                DateTime endOfDay = startOfDay.AddHours(23).AddMinutes(59).AddSeconds(59);

                // Calculate pivot points for the current day
                double HighValue = BarsDaily.HighPrices[barsDailyIndex];
                double LowValue = BarsDaily.LowPrices[barsDailyIndex];
                double CloseValue = BarsDaily.ClosePrices[barsDailyIndex];

                double PPValue = (HighValue + LowValue + CloseValue) / 3;
                double S1Value = (PPValue * 2) - HighValue;
                double S2Value = PPValue - (HighValue - LowValue);
                double S3Value = LowValue - 2 * (HighValue - PPValue);
                double R1Value = (PPValue * 2) - LowValue;
                double R2Value = PPValue + (HighValue - LowValue);
                double R3Value = HighValue + 2 * (PPValue - LowValue);
                
                var currentprice = Bars.ClosePrices[index-1];
                var PPPips = Math.Abs((currentprice - PPValue) / Symbol.PipSize);
                var S1Pips = Math.Abs((currentprice - S1Value) / Symbol.PipSize);
                var S2Pips = Math.Abs((currentprice - S2Value) / Symbol.PipSize);
                var S3Pips = Math.Abs((currentprice - S3Value) / Symbol.PipSize);
                var R1Pips = Math.Abs((currentprice - R1Value) / Symbol.PipSize);
                var R2Pips = Math.Abs((currentprice - R2Value) / Symbol.PipSize);
                var R3Pips = Math.Abs((currentprice - R3Value) / Symbol.PipSize);
                
                
                Print(PPPips);
                
                if ( PPPips <= AlertPips ) {
                
                Print("Price is above or below PPPis");
                
                }
               


                // Draw trendlines at pivot levels
                DrawHorizontalLine("PP Line", startOfDay, PPValue, endOfDay, PPValue, Color.Yellow);
                DrawHorizontalLine("S1 Line", startOfDay, S1Value, endOfDay, S1Value, Color.Red);
                DrawHorizontalLine("S2 Line", startOfDay, S2Value, endOfDay, S2Value, Color.Red);
                DrawHorizontalLine("S3 Line", startOfDay, S3Value, endOfDay, S3Value, Color.Red);
                DrawHorizontalLine("R1 Line", startOfDay, R1Value, endOfDay, R1Value, Color.Green);
                DrawHorizontalLine("R2 Line", startOfDay, R2Value, endOfDay, R2Value, Color.Green);
                DrawHorizontalLine("R3 Line", startOfDay, R3Value, endOfDay, R3Value, Color.Green);
            }
        
        
        }
        
        private void WoodiePivotFormula(int index) 
        {
          if (Bars.OpenTimes[index].Date != Bars.OpenTimes[index - 1].Date)
            {
                var barsDailyIndex = BarsDaily.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
                // Find the start and end of the current day using Bars
                DateTime startOfDay = Bars.OpenTimes[index].Date;
                DateTime endOfDay = startOfDay.AddHours(23).AddMinutes(59).AddSeconds(59);

                // Calculate pivot points for the current day
                double prevHigh = BarsDaily.HighPrices[barsDailyIndex - 1];
                double prevLow = BarsDaily.LowPrices[barsDailyIndex - 1];
                double todayOpen = BarsDaily.OpenPrices[barsDailyIndex];
                double prevRange = prevHigh - prevLow;

                double PPValue = (prevHigh + prevLow + (todayOpen * 2)) / 4;
                double R1Value = (PPValue * 2) - prevLow;
                double R2Value = PPValue + prevRange;
                double S1Value = (PPValue * 2) - prevHigh;
                double S2Value = PPValue - prevRange;
                double S3Value = (prevLow - 2 * (prevHigh - PPValue));
                double S4Value = (S3Value - prevRange);
                double R3Value = (prevHigh + 2 * (PPValue - prevLow));
                double R4Value = (R3Value + prevRange);


                // Draw trendlines at pivot levels
                DrawHorizontalLine("PP Line", startOfDay, PPValue, endOfDay, PPValue, Color.Yellow);
                DrawHorizontalLine("S1 Line", startOfDay, S1Value, endOfDay, S1Value, Color.Red);
                DrawHorizontalLine("S2 Line", startOfDay, S2Value, endOfDay, S2Value, Color.Red);
                DrawHorizontalLine("S3 Line", startOfDay, S3Value, endOfDay, S3Value, Color.Red);
                DrawHorizontalLine("R1 Line", startOfDay, R1Value, endOfDay, R1Value, Color.Green);
                DrawHorizontalLine("R2 Line", startOfDay, R2Value, endOfDay, R2Value, Color.Green);
                DrawHorizontalLine("R3 Line", startOfDay, R3Value, endOfDay, R3Value, Color.Green);
            }
            
        }
        
        
         public void FibonacciPivotformula(int index) 
            {
               if (Bars.OpenTimes[index].Date != Bars.OpenTimes[index - 1].Date)
            {
                var barsDailyIndex = BarsDaily.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
                double prevHigh = BarsDaily.HighPrices[barsDailyIndex - 1];
                double prevLow = BarsDaily.LowPrices[barsDailyIndex - 1];
                double prevClose = BarsDaily.ClosePrices[barsDailyIndex - 1];
                double prevRange = prevHigh - prevLow;

                double Pivot = (prevHigh + prevLow + prevClose) / 3;
                double R38 = Pivot + (prevRange * 0.382);
                double R61 = Pivot + (prevRange * 0.618);
                double R78 = Pivot + (prevRange * 0.786);
                double R100 = Pivot + (prevRange * 1.000);
                double R138 = Pivot + (prevRange * 1.382);
                double R161 = Pivot + (prevRange * 1.618);
                double R200 = Pivot + (prevRange * 2.000);
                double S38 = Pivot - (prevRange * 0.382);
                double S61 = Pivot - (prevRange * 0.618);
                double S78 = Pivot - (prevRange * 0.786);
                double S100 = Pivot - (prevRange * 1.000);
                double S138 = Pivot - (prevRange * 1.382);
                double S161 = Pivot - (prevRange * 1.618);
                double S200 = Pivot - (prevRange * 2.000);

                DateTime startOfDay = Bars.OpenTimes[index].Date;
                DateTime endOfDay = startOfDay.AddHours(23).AddMinutes(59).AddSeconds(59);

                // Draw trendlines at pivot levels
                DrawHorizontalLine("Pivot Line", startOfDay, Pivot, endOfDay, Pivot, Color.Yellow);
                DrawHorizontalLine("R38 Line", startOfDay, R38, endOfDay, R38, Color.Red);
                DrawHorizontalLine("R61 Line", startOfDay, R61, endOfDay, R61, Color.Red);
                DrawHorizontalLine("R78 Line", startOfDay, R78, endOfDay, R78, Color.Red);
                DrawHorizontalLine("R100 Line", startOfDay, R100, endOfDay, R100, Color.Green);
                DrawHorizontalLine("R138 Line", startOfDay, R138, endOfDay, R138, Color.Green);
                DrawHorizontalLine("R161 Line", startOfDay, R161, endOfDay, R161, Color.Green);
                DrawHorizontalLine("R200 Line", startOfDay, R200, endOfDay, R200, Color.Green);
                DrawHorizontalLine("S38 Line", startOfDay, S38, endOfDay, S38, Color.Red);
                DrawHorizontalLine("S61 Line", startOfDay, S61, endOfDay, S61, Color.Red);
                DrawHorizontalLine("S78 Line", startOfDay, S78, endOfDay, S78, Color.Red);
                DrawHorizontalLine("S100 Line", startOfDay, S100, endOfDay, S100, Color.Blue);
                DrawHorizontalLine("S138 Line", startOfDay, S138, endOfDay, S138, Color.Blue);
                DrawHorizontalLine("S161 Line", startOfDay, S161, endOfDay, S161, Color.Blue);
                DrawHorizontalLine("S200 Line", startOfDay, S200, endOfDay, S200, Color.Blue);
            }
            
            
            
            }
        
    }
}                                                              

@mihlali700

PanagiotisCharalampous
06 Jan 2024, 10:09

Hi again,

The values you provided are not for each tick but for each bar since the Calculate() method is called for every bar for historical bars. At the moment I see nothing wrong.

Best regards,

Panagiotis


@PanagiotisCharalampous

mihlali700
06 Jan 2024, 10:26

RE: Why does printing this give me random number ?

PanagiotisCharalampous said: 

Hi again,

The values you provided are not for each tick but for each bar since the Calculate() method is called for every bar for historical bars. At the moment I see nothing wrong.

Best regards,

Panagiotis

I just want the value of just 1 bar , that either being the current or previous , how do I achieve that ?


@mihlali700

mihlali700
06 Jan 2024, 10:26

RE: Why does printing this give me random number ?

PanagiotisCharalampous said: 

Hi again,

The values you provided are not for each tick but for each bar since the Calculate() method is called for every bar for historical bars. At the moment I see nothing wrong.

Best regards,

Panagiotis

I just want the value of just 1 bar , that either being the current or previous , how do I achieve that ?


@mihlali700

PanagiotisCharalampous
08 Jan 2024, 06:43

RE: RE: Why does printing this give me random number ?

mihlali700 said: 

PanagiotisCharalampous said: 

Hi again,

The values you provided are not for each tick but for each bar since the Calculate() method is called for every bar for historical bars. At the moment I see nothing wrong.

Best regards,

Panagiotis

I just want the value of just 1 bar , that either being the current or previous , how do I achieve that ?

Hi there, 

I am a bit confused about what the issue is now. You said that the values do not make sense to you but they seem to make sense to. I have ask for an explanation of what exact value would you expect instead of the ones you see printed and how that value is calculated but you did not provide it (e.g. the value printed at 12:00 is 1 but I would expect it to be 2 because a, b, c….). It is hard to help you further without this information.

Best regards,

Panagiotis


@PanagiotisCharalampous

mihlali700
08 Jan 2024, 08:04

RE: RE: RE: Why does printing this give me random number ?

PanagiotisCharalampous said: 

mihlali700 said: 

PanagiotisCharalampous said: 

Hi again,

The values you provided are not for each tick but for each bar since the Calculate() method is called for every bar for historical bars. At the moment I see nothing wrong.

Best regards,

Panagiotis

I just want the value of just 1 bar , that either being the current or previous , how do I achieve that ?

Hi there, 

I am a bit confused about what the issue is now. You said that the values do not make sense to you but they seem to make sense to. I have ask for an explanation of what exact value would you expect instead of the ones you see printed and how that value is calculated but you did not provide it (e.g. the value printed at 12:00 is 1 but I would expect it to be 2 because a, b, c….). It is hard to help you further without this information.

Best regards,

Panagiotis

When I run this :
 var currentprice = Bars.ClosePrices[index-1];

I just expect to get the value of the currentprice or the price of the bar before that but as you are saying its giving me the value of every single bar starting from bar 1 , I don't want that , I just want the price of the previous bar so that I can minus it with Something Like S1 and get a pip value which is the distance between the current price and S1 


@mihlali700

PanagiotisCharalampous
08 Jan 2024, 12:03

RE: RE: RE: RE: Why does printing this give me random number ?

mihlali700 said: 

PanagiotisCharalampous said: 

mihlali700 said: 

PanagiotisCharalampous said: 

Hi again,

The values you provided are not for each tick but for each bar since the Calculate() method is called for every bar for historical bars. At the moment I see nothing wrong.

Best regards,

Panagiotis

I just want the value of just 1 bar , that either being the current or previous , how do I achieve that ?

Hi there, 

I am a bit confused about what the issue is now. You said that the values do not make sense to you but they seem to make sense to. I have ask for an explanation of what exact value would you expect instead of the ones you see printed and how that value is calculated but you did not provide it (e.g. the value printed at 12:00 is 1 but I would expect it to be 2 because a, b, c….). It is hard to help you further without this information.

Best regards,

Panagiotis

When I run this :
 var currentprice = Bars.ClosePrices[index-1];

I just expect to get the value of the currentprice or the price of the bar before that but as you are saying its giving me the value of every single bar starting from bar 1 , I don't want that , I just want the price of the previous bar so that I can minus it with Something Like S1 and get a pip value which is the distance between the current price and S1 

Hi there,

Then you can use the IsLastBar property to print the values only for the last bar. 


@PanagiotisCharalampous