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

    #16
    Indicator So Far

    Here is the indicator so far if anyone wants to look at it...

    the orders instantly go through and then just get stuck in the state of "Initialized"

    In the strategy I get working, the order does not go right through , I push the button to execute the trade and it shows no order until the first tick of the new bar, then the order is placed and filled instantly...

    Thanks for any help!
    Attached Files

    Comment


      #17
      Hello tshirtdeal,

      Thanks for your suggestion. I will forward this to our development team for consideration. This is already possible inside of a NinjaScript Strategy when using the Set() methods.


      As for your Indicator, I see a few things.

      1. You are checking the current "myBool" when you want to check the value of it 1 bar ago because if the "FirstTickOfBar" is true NinjaTrader is creating a new bar.

      So you may try "if (FirstTickOfBar && myBool[1])"

      2. You are still creating a temporary variable in your Limit Click methods.

      Order o = a.CreateOrder(...)

      You will want to take out the Order in front of this to use the Global variable that you declared.
      JCNinjaTrader Customer Service

      Comment


        #18
        wow,

        thanks , I got it working by getting rid of the order running "private bool myBool;" in variables and just
        "if(FirstTickOfBar && myBool)"

        2 problems though, it is not picking up my chart trader ATM strategy and setting those order once filled... and also what is the best way to get it to enter 1 tick above/below firsttickofbar... I am aware of the command to do it but not sure which section/command it should be placed.


        also... when you say this "NinjaScript Strategy when using the Set() methods." does that mean you can tie it into manual chart trader somehow I am aware it can be done with strategy's as I learned the other day working on this... what would be killer is if you could have a chart trader ATM which was set for account size with a cash stop, so I could set it to auto enter me with 50,000$ worth of shares and always a stoploss of say 100$ for any/all order and equity prices... is this possible in chart trader today?

        Thanks for the help!

        Comment


          #19
          Hello tshirtdeal,

          Most likely the reason why your ATM Strategy is not being attached to your order is due to some other internal handling rules that are be associated with the order.

          As for your offset you may want to use a Limit order type and then use the offset menu that you have created instead of a OrderType.Mar****rder to submit your orders above or below the market price.

          The Set methods are going to be native to a Strategy itself, so you would not be able to use these methods inside of an Indicator or Chart Trader.

          You may try to manually program this by calculating the cash value of a tick size using the MasterInstrument.PointValue and the TickSize.


          JCNinjaTrader Customer Service

          Comment


            #20
            hmmm...

            well now the limit orders are not going in above or below market price but if I set to .10 it sets the order at .10 price not market plus .10

            also, I have another probelm once the order is set I cannot cancel it , it stays in "initialized" state and I can only cancel once the order is placed, but I need to be able to cancel the order once placed/before filled if need be...

            Thanks for any hlep

            Comment


              #21
              Hello tshirtdeal,

              How are you setting the price of the Limit Order? Are you adding the Offset Price to the close value?

              As for the orders stays in "Initialize" you would have to reset your Sim101 account to get ride of them.

              * From the NinjaTrader Control Center window select the menu Tools > Options
              * Select the "Simulator" tab
              * Press the "Reset" button
              JCNinjaTrader Customer Service

              Comment


                #22
                Here is the order code"

                o = a.CreateOrder(Instrument,OrderAction.Buy,OrderType .Limit,TimeInForce.Day,quantity, (double)nudBuyLmtPr.Value, 0,"","Buy");
                myBool = true;


                not sure where I need to specify close price...

                Thanks for any help

                Comment


                  #23
                  Hello tshirtdeal,

                  You are going to want to define this inside of the "Limit" price or where you are using the "(double)nudBuyLmtPr.Value" because this is going to be the price that your order is going to be submitted to.
                  JCNinjaTrader Customer Service

                  Comment


                    #24
                    Thanks JC,

                    The orders currently go through and the limit price is in the order in control center for any adjustments I make to the limit, but the order goes through at the opening price... You are saying that is because the close value is not defined in the logic?

                    Also, because I am trying to run something like this in a strategy as well to see which I prefer and fell more comfortable with.... In a strategy, is there a way to keep it from running on the "FirstTickOfBar" Once I have one order running I want the strategy to stop placing orders for that chart...

                    Thanks again for all the help, I really need this to continue trading right now ....

                    Comment


                      #25
                      Working A Bit In Strategy

                      Would someone mind just looking at it to make sure it looks okay? I never programmed a strategy and it makes me a bit nervous to trade live...

                      One thing I need is for one of the Setstoploss commands to take presedent not sure how to do it....

                      I also have this to keep it from entering trdaes at the FirstTickOfBar all the time.. but would rather have it only trades on push of a toolbar button leaving the strategy enabled if that is possible?



                      Code:
                      if(Performance.RealtimeTrades.Count > 0)
                      	return;
                      Thanks for any help
                      Attached Files
                      Last edited by tshirtdeal; 04-22-2014, 08:34 AM.

                      Comment


                        #26
                        tshirtdeal,

                        You would want to get rid of the FirstTickOfBar and try using the unmanaged approach for the order submission.

                        The reason for unmanaged is if on the next bar the condition is no longer true, with the managed approach, for the order it will get cancelled out. The unmanaged will submit the order with Live Until Cancelled. You will need to manage these orders, with your own internal logic such when to modify the order or cancel it out.

                        See the link below for the unmanaged approach -
                        http://www.ninjatrader.com/support/h...d_approach.htm

                        I'm not sure what you mean by the Set() takes precedence, however, if you do use the unmanaged approach you would not be able to use any of the managed approach order submissions, such as the Set().

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

                        Comment


                          #27
                          Thanks Cal, well maybe I will leave it because everything works pretty well with this...

                          ""
                          I'm not sure what you mean by the Set() takes precedence,
                          What I mean is that I have a breakeven SetStopLoss , then I created a Trailing stoploss off of candle highs and lows... the trailing stop loss takes over, so if I am up 100$ the initial stoploss moves to breakeven but once the candle finishes the other SetStopLoss will push the order away from break even to the high or low.. I was able to remedy this somewhat buy changing the BarsSinceEntry...

                          I would still rather have the Trailingstoploss ONLY move and take precedent if the high/low of the finished candle is above/below my breakeven StopLoss and not move opposite or away from my trade direction (or go from break-even to moving back to were I can take a loss because the high or low is above/below my entry price)

                          Hope that makes sense...

                          Comment


                            #28
                            tshirtdeal,

                            You need to work the logic for your Set() order handling. You have two instances where it is getting changed in which case both conditions can be true and change the other conditions changes
                            Cal H.NinjaTrader Customer Service

                            Comment


                              #29
                              Code:
                              // Long Trailing Stop At Lows
                              			 if (Position.MarketPosition == MarketPosition.Long && BarsSinceEntry() > 1)
                              			
                              				{
                              					SetStopLoss("", CalculationMode.Price, Low[1] -  TickSize*1, false);
                              				}
                              Yes I understand, I just cannot figure how to tell it, I know it needs to be something like && Low(1) > "something" " I know greater then the SetStopLoss that is live.. can I call out that SetStopLoss in this piece of code?

                              Thanks...

                              also, is there anyway to get those "chart trader entry and stop lines that come across the chart on a strategy? I am sure you can get lines at prices, but can you get lines with the little flags telling the amount in the order at entries and so forth?

                              Thanks for the help, sorry for being a pain, just need this right now..

                              Comment


                                #30
                                Tshirtdeal,

                                You could reverse the calculations for when to set break even and then use that as a test to see where the Low and High are in comparison to that value.

                                Essentially, you could check the number of ticks that the instrument must be positive for PnL and test that.

                                Cash Value per tick of an instrument is processed as TickSize * PointValue -

                                double cashValuePTick = TickSize * Instrument.MasterInstrument.PointValue;

                                As for the lines you would need to create your own lines to track those orders.
                                Cal H.NinjaTrader Customer Service

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by SantoshXX, Today, 03:09 AM
                                0 responses
                                11 views
                                0 likes
                                Last Post SantoshXX  
                                Started by DanielTynera, Today, 01:14 AM
                                0 responses
                                2 views
                                0 likes
                                Last Post DanielTynera  
                                Started by yertle, 04-18-2024, 08:38 AM
                                9 responses
                                41 views
                                0 likes
                                Last Post yertle
                                by yertle
                                 
                                Started by techgetgame, Yesterday, 11:42 PM
                                0 responses
                                12 views
                                0 likes
                                Last Post techgetgame  
                                Started by sephichapdson, Yesterday, 11:36 PM
                                0 responses
                                2 views
                                0 likes
                                Last Post sephichapdson  
                                Working...
                                X