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

strange calculation

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

    strange calculation

    Hello,

    I have an indicator in CL running for months and all fine. Today it doesn´t plot as it should, so I added drawing of the values in the chart for debugging and its showing strange numbers.

    In the code I have simply for months working:

    {startprice = Math.Round(CurrentDayOHL().CurrentOpen[0],0);
    priceH = startprice+300*TickSize;
    priceA = priceH-600*TickSize;

    startprice should be 46, no?

    with startprice = Math.Round(CurrentDayOHL().CurrentOpen[0],2); I get also strange number 53,04...

    And in the attached screenshots you can see the numbers for startprice from Math. Round.

    ???

    Thank you!
    Tony
    Attached Files
    Last edited by tonynt; 12-19-2018, 11:54 AM.

    #2
    Hello tonynt,

    Thank you for the post.

    startprice should be 46, no?
    I really couldn't say from the provided details or image I cannot see how you are outputting the data for the image to make an observation here.

    This would likely be a good situation to use Print statements to further debug your script. I could also suggest taking the logic in error and placing that in a new test script to exclude any other logic you may have in the script. This would allow you to test only the calculation you are doing to see if it still results in a strange result.

    Have you at this point tried Printing out the values being calculated from a separate test script? If so and it is not apparent why the values are as shown, do you have a sample that includes both the print and syntax that you can upload to this thread for me to run and also see this result?


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



    JesseNinjaTrader Customer Service

    Comment


      #3
      Hello Jesse,

      thank you for your reply. Sorry, that I did not show the open of CL that day to see the wrong value.

      I do plot the values in the chart for debugging so I see for every bar in the chart the current values and immediately if wrong or correct. I dont know how to do the print statement.

      There´s nothing more in the code than rounding the open and doing this once a day and not all day long with every bar.
      if(Close[0]>0 && levelcalculated==false)
      {startprice = Math.Round(CurrentDayOHL().CurrentOpen[0],0);
      levelcalculated=true;}

      Today open price CL is 47,39 but rounded shows 52. This occurs when I add the bool for calculating the value one time.



      Best regards
      Tony
      Attached Files
      Last edited by tonynt; 12-20-2018, 03:51 AM.

      Comment


        #4
        Hello tonynt,

        Code:
        I do plot the values in the chart for debugging so I see for every bar in the chart the current values and immediately if wrong or correct.
        This is helpful if you can see the plot and track the progression of the script, but in contrast to what you are providing this would not be helpful for me to provide an answer. Print statements in addition to the syntax used in the print statement would be helpful as I could then compare the syntax directly with the output. I could also run that code to see if I can recreate the result and output values to compare with your test. This would help to answer the question of why the graphic is displaying the incorrect value, it may not be incorrectly rounded but something else may be happening as well. Without being able to see the full context for the question I could only guess what is happening here.

        Code:
         I dont know how to do the print statement.
        We have information on how to use the Print statement which goes along with the Tools -> Output window in the help guide.



        Code:
        There´s nothing more in the code than rounding the open and doing this once a day and not all day long with every bar.
        Yes, but we don't know where the problem is stemming from so this is still what you will need to address first. Print statements would be my suggestion here so you can output the values of each part of the calculation every time this is called to better understand where the problem is. In what you have shown I cannot tell what may be happening as I don't have the full context of the script or the test. I can see the values you output in the image but I have no context of when you are plotting this data in your script and how that is working in contrast to your calculation.

        I would still suggest that you make a simple sample of just this code to confirm the calculated value is still not correct. If the sample demonstrates the incorrect rounding the sample could then be uploaded to your post so that we can review the full context of the question together.


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

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by andrewtrades, Today, 04:57 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by chbruno, Today, 04:10 PM
        0 responses
        3 views
        0 likes
        Last Post chbruno
        by chbruno
         
        Started by josh18955, 03-25-2023, 11:16 AM
        6 responses
        436 views
        0 likes
        Last Post Delerium  
        Started by FAQtrader, Today, 03:35 PM
        0 responses
        7 views
        0 likes
        Last Post FAQtrader  
        Started by rocketman7, Today, 09:41 AM
        5 responses
        19 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X