Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Entering and exiting specific contracts

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

    Entering and exiting specific contracts

    Hi, i would like to ask you few things..

    is there any way how could i be in 2 contracts in same time and then leave only the specific-one contract wich i want??
    i will explain...
    I tried something like this
    in initialize:
    {
    CalculateOnBarClose = true;
    ExitOnClose = true;
    Add(PeriodType.Tick, 1);
    EntriesPerDirection = 10;
    EntryHandling = EntryHandling.AllEntries;
    }

    and then in OnBarUpdate
    EnterLong("long1"); - this was entered in this position at 9AM
    EnterLong("long2"); - i called this at 10AM


    so now it is 1pm and i am in two different open positions in the same time.. great. And now i want to exit position long2. So i called ExitLong("long2");
    But NinjaTrader will exit the position which i opened at 9am (position long1).
    But thats wrong. What i wrote wrong? something in initialize?
    Is there even any way how could i realize this idea in code?
    This exiting only the specific open positions?...



    And my other question.. it is possible to be in long position and short position at the same time?
    For example... its 9am and i want to enter to long position..
    then it is 11am and i want to enter to short position but i want to have open the contract from 9am (the long position)
    ..when i am programming in ninjascript any trading systems for backtest always i could be only in short or only in long.
    When i have open any long position and then i call EnterShort(); it will close all my long position and open short. But i want to have theese long positions still open until i will call ExitLong(); or something..

    Thank you for your help

    #2
    zooinek, how do you determine NinjaTrader is exiting the 'wrong' position? For sure it's possible to work with multiple entry / exit signals at the same time in your code - http://www.ninjatrader-support2.com/...ead.php?t=3225

    You could also work with TraceOrders to debug the order behavior of your strategy - http://www.ninjatrader-support2.com/...ead.php?t=3627

    For the last question, I would suggest reviewing the 'Internal Order Handling Rules' at the bottom of this link - http://www.ninjatrader-support.com/H...verview36.html

    You could work around this by using two different individual strategies on the same instrument.

    Comment


      #3
      >> zooinek, how do you determine NinjaTrader is exiting the 'wrong' position?

      here i will you get an example what i mean..




      private bool long16 = true;
      private bool long17 = true;
      private bool long18 = true;
      private bool long19 = true;
      private bool long20 = true;
      private bool long21 = true;

      protected override void Initialize()
      {
      CalculateOnBarClose = true;
      EntriesPerDirection = 3;
      EntryHandling = EntryHandling.AllEntries;
      TraceOrders = true;
      }


      protected override void OnBarUpdate()
      {
      if (Time[0].Hour==16 && long16) {
      String name = "long"+(Time[0].Hour);
      EnterLong(name);
      long16=false;
      }
      if (Time[0].Hour==17 && long17) {
      String name = "long"+(Time[0].Hour);
      EnterLong(name);
      long17=false;
      }
      if (Time[0].Hour==18 && long18) {
      String name = "long"+(Time[0].Hour);
      EnterLong(name);
      long18=false;
      }
      if (Time[0].Hour==19 && long19) {
      ExitLong("long18");
      long19=false;
      }
      if (Time[0].Hour==20 && long20) {
      ExitLong("long17");
      long20=false;
      }
      if (Time[0].Hour==21 && long21) {
      ExitLong("long16");
      long21=false;
      }
      }

      i expect that at first i will exit the position from 18:00 (6pm), then i will exit position from 17:00 (5pm) and at last i will exit position from 16:00 (that is 4pm)
      But NinjaTrader is doing this.
      At first exit the oldest position (16:00), then exit the less old position (17:00) and at last will exit the at least old position (18:00).
      And thats wrong.
      It is wrong because my ninjascript code says that i want to exit position with name long18 as first and not as last. And i want to exit to exit the position with name long16 as last and not as first.

      Comment


        #4
        Thanks - which NinjaTrader version are you running zooinek? You can check under Help > About.

        Also: Have you confirmed your entryorder names are actually the way you expect them to be?

        Comment


          #5
          i am using NT version 6.5.1000.7
          i am sure that first order was EnterLong("long16"); then was EnterLong("long17"); and last was EnterLong("long18"); and the the exit orders was: first was ExitLong("long18"); then was ExitLong("long17"); and last was ExitLong("long16");

          The result is in attach RESULT.JPG
          But i want result like in RESULTwhatIwant.JPG (the black lines is what i expect)


          Ps: this is output from output window

          3.1.2007 16:00:00 Entered internal PlaceOrder() method at 3.1.2007 16:00:00: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='long16' FromEntrySignal=''

          3.1.2007 17:00:00 Entered internal PlaceOrder() method at 3.1.2007 17:00:00: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='long17' FromEntrySignal=''

          3.1.2007 18:00:00 Entered internal PlaceOrder() method at 3.1.2007 18:00:00: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='long18' FromEntrySignal=''

          3.1.2007 19:00:00 Entered internal PlaceOrder() method at 3.1.2007 19:00:00: Action=Sell OrderType=Market Quantity=0 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal='long18'

          3.1.2007 20:00:00 Entered internal PlaceOrder() method at 3.1.2007 20:00:00: Action=Sell OrderType=Market Quantity=0 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal='long17'

          3.1.2007 21:00:00 Entered internal PlaceOrder() method at 3.1.2007 21:00:00: Action=Sell OrderType=Market Quantity=0 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal='long16'
          Attached Files
          Last edited by zooinek; 06-01-2009, 02:38 PM. Reason: i forgot to add pictires

          Comment


            #6
            zooinek,

            Please update to NT6.5.1000.10 and then try again. Thank you.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              and where can i find any update installer please?
              because i already have NT installed and i have any hictoric data and custom indicators and strategies there so i dont want to uninstall this old version and then install new version..
              is there any update installer which install new updates and dont remove my data?
              thank you

              Comment


                #8
                Just go to Help > Download Site inside NinjaTrader and upgrade to 6.5.1000.10

                Comment


                  #9
                  great, its working now thank you...
                  but now i have another problem...
                  i was trying something with Exporting compiled assembly of selected source files few days ago (because i was trying if is possible to export my indicarots and strategies as .DLL files because i dont want to allow to see the source code of the strategies and indicators) and now i can not remove my custom strategies from strategy analyzer - backtest window.

                  i had some old strategies and then i removed them (by Tools - edit strategy - delete selected strategy) but this removed strategies are still in Strategy Analyzer.. why??
                  Last edited by zooinek; 06-02-2009, 01:45 PM.

                  Comment


                    #10
                    zooinek,

                    Please close your Strategy Analyzer, open NinjaScript editor, press F5 to compile, reopen Strategy Analyzer and it should be gone. If not, maybe a reopening of NinjaTrader will clear it out.
                    Josh P.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    558 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    324 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    101 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    545 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    547 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X