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

    #46
    Originally posted by NinjaTrader_Jesse View Post
    Hello frankduc,

    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"?
    A little bit of both.
    First of all i would like to resolve an issue with the Output Window.
    The data that comes out in the OW is repeated several times.
    For exemple, you can see in attachement the data start at 2792 and ends at 2795.25 it seems that every time a new bar is appearing it recalculate from start and add another bunch of data.

    Extract bars traded above is easy.

    if(closePrice > cma)

    Print(closePrice);

    The thing is i just want the price above CMA before for(int barIndex = ChartBars.GetBarIdxByX(chartControl, cursorPointX) - someOtherInt; barIndex <= ChartBars.ToIndex; barIndex++) cursorPointX.

    Do i have to create a CMA for for(int barIndex = ChartBars.GetBarIdxByX(chartControl, cursorPointX) - someOtherInt; barIndex <= ChartBars.GetBarIdxByX(chartControl, cursorPointX); barIndex++) as well or is there a short cut to my problem?

    In that case i would have to create 2 CMA's and send back the answer where i need it.

    As for
    float chartScaleYValue = chartScale.GetYByValue(price); it can only be used in context of the SampleCustomRender.
    My question is, what do i need specifically in SCR to make it work? Cause there's a lot of settings. Its not a priority for now.
    Attached Files

    Comment


      #47
      Hello frankduc,

      The data that comes out in the OW is repeated several times.
      Is the print in OnRender or inside of your loop or both? To be able to accurately answer your questions, I would really need to see accurate samples of what you are questioning when you ask new questions. I am assuming this is from OnRender and also your loop in which you should see OnRender called very very frequently, much more than your other data processing methods like OnBarUpdate. The Loop would also call your print for each bar it loops over. You would see this logic run every time OnRender is called which happens for many reason such as mouse interaction, bar updates, drawing objects being removed etc.. In most cases you will see the prints over and over again if this is from OnRender.

      The thing is i just want the price above CMA before for(int barIndex = ChartBars.GetBarIdxByX(chartControl, cursorPointX) - someOtherInt; barIndex <= ChartBars.ToIndex; barIndex++) cursorPointX.
      Do i have to create a CMA for for(int barIndex = ChartBars.GetBarIdxByX(chartControl, cursorPointX) - someOtherInt; barIndex <= ChartBars.GetBarIdxByX(chartControl, cursorPointX); barIndex++) as well or is there a short cut to my problem?
      You would need to create a condition to check for that price if you are trying to find a price above another price. The loop you have made is not something standard which will have other predefined conditions.

      n that case i would have to create 2 CMA's and send back the answer where i need it.
      If that is what you find is necessary you may need to use that approach. If possible I would suggest to use the least amount of loops you can, or try to do this logic in the first for loop if you can.


      float chartScaleYValue = chartScale.GetYByValue(price); it can only be used in context of the SampleCustomRender.
      No, that is not correct. You can use this in your script as well, from OnRender. You would replace "price" in the method with the price you want to convert to y for rendering. This is not shown in the SampleCustomRender but you can see this in the Help Guide: https://ninjatrader.com/support/help...ub=GetYByValue
      The SampleCustomRender can be used to see how to render to the chart in simple ways, you can then use similar syntax in your script if you wanted to render the value you calculated.



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





      JesseNinjaTrader Customer Service

      Comment


        #48
        Its OnRender and inside the loop i think. Judge by yourself.

        double sum =0;
        int barIndex1 = 0;

        for(int barIndex = ChartBars.GetBarIdxByX(chartControl, cursorPointX) - someOtherInt; barIndex <= ChartBars.ToIndex; barIndex++)
        {
        double closePrice = Bars.GetClose(barIndex);

        sum += closePrice;

        barIndex1++;

        double cma = sum / barIndex1;

        if(closePrice > cma)

        Print(closePrice);
        }

        I just want to be sure that the repetitiveness
        . of data wont alter the calculation. Even if the OW show 4 times the same series of returns my calculation will be done once, its just a visual hindrance in the end.

        I think that indicator once done, if i get to the end of it will probably be heavy considering i have little knowledge of c#. Not to mention without your help this project would be stalling for a while.

        Thank you again

        Comment


          #49
          Hello frankduc,

          Yes this print should be repeated or happen a lot. You have a loop over the visible bars which will happen each time OnRender is called. You would see a print for each bar where your condition is true in the loop. The loop is going to be called for many different events, not just bar events. Clicking the chart, data pushing to the chart, drawing objects, etc.. OnRender is what is called when the chart/script needs to be redrawn.

          Your calculation is going to last for the duration of the render pass as long as you rent accumulating values outside of OnRender. It should just recalculate for each render pass. I see that you are accumulating values inside of OnRender so the value is just going to reset when OnRender is called again.

          If you are having trouble visualizing what process the script is following in regard to OnRender and your logic, I would suggest adding a couple prints like the following to observe how OnRender is called:

          Code:
          Print("Entered OnRender()");
          
          for(int barIndex = ChartBars.GetBarIdxByX(chartControl, cursorPointX) - someOtherInt; barIndex <= ChartBars.ToIndex; barIndex++)
          {
          Print("Loop # " + barIndex);
          double closePrice = Bars.GetClose(barIndex);
          
          sum += closePrice;
          
          barIndex1++;
          
          double cma = sum / barIndex1;
          
          if(closePrice > cma)
          
          Print(closePrice);
          }
          This will show OnRender being entered, your loop and highlights when it repeats.

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






          JesseNinjaTrader Customer Service

          Comment


            #50
            Hello,

            I would like to add a Fibonacci calculation to my indicator. The idea is to determine where is actually close price in the chart regarding its fibo position.

            For exemple, the low 0% will be the lowest price of the bar in the trend. 100% will be the close price from one of my calculation.

            I need a method and the formulas to calculate the % value of the last close price that just came out ( i suppose that's CurrentBar the first bar at the right side of the chart)

            Probably, the difference between 100% - 0%
            Close[0]/ (100 - 0)

            I dont want to draw the fibo retracement in the chart, i only want to get the position in % of the last traded bar.




            First i need the fibo formulas and second i saw a few codes in the tutorial and i wonder if they could be useful.

            Returns R3 value
            FibonacciPivots(PivotRangepivotRangeType, HLCCalculationModepriorDayHLC, doubleuserDefinedClose, doubleuserDefinedHigh, doubleuserDefinedLow, intwidth).R3[intbarsAgo]
            FibonacciPivots(ISeries<double>input, PivotRangepivotRangeType, HLCCalculationModepriorDayHLC, doubleuserDefinedClose, doubleuserDefinedHigh, doubleuserDefinedLow, intwidth).R3[intbarsAgo]

            What is R3? is it 2.62? I would like to find a code i could do some reverse calculation.

            According to pivots R3 is
            r3 = pp + 2 * (currentHigh - currentLow);
            But i dont think that its correct because i get a 1 pts difference between pivots and fibo retracement at 2.62.

            ty
            Last edited by frankduc; 06-06-2019, 06:37 AM.

            Comment


              #51
              Hello frankduc,

              It looks like this no longer relates to the original topic in this thread and this thread is getting very long, I would suggest recreating this question as a new thread about this new topic so we can keep that information together. This helps both the support staff and other users in understanding the information in your post.

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

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by swestendorf, Today, 11:14 AM
              0 responses
              0 views
              0 likes
              Last Post swestendorf  
              Started by Sparkyboy, Today, 10:57 AM
              0 responses
              3 views
              0 likes
              Last Post Sparkyboy  
              Started by TheMarlin801, 10-13-2020, 01:40 AM
              21 responses
              3,917 views
              0 likes
              Last Post Bidder
              by Bidder
               
              Started by timmbbo, 07-05-2023, 10:21 PM
              3 responses
              153 views
              0 likes
              Last Post grayfrog  
              Started by Lumbeezl, 01-11-2022, 06:50 PM
              30 responses
              812 views
              1 like
              Last Post grayfrog  
              Working...
              X