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

Code for A Market Entry At Bar Close Price?

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

    Code for A Market Entry At Bar Close Price?

    Hi,

    I am looking for any help or ideas on a piece of code which would place an order at the price of the close of the current bar and something that would work within chart trader for discretionary trading not a strategy...

    Code:
    Order o = a.CreateOrder(Instrument,OrderAction.Buy,OrderType.Limit,TimeInForce.Day,quantity, (double)nudBuyLmtPr.Value,0,"","Buy");
    				o.Submit();
    I get this to work but how can I get it to set the order, wait for the currnt bar to close and then enter at the price of the close?

    Thanks for any help!

    #2
    Hello tshirtdeal,

    Thank you for your post.

    A bar is not considered closed until the next tick for the new bar is received. With that, you best bet would be to use FirstTickOfBar in your logic to submit the order when the very first tick of the new bar is received.

    http://www.ninjatrader.com/support/h...ttickofbar.htm

    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the help!

      So here is my long order button

      if (a != null)
      {
      Order o = a.CreateOrder(Instrument,OrderAction.Sell,OrderTyp e.Limit,TimeInForce.Day,quantity, (double)nudSellLmtPr.Value,0,"","Sell");
      o.Submit();

      How do I get to tell it to wait for the (FirstTickOfBar)?

      Is there something I can code in onBarUpdate() that will make the button place the order on the firsttickofbar?


      I got it to work in strategy but I need it to work in chart trader so any help is greatly appreciated!
      Thanks again

      Comment


        #4
        Hello Tshirtdeal,

        A thought would be that you have a bool variable set to false and when you click the button, it would set it true which you would then have a test in your if( a != null) statement and the FirstTickOfBar as well.

        example -
        if( a != null & FirstTickOfBar && myBool)
        {
        submit order;
        }

        I don't believe you would be able to get this to work with the chart trader, as that is a protected and internal code with the NinjaTrader Application.
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Thanks Cal,

          I have got the buttons on the chart trader and working under different conditions.. I just cannot get them to work for this condition.

          As I have stated I have got the condition to work in a strategy with buttons in the toolbar but then I lose my quick ability to load an atm with order size and stop loaded for the entry (which I need) I trade different equities each day in different price and lot sizes and need quick ordering...

          any ideas appreciated as I am working on this throughout the day...

          Comment


            #6
            tshirtdeal,

            I'm not sure how you are getting the other buttons to submit other orders, but this is unsupported and as such don't have any documentation.

            I would need to test the script on my end in order to determine what might be going on.
            Cal H.NinjaTrader Customer Service

            Comment


              #7
              Indicator

              Hi Cal,

              Here is the indicator... With some C# and creating an indicator you are able to create chart trader buttons... This is a script for limit buttons I have tweaked to meet my needs, as I said I just need the buttons to place the order but wait to enter at the close (or as you said) the opening price of the next bar..

              This is the code as of so far working without an attempt to get the (FirstTickOfBar) order...

              Thanks for any help and advice as I really need this
              Attached Files

              Comment


                #8
                tshirtdeal,

                Thank you for the script.

                What you would want to do is create the order in your button method for the account, but in OnBarUpdate have it check for FirstTickOfBar and the Bool variable and then to submit the order. You would want to create the Order variable global to the class so that you can access outside the button method.

                So in your button method -
                Code:
                if (a != null)
                	{
                		o = a.CreateOrder(Instrument,OrderAction.Buy,OrderType.Limit,TimeInForce.Day,quantity, (double)nudBuyLmtPr.Value,0,"","Buy");
                		myBool = true;
                	}
                in OnBarUpdate()
                Code:
                if(FirstTickOfBar && myBool)
                       {
                                o.Submit();
                                myBool = false;
                       }
                Let me know if this helps
                Cal H.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks!

                  It is very close, but getting an error in compile around this line

                  [QUOTE]
                  {
                  o.Submit();
                  myBool[0]= false;
                  } [QUOTE]

                  saying the name"o" does not exist in the current context? If I can get that I think it will work...

                  Comment


                    #10
                    Did you create the global class variable for o?

                    private Order o = null;

                    This should be placed in the variables section of the code.
                    Cal H.NinjaTrader Customer Service

                    Comment


                      #11
                      that was it, it compiles now and all looks great but the button will not place the order...

                      any ideas? so dang close... thanks for all the help I really appreciate it!

                      Comment


                        #12
                        Okay, so the orders are getting into the account, but they are not being filled, they just sit in the State "initialize" any ideas?
                        Last edited by tshirtdeal; 04-18-2014, 07:12 PM.

                        Comment


                          #13
                          Which market are you trading? Or is this replay? Most markets today were simply closed for Good Friday.
                          BertrandNinjaTrader Customer Service

                          Comment


                            #14
                            Hi Bertrand,

                            Just trading sim feed trying to work this out... i have now had better luck in strategy (never used strategies before) but since they let you place a hard stop and order account size it works...

                            Problem is I want to enter 1 tick above (or below) FirstTickOfBar


                            so how do I do that here?

                            }
                            if (btnEntry.Text != "SHORT"
                            && FirstTickOfBar )

                            {
                            EnterShort();
                            }




                            also I want/ need the strategy to stop running once my stoploss is hit... how do I do that?

                            Thanks for the help!
                            Last edited by tshirtdeal; 04-18-2014, 11:43 PM.

                            Comment


                              #15
                              actually programming it in a strategy isnt gonna work anyway... i need to be able and manually/ discretionary control my profit targets and exits...

                              But I did have it working in a strategy, just need those buttons to work in chart trader... So any help right now is greatly appreciated!

                              I would like to recommend that you guys allow the stop cash position (hard stop) and account sizing to the chart trader since you have it it for strategies... The ability to just enter the market at 25000$ worth of shares with a 100$ hard stop is something that would make chart trader a million times more efficient!

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by funk10101, Today, 09:43 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post funk10101  
                              Started by pkefal, 04-11-2024, 07:39 AM
                              11 responses
                              37 views
                              0 likes
                              Last Post jeronymite  
                              Started by bill2023, Yesterday, 08:51 AM
                              8 responses
                              44 views
                              0 likes
                              Last Post bill2023  
                              Started by yertle, Today, 08:38 AM
                              6 responses
                              26 views
                              0 likes
                              Last Post ryjoga
                              by ryjoga
                               
                              Started by algospoke, Yesterday, 06:40 PM
                              2 responses
                              24 views
                              0 likes
                              Last Post algospoke  
                              Working...
                              X