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

EnterLongStop() not actually creating order?

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

    EnterLongStop() not actually creating order?

    Completely stumped here. Very simple program so far.

    When I start the strategy on a chart, both print statements from OnBarUpdate execute, but it never gets to OnExecution(). I'm not sure if the order isn't actually being submitted or what. The price does indeed go through the level a few bars later. Am I using ENTERLONGSTOP() incorrectly here? This seems very simple, I must be doing something wrong.

    protectedoverridevoid OnBarUpdate()
    {
    // Check if we have no position (at start of strategy on first bar calc), and create both buy and sell orders if true
    if (Position.MarketPosition == MarketPosition.Flat && initialPxFlag == false)
    {
    initialPx = Close[
    0];
    initialPxFlag =
    true;

    Print(Time[
    0] + " start, initialPx = " + initialPx);

    // Set initial buy order
    tradeEntryPx = initialPx + NumTrailingTicks*myTickSize;
    EnterLongStop(DefaultQuantity, tradeEntryPx,
    "myTrade");

    Print(Time[
    0] + " start, tradeEntryPx = " + tradeEntryPx);

    }
    // end if
    } // end OnBarUpdate()

    protectedoverridevoid OnExecution(IExecution execution)
    {
    tradedPx = execution.Order.AvgFillPrice;
    localMin = tradedPx;
    localMax = tradedPx;


    Print(Time[
    0] + " in OnExecution, tradedPx = " + tradedPx);

    }
    // end OnExecution

    #2
    Hello,

    Thank you for the question.

    The order may be getting ignored based on the value it is being set at, if you have the Tools -> Output window open you would see this.

    Because you have variables listed in the code provided I was unable to compile the example. Instead I compiled a simple example of OnExecution that prints, please take a look at this example and then double check the value you are setting the stop order at.

    Code:
    protected override void OnBarUpdate()
    {
    	if (Position.MarketPosition == MarketPosition.Flat )
    	{
    		EnterLongStop(DefaultQuantity, Close[0] + 1 * TickSize, "myTrade");
    	} 
    } 
    
    protected override void OnExecution(IExecution execution)
    {
    	Print(Time[0] + " in OnExecution, tradedPx = " + execution.ToString());
    }
    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Well in OnBarUpdate I am printing out tradeEntryPx right after calling
      EnterLongStop(DefaultQuantity, tradeEntryPx, "myTrade")

      I have the output window open. The only output is
      3/2/2015 3:30:00 AM start, initialPx = 0.7272
      3/2/2015 3:30:00 AM start, tradeEntryPx = 0.7282

      Which is exacly what I expect to see. There is nothing after that, no trade error no ignoring trade message, no nothing. I'm confused. It doesn't execute and therefore that last print statement in OnExecution never prints.

      Comment


        #4
        Hello,

        If you can provide an example of this with the variables and values for the variables I could test this on my end to see what may be the cause.

        Also please include the instrument and chart type you are using this with.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          How do I send you the whole file, it's not messy or large

          Comment


            #6
            Hello,

            Click Attach from the forum post.
            Navigate to: Documents\NinjaTrader 7\bin\Custom\Strategy
            and select the file.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Pick any currency pair 30min chart and give it a run.
              Attached Files

              Comment


                #8
                Hello,

                Thank you for the file.

                I am not sure why you are not getting the error output, you may actually need to remove the strategy from the chart and apply the changes and then add it back.

                I am seeing the error of:

                Code:
                **NT** Error on calling 'OnExecution' method for strategy 'TrailingEntriesDemo': Object reference not set to an instance of an object.
                This is the first line of your OnExecution, there is not always going to be an order, only if the order is filled will the code you have work so you need to do as the help guide example is doing and add the following line to the top of OnExectuion:

                Code:
                if (execution.Order == null || execution.Order.OrderState != OrderState.Filled) return;
                This will prevent the error and it seems the strategy places orders after doing so.

                Please add this and then remove and re add the strategy from your chart.

                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Jesse, I added it and I'm getting the same problem. I don't see that error in the Output window. I'm running exactly what I sent you plus that line as the first line in OnExecution() on different currency pairs with 30min bars. Every time I get the output of the initial price and tradeEntryPx in the Output window, and then nothing after that.

                  You are getting orders? This is crazy. I also restarted my NT just for the heck of it.

                  Comment


                    #10
                    Hello,

                    Yes I am, I did have to increase my DaysToLoad I am currently at 30.

                    Here is an image of what output I have received and the script is attached as well with the change I added.

                    Please try using this script, it should be identical to what you have. Also try 30 days or greater and see if you get results. If not please let me know.


                    I look forward to being of further assistance.
                    Attached Files
                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      Same issue. Ok. I'm running NT 7.0.1000.22

                      I haven't had any issues with the other scripts I've written, they still work as expected. Could using a different version matter?

                      Comment


                        #12
                        Hello,

                        That is strange, I don't believe there is anything code breaking between .22 and the current release of .27 but you may try updating the platform because this is what I tested it with.

                        To upgrade please exit the platform and visit http://www.ninjatrader.com/download-registration.php
                        Enter your email and proceed to the download page.
                        Download the current release and install it.
                        After downloading please open the platform and do an instrument reset, this is needed because you are on a pretty old version.
                        Disconnect if you are connected.
                        Go to Tools -> Options -> Data -> Reset Instruments.
                        Restart the platform when prompted.

                        if this does not resolve what is happening please email me at platform support @ ninjatrader.com and reference ticket 1271196 and we will schedule a remote assistance call.

                        I look forward to being of further assistance.
                        JesseNinjaTrader Customer Service

                        Comment


                          #13
                          Unfortunately, this did not work. I really appreciate all the effort though. I'll be sending that email now.

                          Comment


                            #14
                            Originally posted by Locke View Post
                            Completely stumped here. Very simple program so far.

                            When I start the strategy on a chart, both print statements from OnBarUpdate execute, but it never gets to OnExecution(). I'm not sure if the order isn't actually being submitted or what. The price does indeed go through the level a few bars later. Am I using ENTERLONGSTOP() incorrectly here? This seems very simple, I must be doing something wrong.

                            protectedoverridevoid OnBarUpdate()
                            {
                            // Check if we have no position (at start of strategy on first bar calc), and create both buy and sell orders if true
                            if (Position.MarketPosition == MarketPosition.Flat && initialPxFlag == false)
                            {
                            initialPx = Close[
                            0];
                            initialPxFlag =
                            true;

                            Print(Time[
                            0] + " start, initialPx = " + initialPx);

                            // Set initial buy order
                            tradeEntryPx = initialPx + NumTrailingTicks*myTickSize;
                            EnterLongStop(DefaultQuantity, tradeEntryPx,
                            "myTrade");

                            Print(Time[
                            0] + " start, tradeEntryPx = " + tradeEntryPx);

                            }
                            // end if
                            } // end OnBarUpdate()

                            protectedoverridevoid OnExecution(IExecution execution)
                            {
                            tradedPx = execution.Order.AvgFillPrice;
                            localMin = tradedPx;
                            localMax = tradedPx;


                            Print(Time[
                            0] + " in OnExecution, tradedPx = " + tradedPx);

                            }
                            // end OnExecution
                            Your trade did not trigger on the bar that you set it, and was canceled when the next bar opened (that is the default action). You never reset your entry condition, so that block will be entered only once. Therefore, your code gives you exactly only one, and only one shot at entry for your entire chart. Correct your logic. (You have set initialPxFlag to true inside the entry block).

                            If you use the liveUntilCanceled override on orders, you will possibly be guaranteed an entry, but your current logic would still ensure that you have exactly one trade opportunity on the entire chart.

                            ref: http://www.ninjatrader.com/support/h...erlongstop.htm

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Barry Milan, Yesterday, 10:35 PM
                            5 responses
                            16 views
                            0 likes
                            Last Post NinjaTrader_Manfred  
                            Started by DanielSanMartin, Yesterday, 02:37 PM
                            2 responses
                            13 views
                            0 likes
                            Last Post DanielSanMartin  
                            Started by DJ888, 04-16-2024, 06:09 PM
                            4 responses
                            13 views
                            0 likes
                            Last Post DJ888
                            by DJ888
                             
                            Started by terofs, Today, 04:18 PM
                            0 responses
                            12 views
                            0 likes
                            Last Post terofs
                            by terofs
                             
                            Started by nandhumca, Today, 03:41 PM
                            0 responses
                            8 views
                            0 likes
                            Last Post nandhumca  
                            Working...
                            X