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

Newbie - Place order once from within OnBarUpdate

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

    Newbie - Place order once from within OnBarUpdate

    Hi,

    Newbie question - and I have been looking at the forum but I might just need a little pointing in the right direction.

    I simply want to place an order once from within OnBarUpdate and then not have it constantly resubmit on every tick - so I used a Boolean but when I do the order never gets to Sim101.....its not a real strategy just trying to get to grips with how NT works

    I have at the top....
    #region Variables
    privateint lotSize = 1; // Default setting for LotSize
    privatebool entrySubmitS = false;
    #endregion

    ...then further down I have....
    protectedoverridevoid OnBarUpdate()
    {
    if (entrySubmitS == false)
    {
    Print("OnBarUpdate(): S" + Time[0]);
    // Only allow entries if we in time zone
    if ((ToTime(Time[0]) >= 110000 && ToTime(Time[0]) < 143500))
    {
    // Entry Signal:
    EnterShortStop(LotSize, GetCurrentBid() + -15 * TickSize, "D2");
    EnterShortStop(LotSize, GetCurrentBid() + -
    20 * TickSize, "D3");
    entrySubmitS = true;
    }
    Print(
    "OnBarUpdate(): Out S" + Time[0]);
    }}

    ...so basically once we are in the time zone I want to put in those two orders and then stay at that position in the queue. Currently it resubmits on every tic update - naturally. But the Boolean switch when put in there to true stops even the inital order being sent in.



    Apologies if I have missed the obvious - the forum is great - I can see loads of great things I would like to try. Thanks

    #2
    OddNick, welcome to the forums - I think this happens because you never reset the switch to allow for new orders coming in, you can try this for example with

    if (Historical) return;

    at the OnBarUpdate() start, thus placing the order once in realtime and then stopping to see how it behaves.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Many thanks for that - it works great now I have done that.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by rayyyu12, Today, 12:47 AM
      0 responses
      2 views
      0 likes
      Last Post rayyyu12  
      Started by ETFVoyageur, 05-07-2024, 07:05 PM
      17 responses
      133 views
      0 likes
      Last Post ETFVoyageur  
      Started by ETFVoyageur, Yesterday, 10:13 PM
      1 response
      8 views
      0 likes
      Last Post ETFVoyageur  
      Started by somethingcomplex, Yesterday, 10:36 PM
      0 responses
      9 views
      0 likes
      Last Post somethingcomplex  
      Started by sofortune, 05-10-2024, 10:28 AM
      5 responses
      22 views
      0 likes
      Last Post sofortune  
      Working...
      X