Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Compare a price to an indicator at a specified time

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

    Compare a price to an indicator at a specified time

    Hello,

    When evaluating a potential entry, is there a way to compare price to an indicator at a specific time in the day?

    For example, I would like enter long at the market if the price of a stock is above the 20 day SMA at 3:55 PM EST, 5 minutes before close. So far I am only able to check if the stock closed above the 20 day SMA at the close and then code an entry for the open on the next day. This does not allow me to take advantage of overnight gaps. Any way to code this?

    Thank you very much!

    #2
    Originally posted by hausebrent View Post
    Hello,

    When evaluating a potential entry, is there a way to compare price to an indicator at a specific time in the day?

    For example, I would like enter long at the market if the price of a stock is above the 20 day SMA at 3:55 PM EST, 5 minutes before close. So far I am only able to check if the stock closed above the 20 day SMA at the close and then code an entry for the open on the next day. This does not allow me to take advantage of overnight gaps. Any way to code this?

    Thank you very much!
    If you are running this live and not on Historical data you can use DateTime.Now to know what time your computer's clock has. Review Microsoft's DataTime in the C# doc's.

    If you want to do this on historical data, you can't use DateTime.Now... because that is the current time.

    One way to do it would be to run a 1 minute secondary bar series ( or other minute value... 5 would work for you), and use the NinjaScript Time and/or ToTime to check the close time of every minute bar so you know when 5 minutes to market close is...

    There must be more elegant ways.... I would like to know of any more elegant ways to kow what time it is within historical data....if anyone cares to share
    Last edited by Crassius; 08-14-2012, 02:51 PM.

    Comment


      #3
      Hello,

      There are two ways you can do this.

      When you turn on a strategy you can carry this value forward and then check it on the current bar.

      For example:

      private double trackedSMAPrice = 0.00;
      private bool doOnce = true;

      // http://www.ninjatrader.com/support/h...rofsession.htm
      if(Bars.FirstBarofSession)
      {
      doOnce = true;
      }

      if(Time[0] >= ToTime(3, 55, 00) && doOnce)
      {
      trackedSMAPrice = SMA(20)[0];
      doOnce = false;
      }



      Then when it comes time to take a long based on your condition.

      if (Close[0] > trackedSMAPrice)
      ...


      The other method is using the following method to get the bar index of the bar at that time.




      -Brett

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by lightsun47, Today, 03:51 PM
      0 responses
      5 views
      0 likes
      Last Post lightsun47  
      Started by 00nevest, Today, 02:27 PM
      1 response
      10 views
      0 likes
      Last Post 00nevest  
      Started by futtrader, 04-21-2024, 01:50 AM
      4 responses
      46 views
      0 likes
      Last Post futtrader  
      Started by Option Whisperer, Today, 09:55 AM
      1 response
      14 views
      0 likes
      Last Post bltdavid  
      Started by port119, Today, 02:43 PM
      0 responses
      10 views
      0 likes
      Last Post port119
      by port119
       
      Working...
      X