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

Incorrect values from EVERYTHING

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

    Incorrect values from EVERYTHING

    I'm programming some indicators and of course using the output window with Print statements. When looking at the values of say:

    double value = MACD(12, 26, 9).Diff[0];
    Print(Time[0].ToString() + "The current MACD DIFF value is " + value.ToString());

    and comparing the output values printed with the statement above to whats going on in the chart, it's sometimes incorrect! This seems to happen with most Print statements.I use trying to get values from the chart. So when I'm programing an indi, it's working about 80% of the time.

    So I have a simple IF statement:
    if( MACD(12,26,9).Diff[0] >= .4 && MACD(12,26,9).Avg[0] > -.5 && MACD(12,26,9).Avg[0] < .5 && Close[0] >= EMA(20)[0] )
    Draw.ArrowUp(this, CurrentBar.ToString(), true, 0, Low[0] - TickSize, Brushes.Lime);

    and it occasionally puts the up arrow in a totally incorrect spot. That Macd.Diff[0] is definitely not over the .4 value in the picture attached

    8/22/2022 9:09:07 AMThe current MACD DIFF value is -0.445061053749779
    8/22/2022 9:09:07 AMThe current MACD AVG value is -0.459982212843787
    8/22/2022 9:09:52 AMThe current MACD DIFF value is 0.423138811727991
    8/22/2022 9:09:52 AMThe current MACD AVG value is -0.479593036466437
    8/22/2022 9:09:56 AMThe current MACD DIFF value is 0.447511200504411
    8/22/2022 9:09:56 AMThe current MACD AVG value is -0.367715236340334
    8/22/2022 9:09:59 AMThe current MACD DIFF value is 0.458634870584208
    8/22/2022 9:09:59 AMThe current MACD AVG value is -0.253056518694282
    8/22/2022 9:10:03 AMThe current MACD DIFF value is 0.427917225736657
    8/22/2022 9:10:03 AMThe current MACD AVG value is -0.146077212260117
    8/22/2022 9:10:09 AMThe current MACD DIFF value is 0.403518046988103
    8/22/2022 9:10:09 AMThe current MACD AVG value is -0.0451977005130917
    8/22/2022 9:10:11 AMThe current MACD DIFF value is 0.415347338305496
    8/22/2022 9:10:11 AMThe current MACD AVG value is 0.0586391340632824
    8/22/2022 9:10:55 AMThe current MACD DIFF value is -0.409898082600649
    8/22/2022 9:10:55 AMThe current MACD AVG value is 0.0734311354267453
    8/22/2022 9:40:46 AMThe current MACD DIFF value is 0.435389947086998
    8/22/2022 9:40:46 AMThe current MACD AVG value is 0.0191083602385957

    this happens with all indi's that i'm trying to get a value from and using similar code to just place an arrow when the if statement is true.

    why is there a mismatch between the output values and what is showing on the chart??


    Attached Files
    Last edited by dynamiclink; 08-25-2022, 05:57 AM.

    #2
    Just found another issue. How does the chart validate as true?? Macd.diff is not less than -.4, the macd.avg is definitely not between -.5 and .5, and close is definitely not below EMA20???

    if( MACD(12,26,9).Diff[0] <= -.4 && MACD(12,26,9).Avg[0] > -.5 && MACD(12,26,9).Avg[0] < .5 && Close[0] <= EMA(20)[0])



    Attached Files

    Comment


      #3
      Hello dynamiclink,

      Thank you for your post.

      First, I would like to clarify that the Print() method already converts object data into a string format. You do not need to use .ToString(), so your statement could be simplified:

      Print(Time[0] + "The current MACD DIFF value is " + value);

      For more information regarding the Print() method:


      Additionally, in order to better understand the behavior of your script and when the arrows are drawn, please print the time and all values being used in your condition. This will give a more complete picture of what the values are when your condition is evaluated to true and drawing the arrows. Here is an example of a more complete print statement you could use (Note, I utilized String.Format in this statement. More information may be found in the publicly available Microsoft documentation):

      Print(string.Format("{0} | Value[0]: {1} - Avg[0]: {2} = {3}, Diff[0]: {4}", Time[0], myMACD.Value[0], myMACD.Avg[0], (myMACD.Value[0] - myMACD.Avg[0]), myMACD.Diff[0]));

      I recommend using this print statement outside of your conditions and then adding a similar print statement inside of your conditions that maybe also states something like "Arrow Drawn" so you can see what the values were when the arrow was drawn. This should help you to debug and further understand the behavior of your script. For more information on how to debug and use print statements, please see the post here:



      Please let us know if we may be of further assistance.
      Emily C.NinjaTrader Customer Service

      Comment


        #4
        My first post clearly shows the information you are looking for. The output of Print shows a value at 9:09 am of -.4 for the MACD.Diff and then jumps to a positive .4 40 seconds later.. On the attached picture there are UP arrows drawn at 9:09am which do not match the IF statement logic I provided and if you look at the DIFF graph on the MACD it is no where near .4 in value. why does the DIFF value jump like that. It happens on every indicator I have output with print and screws up my condition logic...

        8/22/2022 9:09:07 AMThe current MACD DIFF value is -0.445061053749779
        8/22/2022 9:09:52 AMThe current MACD DIFF value is 0.423138811727991

        Comment


          #5
          Hello dynamiclink,

          Thank you for your patience.

          I have created a test script that uses your condition to draw the up arrow. I also added the suggested print both inside and outside of the condition, and when printed inside of the condition I added "ARROW DRAWN" to the beginning of the print. I made a video where I add the test indicator to a chart, as well as the same EMA and MACD indicators that I am using in the script. Per the NinjaScript Output and the data box, the values are correct when the arrow is drawn. Please import this script and test on your end. If you still encounter issues, could you please demonstrate with this test script and/or provide any modified steps to get to the same result you are seeing?

          MACDPrintsTest_NT8.zip

          Video of my test: https://www.screencast.com/t/Aa0GSU3B

          I look forward to your reply.
          Emily C.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Christopher_R, Today, 12:29 AM
          0 responses
          7 views
          0 likes
          Last Post Christopher_R  
          Started by sidlercom80, 10-28-2023, 08:49 AM
          166 responses
          2,235 views
          0 likes
          Last Post sidlercom80  
          Started by thread, Yesterday, 11:58 PM
          0 responses
          3 views
          0 likes
          Last Post thread
          by thread
           
          Started by jclose, Yesterday, 09:37 PM
          0 responses
          7 views
          0 likes
          Last Post jclose
          by jclose
           
          Started by WeyldFalcon, 08-07-2020, 06:13 AM
          10 responses
          1,415 views
          0 likes
          Last Post Traderontheroad  
          Working...
          X