• 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

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.
    https://ninjatrader.com/support/help...ttickofbar.htm
    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:	1
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.
            http://ninjatrader.com/support/helpG...-us/export.htm
            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.
                    https://drive.google.com/file/d/1X2A...w?usp=drivesdk


                    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).
                        https://drive.google.com/file/d/1eJA...w?usp=drivesdk

                        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 CandySNK, Today, 10:24 PM
                        0 responses
                        3 views
                        0 likes
                        Last Post CandySNK  
                        Started by user1986, Today, 07:28 PM
                        2 responses
                        11 views
                        0 likes
                        Last Post NinjaTrader_EricB  
                        Started by ericson, Today, 08:14 PM
                        0 responses
                        7 views
                        0 likes
                        Last Post ericson
                        by ericson
                         
                        Started by jertrade, Today, 06:57 PM
                        0 responses
                        5 views
                        0 likes
                        Last Post jertrade  
                        Started by Emma1, Today, 02:42 PM
                        1 response
                        17 views
                        0 likes
                        Last Post NinjaTrader_DrewO  
                        Working...
                        X