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

How to Call Indicator Calculate OnEachTick and OnBarClose in same chart

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

    How to Call Indicator Calculate OnEachTick and OnBarClose in same chart

    Hi

    How to call Indicator on calculate OnEachTick after Calculate OnBarClose is already in use


    Once if condition changes, chart should run back with Calculate bar close and again call calculate on each tick like

    if (State == State.SetDefaults)
    {
    Calculate = Calculate.OnBarClose;
    }
    void OnBarUpdate(){
    If (Condition = True)
    Call Calculate On each tick
    If (Condition = True)
    Call Calculate On each tick
    }
    AFTER ONBARUPDATE THAT RESET BY DEFAULT VALUE Calculate = Calculate.OnBarClose;

    #2
    Hello yeshujbp,

    Thank you for your note.

    When Calculation is .OnEachTick, IsFirstTickOfBar will be true only after a bar has closed. Require this to be true for the conditions that trigger actions only when the bar is closing.

    Below is a link to the help guide which includes a code sample.

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi
      Thanks for reply

      my code is
      protected override void OnBarUpdate()
      {

      if (State == State.Historical)
      {
      return;
      }
      else
      // i used Calculate.OnEachTick so i used IsFirstTickOfBar
      if(IsFirstTickOfBar)
      {

      //check green reversal bar

      if ((Close[0] > Open[0] && Close[1] < Open[1]))
      {

      high = High[1]-Low[1];
      flag = true;
      per = high * 30 / 100;
      comp = High[1] - per;
      redflag = false;
      Draw.Dot(this, "Slave" + comp + "pre=" + per + Close[0], true, 1, Close[0], Brushes.Black);

      }
      //check red reversal bar
      if ((Close[0] < Open[0] && Close[1] > Open[1]))
      {
      flag = false;
      high = High[1]-Low[1];
      redflag = true;
      per = high * 30 / 100;
      comp = Low[1] + per;
      redtemp=false;
      Draw.Dot(this, "Slaves" + comp + "pre=" + per + Close[0], true, 1, Close[0], Brushes.Black);


      }
      }


      i used Calculate.OnEachTick so i used IsFirstTickOfBar that condition true only first tick of bar but i got multi-pal Black dot.like
      Click image for larger version

Name:	nt8 f.JPG
Views:	868
Size:	74.7 KB
ID:	1061067
      what is problem ?




      Comment


        #4
        Hello yeshujbp,

        Have you compiled after making changes?

        Has the script been reloaded on the chart?

        Are you certain the script you are editing and compiling is the script on the chart?
        (The chart is showing yellow dots which are not in the code you have provided)
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          hi
          yes i compiled many times but same problem occur. this is half code yellow dots draw after this condition .full code


          protected override void OnBarUpdate()
          {

          if (State == State.Historical)
          {
          return;
          }
          else
          // i used Calculate.OnEachTick so i used IsFirstTickOfBar
          if(IsFirstTickOfBar)
          {

          //check green reversal bar

          if ((Close[0] > Open[0] && Close[1] < Open[1]))
          {

          high = High[1]-Low[1];
          flag = true;
          per = high * 30 / 100;
          comp = High[1] - per;
          redflag = false;
          Draw.Dot(this, "Slave" + comp + "pre=" + per + Close[0], true, 1, Close[0], Brushes.Black);

          }
          //check red reversal bar
          if ((Close[0] < Open[0] && Close[1] > Open[1]))
          {
          flag = false;
          high = High[1]-Low[1];
          redflag = true;
          per = high * 30 / 100;
          comp = Low[1] + per;
          redtemp=false;
          Draw.Dot(this, "Slaves" + comp + "pre=" + per + Close[0], true, 1, Close[0], Brushes.Black);


          }
          }
          if (flag)
          {
          if (Low[0] <= comp)
          {
          Draw.Dot(this, "S" + CurrentBar, true, 0, High[0], Brushes.Yellow);
          return;
          }
          }
          if (redflag)
          {
          if (High[0] >= comp)
          {
          Draw.Dot(this, "Sh" + CurrentBar, true, 0, High[0], Brushes.Yellow);
          return;
          }
          }

          Comment


            #6
            Hello yeshujbp,

            May I test your script?

            To export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
            1. Click Tools -> Export -> NinjaScript...
            2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
            3. Click the 'Export' button
            4. Enter a unique name for the file in the value for 'File name:'
            5. Choose a save location -> click Save
            6. Click OK to clear the export location message
            By default your exported file will be in the following location:
            • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
            Below is a link to the help guide on Exporting NinjaScripts.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Thanks for your support

              That is my script file check it.
              Attached Files
              Last edited by yeshujbp; 06-18-2019, 02:11 PM.

              Comment


                #8
                Hello yeshujbp,

                Are you 100% certain this is the exact script you are running?

                This script can't be run. Smscriteria is not initialized to a new List object and causes a run-time error OnStartUp().

                What is the actual script you are running?
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hi yes this is correct script i am facing issue if(IsFirstTickOfBar) condition that run many times.

                  List object is other thing is comment it and is my run-able final script.PFA
                  Attached Files

                  Comment


                    #10
                    Hello yeshujbp,

                    I have run the new script from your last post #9 on a ES 09-19 1 Minute chart in playback for two days and I am not finding the conditions are ever true for a drawing object to be drawn.

                    Below is a link to a video.



                    Is there a specific date and time and instrument this needs to be run on?
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi
                      Thanks
                      I am sending script also send chart that run properly .plz focus on bold if-condition that not work-properly
                      if(IsFirstTickOfBar){
                      //if ((Close[1] > Open[1] && Close[2] < Open[2]))
                      if ((Close[0] > Open[0] && Close[1] < Open[1]))

                      {
                      index= Bars.GetBar(Time[1]);


                      double ss=(double)Smscriteria;

                      high = High[1]-Low[1];
                      flag = true;
                      per = high * 30 / 100;
                      comp = High[1] - per;
                      redflag = false;

                      string smstext="New Long Signal "+Bars.BarsType.DisplayName+" Alert for "+Bars.Instrument.FullName;
                      //Smssent(smstext);

                      gcounter++;

                      Draw.Dot(this, gcounter+"Slaves" + comp + "pre=" + per + Close[1], true, 1, Close[1], Brushes.Black);


                      }
                      //if ((Close[1] < Open[1] && Close[2] > Open[2]))
                      if ((Close[0] < Open[0] && Close[1] > Open[1]))
                      {

                      index= Bars.GetBar(Time[1]);

                      double ss=(double)Smscriteria;
                      flag = false;
                      high = High[1]-Low[1];
                      redflag = true;
                      per = high * ss / 100;
                      comp = Low[1] + per;

                      rcounter++;
                      Draw.Dot(this, rcounter+"Slaves" + comp + "pre=" + per + Close[1], true, 1, Close[1], Brushes.Black);
                      string smstext="New Short Signal "+Bars.BarsType.DisplayName+" Alert for "+Bars.Instrument.FullName;
                      //Smssent(smstext);

                      }
                      }


                      Last edited by yeshujbp; 07-06-2019, 01:07 PM.

                      Comment


                        #12
                        Hello yeshujbp,

                        To confirm, you are not able to reproduce this behavior when using 1 minute ES 09-18 minute bars?

                        I am not able to debug or assist you with logic and each time you provide the script the code is changing, so we are not testing the same code.

                        Instead I am providing you with a simplified demonstration script that shows a dot being drawn once on each new bar with Calculate set to .OnEachTick.

                        Below is a link to a video testing the exact script attached (without any changes to the code).


                        In your custom logic, I recommend using prints to see when the condition is evaluating as true.

                        This thread will remain open for any community members that would like to assist with your custom logic.

                        You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our business development follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request.
                        Attached Files
                        Chelsea B.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by elirion, Today, 01:36 AM
                        0 responses
                        2 views
                        0 likes
                        Last Post elirion
                        by elirion
                         
                        Started by gentlebenthebear, Today, 01:30 AM
                        0 responses
                        2 views
                        0 likes
                        Last Post gentlebenthebear  
                        Started by samish18, Yesterday, 08:31 AM
                        2 responses
                        9 views
                        0 likes
                        Last Post elirion
                        by elirion
                         
                        Started by Mestor, 03-10-2023, 01:50 AM
                        16 responses
                        389 views
                        0 likes
                        Last Post z.franck  
                        Started by rtwave, 04-12-2024, 09:30 AM
                        4 responses
                        31 views
                        0 likes
                        Last Post rtwave
                        by rtwave
                         
                        Working...
                        X