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

Strategy not buying at a offset, based on previous bar.

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

    Strategy not buying at a offset, based on previous bar.

    Hers a image of my strategy: https://gyazo.com/25e3a4f91208e5f4049af668d4676327

    so its entering a short entry wen i want it to enter, at the red bar before it, 1 tick under it for a short. Like this: https://gyazo.com/ac4a1fdfca8643c26de9dd0edf872bc0

    This is my code so far:

    protected override void OnBarUpdate()
    {

    if (Open[2] < Close[2] && Open[1] < Close[1] && Open[0] > Close[0])
    {

    EnterShortLimit((Low[2])-1,"entry");

    No matter what i put to enter the short, it focuses on that bar.

    #2
    Hello papayax999,

    Are you inquiring why an order submitted after a bar has closed appears at the open of the next bar?

    When NinjaTrader is running with Calculate set to OnBarClose, orders are placed after the bar closes using logic calculated from that bar.
    Below is a link to the help guide on the Calculate property.


    This means that any orders that are triggered from that bar are submitted after the bar closes as the new bar opens. As the order is placed as the new bar opens and the timestamp of the order is within the time of the next bar, the order will show on the next bar.

    If the strategy were running with Calculate as OnPriceChange or OnEachTick, or if the script has intra-bar granularity and submitted orders on a smaller timeframe, this would cause the timestamp of the order to be within the bar it is triggered on as the order may be submitted intra-bar. This order would show on the same bar as the bar that triggered the order submission.

    This is outlined in the help guide Discrepancies: Real-Time vs Backtest.


    Also, below is a link to a forum thread about intra-bar granularity.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello papayax999,

      Are you inquiring why an order submitted after a bar has closed appears at the open of the next bar?

      When NinjaTrader is running with Calculate set to OnBarClose, orders are placed after the bar closes using logic calculated from that bar.
      Below is a link to the help guide on the Calculate property.


      This means that any orders that are triggered from that bar are submitted after the bar closes as the new bar opens. As the order is placed as the new bar opens and the timestamp of the order is within the time of the next bar, the order will show on the next bar.

      If the strategy were running with Calculate as OnPriceChange or OnEachTick, or if the script has intra-bar granularity and submitted orders on a smaller timeframe, this would cause the timestamp of the order to be within the bar it is triggered on as the order may be submitted intra-bar. This order would show on the same bar as the bar that triggered the order submission.

      This is outlined in the help guide Discrepancies: Real-Time vs Backtest.


      Also, below is a link to a forum thread about intra-bar granularity.
      http://ninjatrader.com/support/forum...297#post491297
      Is there anyway to use the most recent closed bar, to help place a buy order? my strategy is dependent on a candle stick pattern, but i want to have confirmation on the most recent bar to place it 1 tick above, if going long, or 1 tick below, if going short.

      Comment


        #4
        Hello papayax999,

        Yes, for a limit or stop price you can use the Close[1] of the previous bar. The [1] is the barsAgo value of 1 bar ago.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ChelseaB View Post
          Hello papayax999,

          Yes, for a limit or stop price you can use the Close[1] of the previous bar. The [1] is the barsAgo value of 1 bar ago.
          I got that going, but i would like to purchase it 1 tick above that closed bar, how would i do that? This is what i have currently, and its not doing it:

          protected override void OnBarUpdate()
          { // check to make sure we have enough bars on the chart to check, if not, don't process if (CurrentBar < 3)
          return;
          // if the open is greater than the close of the preceding two bars and the open is less than the close of the current bar
          if (Open[2] > Close[2] && Open[1] > Close[1] && Open[0] < Close[0])
          { //this will draw a dot above the green up bar.
          Draw.Dot(this, "Dot "+CurrentBar, true, 0, High[0] + (2*TickSize), Brushes.Goldenrod);
          //this will place a limit order 1 tick above the high of the most recent finished bar
          EnterLongLimit(High[1] + ((1 * TickSize)+.25));
          SetProfitTarget(CalculationMode.Ticks, 4); } } } }

          Comment


            #6
            Hello papayax999,

            A buy limit order must be below the current ask price. Other wise the limit order, which fills at the specified price or better, will fill at the market price which is a better price.

            Are you ensuring that High[1] + 1 * TickSize is below the GetCurrentAsk()?

            Print the value of High[1] + 1 * TickSize and print the GetCurrentAsk().


            Are you wanting to use a buy stop order above the ask and not a buy limit order below the ask?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              i dont want to purchase anything above the ask, what i would like to do go long , in that current example, 1 tick above the last formed candle. For example, if the 1 minute candle is complete, and it has a DOT, and it has a high of $100 dollars, go place a longer order at $100.25.

              Comment


                #8
                Hello papayax999,

                If you are adding 1 tick to the high of the previous bar, then you need to be sure that this price is less than the current ask. Are you checking this?

                You can place an order at that price, if the price is below the current ask. Have you printed this to know?
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_ChelseaB View Post
                  Hello papayax999,

                  If you are adding 1 tick to the high of the previous bar, then you need to be sure that this price is less than the current ask. Are you checking this?

                  You can place an order at that price, if the price is below the current ask. Have you printed this to know?
                  oh i see what your saying. What is another way to add a entry, to purchase at that price no matter the ask? Is it a stopmarket?
                  thanks,

                  Comment


                    #10
                    Hello papayax999,

                    You would need the proper order for the side of the market.

                    If this is a buy order a limit must be below the ask, a stop must have the stop price above the ask,. (Or the order will be rejected or fill at an unexpected price)
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_ChelseaB View Post
                      Hello papayax999,

                      You would need the proper order for the side of the market.

                      If this is a buy order a limit must be below the ask, a stop must have the stop price above the ask,. (Or the order will be rejected or fill at an unexpected price)
                      yes i see that, but for example, this is wat i would liek to have: https://gyazo.com/5f4b6b9067df10b7eb7edc32f7971346

                      Imagine the green candle is complete, and i want to only enter the trade, if the next candle touches that.

                      Comment


                        #12
                        Hello papayax999,

                        The screenshot appears to be showing a stop market order above the ask price.

                        You can choose when orders are submitted or cancelled. You can choose the order price and order type.
                        The price for an order must be valid for the order price.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_ChelseaB View Post
                          Hello papayax999,

                          The screenshot appears to be showing a stop market order above the ask price.

                          You can choose when orders are submitted or cancelled. You can choose the order price and order type.
                          The price for an order must be valid for the order price.
                          Is there a way to bring a ATM strategy you already have set, and put it into ninjascript editor?

                          Comment


                            #14
                            Hello papayax999,

                            There are Atm Strategy methods available for advanced programmers.

                            Included with NinjaTrader is the SampleAtmStrategy that has sample code.

                            Below is a link to the help guide.
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Originally posted by NinjaTrader_ChelseaB View Post
                              Hello papayax999,

                              There are Atm Strategy methods available for advanced programmers.

                              Included with NinjaTrader is the SampleAtmStrategy that has sample code.

                              Below is a link to the help guide.
                              https://ninjatrader.com/support/help...gy_methods.htm

                              thank you, ill take a look. i got my entry in and it works perfectly, but the stoploss has been tough to implement, would i be able to implement this?: i want a stop loss 1 tick below my entry candle, wich would be my Low[0], but it wont work wen i do that. then i want my profit target to be 4 ticks.

                              EnterLongStopLimit(High[0] +.25,High[1],"Entry");
                              SetStopLoss(CalculationMode.Ticks,-4);
                              SetProfitTarget(CalculationMode.Ticks, 4);

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Waxavi, Today, 02:10 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post Waxavi
                              by Waxavi
                               
                              Started by TradeForge, Today, 02:09 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post TradeForge  
                              Started by Waxavi, Today, 02:00 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post Waxavi
                              by Waxavi
                               
                              Started by elirion, Today, 01:36 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post elirion
                              by elirion
                               
                              Started by gentlebenthebear, Today, 01:30 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post gentlebenthebear  
                              Working...
                              X