Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

sum close in a series

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #31
    Hello frankduc,

    I was hoping to set a time period in my indicator (proprieties) like 922 and automatically the indicator will calculate the 922 CMA's for that trend period. I dont want to have to cut the data myself in the chart.
    From this, I understand that you have used the mouse to manually place the line as there was some problem in creating a property to control this automatically, is that right? But it would be more aligned with your goal if you just had a property to use and the indicator created the line its self, is this what you are saying?


    Suppose to calculate the zone i want like on the second chart attach i set only the period i need. The problem is if i do that everytime there is a new bar i lose 1 bar at the beginning at the chart (left side).
    If you know that you will loose one bar, this would be something to account for in your logic. Generally if you need a fixed starting point, you need to save the bars index as a variable that you can recall later to specify that is the start.

    Can we use islock to freeze the chart at the number of periods i desired ?
    I am not certain what you are asking here, can you provide more detail on this question?

    If i set the number of period to 1367 bar like on the chart we add a +1 somewhere to keep the chart staying at the beginning at 10:56 always?
    I am not certain what you mean by add a +1 somewhere, are you asking to prevent the chart from proceeding forward as data progresses?

    I think islock could do that?
    What are you referring to with "islock"? This is not a NinjaScript term and also not a C# term I am aware of. Are you asking about a drawing tools "IsLocked" property?

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #32
      "
      But it would be more aligned with your goal if you just had a property to use and the indicator created the line its self, is this what you are saying?



      "

      By line you mean the CMA? If its the CMA i did some try but its not convincing. I dont understand yet if i should code the CMA "line" from OnBarupdate or Onrender and how do it anyway.

      Here's an exemple about Period use:

      The goal was to divide the downtrend by a previous uptrend and get % at 429 bars. This was a test, it will be needed later when i will code the different formulas i have, using the CMA's volume above or below the CMA's. If there is 86 bars, well 86 / 429 = 20%

      // -minus
      int modifiedBarIndex2 = clickedBarIndex - 429;

      {
      double sumOfVolumes = 0;
      double sumOfVolumes1 = 0;
      double sumOfVolumes2 = 0;


      for (int i = 0; i <= clickedBarIndex; i++)
      {
      sumOfVolumes += Bars.GetVolume(i);
      }
      for (int i = 0; i <= totalBarIndex; i++)
      {
      sumOfVolumes1 += Bars.GetVolume(i);
      }

      double cursorbar = sumOfVolumes1 - sumOfVolumes;

      for (int i = 0; i <= modifiedBarIndex2; i++) //cursorX-429ofcursorX
      {
      sumOfVolumes2 += Bars.GetVolume(i);
      }

      double minus = sumOfVolumes - sumOfVolumes2;


      double percent = cursorbar / minus;


      Print(percent);

      I would like to change 429 for a time period. I would click in the chart the proprieties indicator and set 429. The problem, i tried to replace 429 by Period and add Period in if (State == State.SetDefaults) but it did not work and replied Period does not exist in context.
      If i can use Period i will be able to control the scale the datas i am calculating. This will reflect on the CMA's line, the line will have 429 periods. Than the indicator should calculate automatically all other CMA line below 429 periods; 428, 427, 426 etc till zero.

      "Generally if you need a fixed starting point, you need to save the bars index as a variable that you can recall later to specify that is the start. "

      I suppose its true but by default i thought isLocked would of done the job for me. You see everytime i click on the chart to displace the fibonacci tool the indicator is moving where i clicked and its anoying. I have tried many times to make it work but cant find how to code the thing. When Islocked on with Fibo the data seems fix.

      Where do we code the IsLocked?
      public
      override
      void
      OnMouseMove(ChartControl
      chartControl,
      ChartPanel
      chartPanel,
      ChartScale
      chartScale,
      Point
      point)
      {
      if
      (IsLocked)
      //if the object is locked, do not attempt to move
      return
      ;
      }
      Its somewhere around here but the exemple in tutorial is not clear.






      }
      else if (State == State.Historical)
      {
      //add event handler
      if (ChartControl != null) ChartControl.MouseUp += ChartControl_MouseUp;
      }
      else if (State == State.Terminated)
      {
      //remove event handler
      if (ChartControl != null) ChartControl.MouseUp -= ChartControl_MouseUp;
      }
      }

      private void ChartControl_MouseUp(object sender, MouseButtonEventArgs e)
      {
      //cause a refresh to poll after up click
      ForceRefresh();
      }

      protected override void OnBarUpdate()
      {

      }
      public override void OnRenderTargetChanged()
      {
      textBrush = Brushes.Red.ToDxBrush(RenderTarget);
      }

      protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
      {
      if (IsInHitTest) return;
      if (ChartBars != null)
      "are you asking to prevent the chart from proceeding forward as data progresses? "

      As the data progress at the letf side of the chart i will lose a bar, 10:56 will be lost and replace by 10:57, 10:58 etc and i want to prevent that. Otherwise i will have to change constantly the Period from 429 to 430, 431 etc to keep the chart from 10:56 to now.

      thank you for your time

      Last edited by frankduc; 06-01-2019, 04:24 PM.

      Comment


        #33
        Hello frankduc,


        "
        But it would be more aligned with your goal if you just had a property to use and the indicator created the line its self, is this what you are saying?
        "
        By line you mean the CMA? If its the CMA i did some try but its not convincing. I dont understand yet if i should code the CMA "line" from OnBarupdate or Onrender and how do it anyway.

        I believe there is a translation problem, this is not what I was asking.

        To rephrase what I was asking: Do you want enter a value into the indicator properties, or manually click to draw a line? From your description it seems that you would rather enter a value as a property and have the indicator do this for you. Entering a value is likely easier than including mouse clicking logic.



        but it did not work and replied Period does not exist in context.
        It sounds like you have a new problem with something you were trying here, unfortunately there are many questions still unanswered in this thread and it seems there are also some translation problems. Before we continue on to new questions, it would be best to first answer the existing items you have asked and reduce the amount of information here to a few specific questions.

        I would still like to get an understanding of your goal at a very high level. I don't need to know the specific details you are providing but would like to understand the following questions:

        Do you specifically need to click and use the mouse selection, or would you rather have the indicator use a property to control the line placement?

        Is the overall goal to just display the indicator past the line, excluding prior data or should the prior data just be hidden when it meets the line?



        I suppose its true but by default i thought isLocked would of done the job for me.
        If you are calling the Draw syntax again to re draw the line, it will update the existing line to the new values you had supplied. IsLocked is used in a drawing objects logic for specific reasons related to its drawing, but this is not going to relate to a NinjaScript strategy and how it calls a Draw. method.





        As the data progress at the letf side of the chart i will lose a bar, 10:56 will be lost and replace by 10:57, 10:58 etc and i want to prevent that. Otherwise i will have to change constantly the Period from 429 to 430, 431 etc to keep the chart from 10:56 to now.
        There is no way to stop the chart from progressing besides disconnecting from your data provider. If you need to keep increasing the period to retain a fixed starting point, you will need to store the index from that point and then use math to get the bars ago. One example would be if the 10:56 bar is bar # 1000 and we are now on bar 1429, you would use CurrentBar - storedBar = BarsAgo or 1429 - 1000 = 429. Now we can assume time has progressed forward and we are on bar 1430 or 1430 - 1000 = 430.




        I look forward to being of further assistance.

        JesseNinjaTrader Customer Service

        Comment


          #34
          Sorry, are you talking about the vertical blue line i draw manually in a previous chart or the line draw by the CMA?

          The vertical blue line refer to the calculation i made when i divide an uptrend by a downtrend. That line has no importance at all, it just say the CMA must start at that line. I know the value of the vertical blue line is 429 bars for exemple. So i want to be able to enter myself 429 in the propriety window in the indicator. But it could be 500 or 1000 and the CMA will draw using those numbers.
          In any case i dont have the choice to enter myself the 429 cause i am the only one who can evaluate where the trend start and end. Its got to be simple, its already enough complicated as it is.

          I dont think its translation problem its more a perception one. Its hard to be clear using text.

          If you exclude the data, it will draw a CMA like the chart i attach earlier. If you hide the data i dont know what difference it will make. Preferably its better if you can see the entire day chart even if the CMA start calculation or drawing at bar 1000 even if there's 3000 bars in the chart.

          In attachement it should look like this the blueline is barindex 2830 and i shall enter in proprieties period 1434 and the CMA will draw by itself. Its like for the SMA you put 14 SMA it draw a 14 period, in this case you enter Period = 1434 instead and it draw the CMA.

          I hope this will answer your questions.
          Attached Files
          Last edited by frankduc; 05-29-2019, 12:27 PM.

          Comment


            #35
            Hello frankduc,

            Sorry, are you talking about the vertical blue line i draw manually in a previous chart or the line draw by the CMA?
            To be clear, I am referring to the vertical line. I will say CMA if I refer to that.

            The vertical blue line refer to the calculation i made when i divide an uptrend by a downtrend. That line has no importance at all, it just say the CMA must start at that line.
            That seems important toward your goal as this is the starting point you want to use.


            I know the value of the vertical blue line is 429 bars for example. So i want to be able to enter myself 429 in the propriety window in the indicator. But it could be 500 or 1000 and the CMA will draw using those numbers.
            Is this specifically going to be the 10:30 bar? What is the significance of the values you are mentioning such as 429? Are you trying to place the line at the 10:30 bar always or will the lines position be variable? If you are trying to place the line 429 bars from now, and that is the 10:30 bar it may be easier to just use the Time's of the bars for the placement of the line. This would also allow for calculation of BarsAgo from now to continue the calculation going forward.


            If you exclude the data, it will draw a CMA like the chart i attach earlier. If you hide the data i dont know what difference it will make. Preferably its better if you can see the entire day chart even if the CMA start calculation or drawing at bar 1000 even if there's 3000 bars in the chart.
            I was not asking about hiding data or showing data, I was specifically asking about hiding or showing the CMA based on the Line position as you previously had asked. You commented on this previously, I had follow up questions surrounding this:
            Ok What i want is to create a CMA for the data series i am testing. In the chart it means from vertical blueline to the end (right side) of the chart.
            I then ask:
            Are you asking to not include the data prior to the blue line, as in calculate only from that point forward? Or do you just want to hide the plot before the line and retain the original calculated value?
            Should the indicator calculate starting from the line, or over the whole chart? You provided a picture which shows hiding the CMA when it is before the blue line, should that data be calculated and just hidden, or are you trying to start calculating at the blue line to the end of the chart?

            In attachement it should look like this the blueline is barindex 2830 and i shall enter in proprieties period 1434 and the CMA will draw by itself. Its like for the SMA you put 14 SMA it draw a 14 period, in this case you enter Period = 1434 instead and it draw the CMA.
            The CMA you provided already works like this however it does not have a specific period property. Are you asking how to modify the CMA to include a period property?




            Please let me know if I may be of additional assistance.
            JesseNinjaTrader Customer Service

            Comment


              #36
              "Is this specifically going to be the 10:30 bar? What is the significance of the values you are mentioning such as 429? Are you trying to place the line at the 10:30 bar always or will the lines position be variable?"
              "This would also allow for calculation of BarsAgo from now to continue the calculation going forward."


              It will be variable. 429 or any other number is the number of bars i want the CMA to start. Like i said the blueline is an exemple. The blue line = 429 bars from the blueline to the end of the right side of the chart. 429 is an hypothetical number, honnestly there is probably more than 429 bars from the blueline on the chart i provided. My mistake.
              About using the Time bars, its a good idea. I'm afraid it will get more complicated to code.

              "The CMA you provided already works like this however it does not have a specific period property. Are you asking how to modify the CMA to include a period property? "
              This is exactly what i want! If for exemple i set a period at 429. The CMA line should look like on the chart i provided last post. The CMA start at 10:30 till the end of the chart (right side of the chart) The red line CMA on the chart is an exemple i draw the line myself on paint.

              At the beginning i thought it was only possible to apply the CMA to the data series (render) i created. But if we set a period in propriety indicator i will be able to use the RMMA to create multiple CMA's from that point. From 429 to period 1 for exemple. Of course assuming we can include also the RMMA in my indicator and the CMA.

              Thank you
              Last edited by frankduc; 05-30-2019, 11:19 AM.

              Comment


                #37
                Hello frankduc,

                It will be variable. 429 or any other number is the number of bars i want the CMA to start. Like i said the blueline is an exemple. The blue line = 429 bars from the blueline to the end of the right side of the chart. 429 is an hypothetical number, honnestly there is probably more than 429 bars from the blueline on the chart i provided.
                Thank you for confirming, it sounds like programming this into the indicator is not likely an option as this is variable based on where you place the line.

                This is exactly what i want! If for exemple i set a period at 429.
                If that is the case, this is something you can investigate and add to the CMA if it should work that way. You can review the SMA or EMA as some simple examples of using a period in logic. Because the CMA was not designed that way to start with, you would likely need to re work the logic to calculate for the period rather than every bar is it does now. It looks like it is doing a division against the CurrentBar + 1, this may be where you could use a period value instead, however you would need to test this and see what the output value is to know if that will be valid or not.

                The CMA line should look like on the chart i provided last post. The CMA start at 10:30 till the end of the chart (right side of the chart) The red line CMA on the chart is an exemple i draw the line myself on paint.
                The visual aspect can be modified later, such as hiding the plot before the blue line as you are asking. This is still one of my open questions, or: do you want the CMA only include the data from the blue line forward, ignoring the bars before the blue line?

                By default the indicator is going to run for all bars, not just the bars past the blue line. The indicator has a constant calculation so depending on when you wanted to start that calculation, it will change the result. You can hide the data before the blue line if you wanted, however the data before the line is still part of the calculation.

                Do you mean to just hide the plot before the blue line, or do you mean to not calculate that data at all and only include the data past the line? This will change how you approach the question, if you mean to just hide the data that will likely be fairly straightforward. If you mean to exclude the data and only use the data ahead of the line, that is more difficult and likely will require you to manually calculate the CMA value using math/the existing calculation in the indicator and not the indicator directly.


                Please let me know if I may be of additional assistance.






                JesseNinjaTrader Customer Service

                Comment


                  #38
                  Originally posted by NinjaTrader_Jesse View Post
                  Hello frankduc,

                  Do you mean to just hide the plot before the blue line, or do you mean to not calculate that data at all and only include the data past the line? This will change how you approach the question, if you mean to just hide the data that will likely be fairly straightforward. If you mean to exclude the data and only use the data ahead of the line, that is more difficult and likely will require you to manually calculate the CMA value using math/the existing calculation in the indicator and not the indicator directly.
                  I mean that the data before the blue line should not be included in the calculation. If you include that data its just a CMA of all the points in the chart.
                  In fact i dont need periods (its useful but not essential) I just want the calculation to start at the blue line and than decrease of one period each CMA from blue line to the end of the chart (ride side) That means a CMA of each period from the blue line, so a 429 CMA than a 428 CMA , etc.

                  I can do without seeing the CMA in the chart, i just need the returns, as long as the numbers are right.

                  I already created an average of the number of bars i want but its not cumulative and at this point i still dont know how to do it. You just take the sum of all closes / by the number of bars and there's the average. But after that for the next point ? All closes[0] - 1 / total bars -1 period? I dont know. Manually its probably feasible, do you have any hints or suggestions?

                  Comment


                    #39
                    Hello frankduc,

                    I mean that the data before the blue line should not be included in the calculation.
                    Thank you for clarifying that.

                    If you do not want to include the data, the most simple way to do this will be to not use the indicator and just use math it has in it to calculate this value for the period you wanted. Using the indicator assumes you want to calculate the whole series, if you wanted just past the line it would be more simple to just accumulate the value and do the division yourself.

                    I already created an average of the number of bars i want but its not cumulative and at this point i still dont know how to do it. You just take the sum of all closes / by the number of bars and there's the average.
                    If you are trying to mirror what the indicator does, you provided the syntax for that already:

                    Code:
                    sum += Input[0];
                    
                    Value[0] = sum / (CurrentBar + 1);
                    It looks like for the time the script is run, it is just accumulating the input to a variable and then dividing that against the current bar + 1. This is a part of the script you would need to review and see what calculation will work for the result you want.

                    If you are using OnRender, the CurrentBar would be replaced with the Index you are rendering. If you only wanted to do the division across the bars after the line, you will need to know the lines index and the index of the last bar on the chart or ChartBars.ToIndex. With that information you could calculate a number or period to do the division against.

                    Please let me know if I may be of additional assistance.
                    JesseNinjaTrader Customer Service

                    Comment


                      #40
                      double sum =0;

                      for(int barIndex = ChartBars.GetBarIdxByX(chartControl, cursorPointX) - someOtherInt; barIndex <= ChartBars.ToIndex; barIndex++)

                      {
                      double closePrice = Bars.GetClose(barIndex);

                      sum += closePrice;

                      double cma = sum / barIndex;

                      Print(cma);


                      }

                      If i do barIndex++ it will return the barIndex position like for exemple from 2600 to the right side of the chart.
                      How do we get barIndex to list 1,2,3,4,5 etc
                      so i can divide my sum of close price by each position 1, 2, 3, 4 etc?
                      i have the feeling the answer is easy but i am stuck for an hour on this. barIndex cant be modified to start at 0
                      Last edited by frankduc; 06-04-2019, 08:23 AM.

                      Comment


                        #41
                        Hello frankduc,

                        In this case barIndex is only going to be 0 if you happen to click on the first bar of the chart. You are getting an ID of a bar by its X value, if you are past the first bar on the chart it will likely be a high number.

                        If you clicked on the first bar of the chart, you would see a range between 0 and your ChartBars.ToIndex.

                        The ChartBars.ToIndex is the last rendered bar of the current view, not to be confused with the last actual bar of data which is not currently being rendered. If you scroll back to the beginning of the chart, some of the data will now be outside of the rendered chart area to the right. I just wanted to make sure you understand this in case you are instead looking for the last actual bar on the chart, that would be Count - 2 or -1 depending on the Calculate setting.

                        Keep in mind, if you scroll back in time and the line goes past the right side of the chart, your loop will not happen. Lets assume the line is at bar 2000 and the ChartBars.ToIndex is 3000. If you scroll back in time and your line moves toward the right and then off the right side of the chart, the line is still at bar 2000, but now your rendered ChartBars.ToIndex is also 1900. your loop is looping over 2000 <= 1900 which changes the calculation to not happen.


                        Please let me know if I may be of additional assistance.
                        JesseNinjaTrader Customer Service

                        Comment


                          #42
                          ok thank you
                          i got it
                          Last edited by frankduc; 06-04-2019, 09:53 AM.

                          Comment


                            #43
                            Hello frankduc,

                            I want to know how to convert the bar position so it goes from 1 to 1700 (if theres 1700 barsago in my index).
                            cant divide 2739 (emini) by 1700 the first number must divide by one than by 2, 3,4 etc.
                            Right now its dividing by 1700, 1699, 1698 etc
                            I am not certain what you are asking to do here, the index does not work this way with the syntax you have used. Your loop controls the index based on where you clicked and the right most rendered bar.

                            tried

                            int newbarIndex = 0;
                            newbarIndex++;

                            double cma = sum / newbarIndex++;

                            but newbarIndex give me an increment of 3, 5 , 8 etc instead of 1 ,2, 3, 4 etc
                            For this new sample, you have used two increments so I would expect that it increments by two by the time it reaches your print which is not shown.

                            Code:
                            int [B]newbarIndex[/B] = 0;
                            [B]newbarIndex[/B]++;  [U]// one increment[/U]
                            
                            double cma = sum / [B]newbarIndex[/B]++; [U] //second increment[/U]
                            ++ increments the variable where used.


                            Please let me know if I may be of additional assistance.
                            JesseNinjaTrader Customer Service

                            Comment


                              #44
                              Sorry you got to reply before i found the problem. But it works now. I got my cma TY

                              I have another question:

                              How do i compare the CMA result from the Index. Extract all the bar traded above the CMA.
                              I'm guessing the use of If else is necessary.

                              something like

                              for (int i = 0; i <= barIndex; i++)
                              {
                              if(barIndex
                              <=
                              CMA)
                              {

                              Also is it possible to plot the cma into the chart now that i have the data?
                              Last edited by frankduc; 06-04-2019, 10:17 AM.

                              Comment


                                #45
                                Hello frankduc,

                                How do i compare the CMA result from the Index. Extract all the bar traded above the CMA.
                                I'm guessing the use of If else is necessary.
                                You can compare a double against another value using an if statement like you had noted, are you asking how to create an if statement or the other part of your statement " Extract all the bar traded above the CMA"?


                                Also is it possible to plot the cma into the chart now that i have the data?
                                We are looping back to earlier in this thread where we were discussing OnRender. That portion of the thread should make more sense now that you have figured out how you want to call/calculate the indicator value. If you wanted to plot the data, you can just render it however you like using OnRender now that you have the X starting point and your price. The price and be converted to Y values using:

                                Code:
                                 float chartScaleYValue = chartScale.GetYByValue(price);
                                The indicator SampleCustomRender demonstrates the various rendering concepts if you wanted a more complete reference on how to render.


                                I look forward to being of further assistance.
                                JesseNinjaTrader Customer Service

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by rtwave, 04-12-2024, 09:30 AM
                                5 responses
                                37 views
                                0 likes
                                Last Post NinjaTrader_ChelseaB  
                                Started by funk10101, Today, 12:02 AM
                                1 response
                                11 views
                                0 likes
                                Last Post NinjaTrader_LuisH  
                                Started by GLFX005, Today, 03:23 AM
                                1 response
                                6 views
                                0 likes
                                Last Post NinjaTrader_Erick  
                                Started by nandhumca, Yesterday, 03:41 PM
                                1 response
                                13 views
                                0 likes
                                Last Post NinjaTrader_Gaby  
                                Started by The_Sec, Yesterday, 03:37 PM
                                1 response
                                11 views
                                0 likes
                                Last Post NinjaTrader_Gaby  
                                Working...
                                X