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 burtoninlondon, Today, 12:38 AM
      0 responses
      5 views
      0 likes
      Last Post burtoninlondon  
      Started by AaronKoRn, Yesterday, 09:49 PM
      0 responses
      14 views
      0 likes
      Last Post AaronKoRn  
      Started by carnitron, Yesterday, 08:42 PM
      0 responses
      11 views
      0 likes
      Last Post carnitron  
      Started by strategist007, Yesterday, 07:51 PM
      0 responses
      13 views
      0 likes
      Last Post strategist007  
      Started by StockTrader88, 03-06-2021, 08:58 AM
      44 responses
      3,982 views
      3 likes
      Last Post jhudas88  
      Working...
      X