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 Jon17, Today, 04:33 PM
        0 responses
        1 view
        0 likes
        Last Post Jon17
        by Jon17
         
        Started by Javierw.ok, Today, 04:12 PM
        0 responses
        6 views
        0 likes
        Last Post Javierw.ok  
        Started by timmbbo, Today, 08:59 AM
        2 responses
        10 views
        0 likes
        Last Post bltdavid  
        Started by alifarahani, Today, 09:40 AM
        6 responses
        41 views
        0 likes
        Last Post alifarahani  
        Started by Waxavi, Today, 02:10 AM
        1 response
        20 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Working...
        X