• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stochastics error? - chart data does not match NinjaScript condition

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

    Stochastics error? - chart data does not match NinjaScript condition

    Hello,

    I found out a peculiar error. I try to DrawText, when Stochastics gets below certain values.

    When I was testing it out I found several occasions when NinjaScript draws the text but it should NOT do so, since data in the chart show that the NinjaScript condition is not met (see attached picture).

    Any ideas where I am making a mistake?

    #2
    Hello kadan,

    Thank you for your post.

    I see that you are adding two additional series, but you have not added any filtering for which series should execute this condition. Right now, the condition could become true for any of the three series but your chart is only displaying the daily stochastics. For this to match the chart stochastics, you would likely need to remove the two additional series the script is adding so it only uses daily data.

    Another item is the print you are using, this is not helpful to understand why the condition happened, only that it did. A better print would be to print out the values the condition uses to understand why it was true. You may additionally want to include the BarsInProgress in the print if you plan on using a multii series script to know which series executed the logic.

    Print(BarsInProgress);



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

    Comment


      #3
      Hello Jesse,

      Thank you for teaching me something new. C## is difficult for me (compared to Python) but thanks to this forum I learn small steps at a time.

      My ultimate aim is to test 3 data series. I have solved the issue above by adding 1 data series - Add(PeriodType.Day,1). The code seems to work as expected now :-)

      I was also searching this forum for answer to another question (but I could not find exactly what I want to achieve):
      2. I would like to have the Drawtext to move to the right with every new bar (see attached picture)

      I found a thread suggesting making variable for last bar but I was not able to put that into practice either. Do you have any hints please.

      Comment


        #4
        Hello kadan,

        In the image it looks like the text is only getting called when that condition becomes true. If you wanted this to track along with the current bar, it would need to be called on each bar. This would be a good use case for a variable.

        Here is a simple example of what I mean

        Code:
        private double myTextValue;
        
        protected override void OnBarUpdate()
        {
            if(CurrentBar == 0)
            {
                 myTextValue = Open[0];    
            }
            if(Close[0] > Open[0])
            {
                myTextValue = Open[0] + 2 * TickSize;
            }
        
            DrawText("MyText", "MyText", 0, myTextValue, Color.Red);
        }
        Based on the condition becoming true, it will reset the value of the variable, the text will move to the new location each time this happens and also track with the current bar. Pay specific attention to where the DrawText is placed in contrast to the braces, it is outside of the condition but within OnBarUpdate.



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

        Comment


          #5
          Hello Jesse,

          Great stuff. This is exactly what I was searching for.

          Thank you very much for your help

          Comment


            #6
            Hello Jesse,

            I was able to implement your suggestion in post #4 but only with one condition.

            When I test several conditions I am not able to replicate this behavior of Drawtext (see attachments).

            1. When I put DrawText inside curly brackets the script compiles OK, but DrawText does not move with the last bar on the chart.
            2. When I put the curly bracket in front of the DrawText I get error while compiling.

            I can't figure it out. Could you kindly provide me with some direction
            Attached Files

            Comment


              #7
              Hello kadan,

              Thank you for your reply.

              I created a couple of images to help highlight the problem here.

              In the first case, you have the draw syntax inside of your condition (see image 1). Being inside of the if condition, the Draw syntax is only called when the condition is true. For the object to be updated each bar, it needs to go in just OnBarUpdate outside of any condition.

              The second case I used red to highlight the area between the if and its matching else statement. The area between an if else is not a code region so you cannot place code in between the else and the closing brace of the if statement. I highlighted in green the next area outside of the if block which would be a valid location.




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

              Comment


                #8
                Hello Jesse,

                Thank you for all the feedback. It has helped me a lot.

                I reallly appreciate the level of service of moderators in this forum. Keep up the good work guys :-)

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by saeed, Today, 10:17 AM
                3 responses
                14 views
                0 likes
                Last Post NinjaTrader_Kate  
                Started by ntbone, Yesterday, 08:10 PM
                2 responses
                24 views
                0 likes
                Last Post ntbone
                by ntbone
                 
                Started by Bougie_NT8, Today, 08:44 AM
                1 response
                4 views
                0 likes
                Last Post NinjaTrader_Tyler  
                Started by pjsmith, Today, 02:56 AM
                6 responses
                14 views
                0 likes
                Last Post pjsmith
                by pjsmith
                 
                Started by bubblegum, Today, 01:13 AM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_ChrisL  
                Working...
                X