Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Plotting indicator for only last 2 days

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

    Plotting indicator for only last 2 days

    Hi Support/Ninjausers,

    In an indicator code,if one wants to make it to plot only for last 2 days,how can one do it( even though chart is loaded for like 10 days)?

    Can one do something like below at start of the code:

    if ( CurrentDay < 3)
    {return;}

    Thanks
    Commodity_Trader

    #2
    If you only want last two days, how about just drawing a line instead of using a plot?

    DrawLine("MyLine", 1, startingYValue, 0, endingYValue, Color.Blue);
    RayNinjaTrader Customer Service

    Comment


      #3
      Hi Ray,

      Thanks for the reply.

      No, I am not sure if I posted my question correctly. I am trying to make the indicator OnBarUpdate method work, only for last 2 days. So that, as soon as OnBarUpdate is called, and it sees the below condition and it knows to skip the bar/day. And it executes the indicator code for only last 2 days of the chart( even though the chart is like loaded for last 10 days, just trying to minimise the drawobjects on the chart that the indicator makes)

      At the start of OnBarUpdate can I do something like below,..so that it executes the code below this for only last 2 days (when someone does a refresh by F5 on the indicator).

      if ( CurrentDay < 3)
      {return;}


      Thanks
      Commodity_trader

      Comment


        #4
        commodity_trader,

        If you only have draw objects in question you could just use two unique signal names and alternate off using which one. That way every time you draw an object it will move the old one forward and you are left with only two of the latest objects.

        untested code
        Code:
        if (CurrentBar % 2 == 0)
             useObj1 = true;
        else
             useObj2 = true;
        
        if (useObj1)
        {
             DrawDot("object1", true, 0, Close[0], Color.Red);
             useObj1 = false;
        }
        else if (useObj2)
        {
             DrawDot("object2", true, 0, Close[0], Color.Blue);
             useObj2 = false;
        }
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Thanks Josh.

          But if there are multiple draw objects,..there isn't any method in ninjascript like "currentday",..that one can check similar to like "currentbar" ? Or may be I have to try using the Time function to find if "today" is one of last 2 days.


          Thanks
          Commodity_trader

          Comment


            #6
            commodity_trader,

            You can use DateTime.Now and use ToDay(DateTime.Now) to get today's date and then compare ToDay(Time[0]) to that to see if it is today. Then make some comparison based off of that. The problem with this approach is that DateTime.NOw is based off of your system clock and if you are running this not on a chart with today the calculations will be thrown off for historical charts.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Hello,

              Could someone, please, help what to do if I have an indicator (let say MarketProfile) wich draws a lot of objects per day (volume histogramm) and I have 20 days of history in DataSeries.

              So, the question is , how to do calculations only for two-three days to minimize calculations and drawing objects?

              How to compare dates for that ?
              Thank you in advance for the answer.

              Short explanation what I want to do see in attached image.

              --
              Andriy
              Attached Files

              Comment


                #8
                Hello akushyn,

                While this is mostly a logic exercise, below is code that may help you to accomplish only drawing objects if the bar time is within the last 2 days preceding the current real time (last 3 days).
                Code:
                if (Time[0] >= DateTime.Now.AddDays(-2).Date)
                {
                // execute draw object code
                }
                OR to prevent all code from executing if the bar time is before 2 days ago, place this at the beginning of OnBarUpdate()
                Code:
                if (Time[0] < DateTime.Now.AddDays(-2).Date)
                {
                return;
                }
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Thank you for the answer. I have tried , but doesn't work.
                  Could you please check it by yourself?

                  Indicator source code in attached document.
                  Thank you.!
                  Attached Files

                  Comment


                    #10
                    Hello akushyn,

                    I have looked at the script you supplied, however, I am not seeing the suggested code in this.

                    I am attaching a working example to this post. This will draw dots every 5 bars but will not draw the dots on bars older than 2 days.

                    Follow these steps to import the NinjaScript:

                    1. Download the script to your desktop, keep it in the compressed .zip file.
                    2. From the Control Center window select the menu File > Utilities > Import NinjaScript
                    3. Select the downloaded .zip file
                    4. NinjaTrader will then confirm if the import has been successful.

                    Note that on any files that say "File already exists on your PC" that start with an "@" symbol are the ones that came preloaded inside of NinjaTrader so you would say "No" so that you do not override those files.
                    Attached Files
                    Chelsea B.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by jclose, Today, 09:37 PM
                    0 responses
                    5 views
                    0 likes
                    Last Post jclose
                    by jclose
                     
                    Started by WeyldFalcon, 08-07-2020, 06:13 AM
                    10 responses
                    1,413 views
                    0 likes
                    Last Post Traderontheroad  
                    Started by firefoxforum12, Today, 08:53 PM
                    0 responses
                    11 views
                    0 likes
                    Last Post firefoxforum12  
                    Started by stafe, Today, 08:34 PM
                    0 responses
                    11 views
                    0 likes
                    Last Post stafe
                    by stafe
                     
                    Started by sastrades, 01-31-2024, 10:19 PM
                    11 responses
                    169 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Working...
                    X