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 josh18955, 03-25-2023, 11:16 AM
      6 responses
      435 views
      0 likes
      Last Post Delerium  
      Started by FAQtrader, Today, 03:35 PM
      0 responses
      3 views
      0 likes
      Last Post FAQtrader  
      Started by rocketman7, Today, 09:41 AM
      5 responses
      18 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by frslvr, 04-11-2024, 07:26 AM
      9 responses
      126 views
      1 like
      Last Post caryc123  
      Started by selu72, Today, 02:01 PM
      1 response
      12 views
      0 likes
      Last Post NinjaTrader_Zachary  
      Working...
      X