Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

How to have bot enter every X minutes

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

    How to have bot enter every X minutes

    Hello,

    I trade the ES market.

    I am building a strategy manually through ninjascript. The strategy only operates between the hours of 8:30:05 AM and 12:00PM. I would like to know how to have the strategy enter either long or short every, say 15 minutes, within that timeframe?
    below is a portion of of the script:

    Dataseries: ...Minute, 15);

    if ((ToTime(Time[0]) >= startTime && ToTime(Time[0]) < endTime))
    {
    if (Close[0] > Open[0])
    EnterShortStopMarket(0,true,Convert.ToInt32(OrderQ uantity), ShortEntryPrice, "ShortEntryPrice");
    }

    The strategy enters fine the first time; however, on its second time, I receive an error that reads "short stop order cannot be placed above market price".
    In this back test scenario, the historical market price on second entry is higher than the market price on the first entry.


    Thanks in advance.

    #2
    Hello Don22Trader1,

    The error you are seeing is likely that the price you are using is not valid when submitting the order. I don't see that you are calculating a price before submitting it, if you are not calculating a new price at the time you submit the order that would be the problem.

    JesseNinjaTrader Customer Service

    Comment


      #3
      The entry price is stated as ShortEntryPrice, and that value is defined as shown below:

      private double ShortEntryPrice;
      private int ShortEntryTicks = 4;

      OnBarUpdate()

      if (Position.MarketPosition == MarketPosition.Flat)
      {
      ShortEntryPrice = (Close[0] - (ShortEntryTicks * TickSize));
      }

      Basically I am looking to have the strategy enter 4 ticks below the close of the previous 15 minute bar and have it run continuously within the time frame of 8:30:05 AM - 12:00 PM.

      Comment


        #4
        Hello Don22Trader1,

        You may want to move that logic setting the variable to before the entry inside the entry condition so that a valid price is calculated at that time. I can't tell from the split up samples where that code exists in contrast to the entry at this point. You would otherwise need to check that the price is valid before submitting the order, if its not valid you would need to set some other price or not submit the order.

        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by slimcactus, Today, 10:26 AM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by Monares, Today, 10:49 AM
        3 responses
        17 views
        0 likes
        Last Post NinjaTrader_JustinD  
        Started by d122y, Today, 10:20 AM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_ChrisL  
        Started by trader3000a, Today, 06:41 AM
        1 response
        14 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by trader3000a, Today, 09:23 AM
        5 responses
        19 views
        0 likes
        Last Post trader3000a  
        Working...
        X