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

market order and limit order

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

    market order and limit order

    Dear NT8 support team,

    I have a simple strategy to perform reversal trading based on opposite signal. I have included a signalname for my entry orders and trying to exit the particula orders based on the signal name. My default entries per direction is 1. I did backtesting with market order and functionality worked perfectly. When i try to test it in paper account with live market data, it is not working as expected. Strategy is missing the signals and not taking trades, only one trade is executed per day and that trade is closed at the end of session. Could you please check the code snippet and suggest?

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    // Condition set 1
    if (RMheikinashi(Length).BullIndication[0] == true && Position.MarketPosition != MarketPosition.Flat)
    {
    if(Position.MarketPosition != MarketPosition.Long)
    {
    //EnterLong();
    EnterLongLimit(DefaultQuantity, lastP, "longEntryHA1");
    Print(" HA is Buy - Enter Long" );
    }
    }

    // Condition set 2
    if (RMheikinashi(Length).BearIndication[0] == true && Position.MarketPosition != MarketPosition.Flat)
    {
    if(Position.MarketPosition != MarketPosition.Short)
    {
    //EnterShort();
    EnterShortLimit(DefaultQuantity, lastP, "shortEntryHA1");
    Print(" HA is Sell - Enter Short" );
    }
    }
    //Reversal signals
    // Condition set 3
    if (RMheikinashi(Length).BearIndication[0] == true && Position.MarketPosition != MarketPosition.Flat)
    {
    if(Position.MarketPosition == MarketPosition.Long)
    {
    //ExitLong();
    ExitLongLimit(lastP, "", "longEntryHA1");
    Print(" HA is Sell - Exit Long" );
    }
    }

    // Condition set 4
    if (RMheikinashi(Length).BullIndication[0] == true && Position.MarketPosition != MarketPosition.Flat)
    {
    if(Position.MarketPosition == MarketPosition.Short)
    {
    //ExitShort();
    ExitShortLimit(lastP, "", "shortEntryHA1");
    Print(" HA is Buy - Exit Short" );
    }
    }

    }

    #2
    Hello radhmu978,

    Print the time of the bar and all values used in the conditions (outside of any conditions so the prints appear for each bar). Include labels with each value in the print to identify what the value is and how it is being compared.
    Also enable TraceOrders.
    Save the output to a text file and include this with your next post.

    Below is a link to a forum post that demonstrates using Print() to understand behavior.


    I am happy to assist with analyzing the output.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Looks like strategy is not able to ready the signals I'm sending from indicator. It was working as expected in backtest. But when I'm testing with the market data, stategy is not able to read the buy and sell signals from indicators. I have no plots, disabled the plaots in indicators. I created Buy/Sell alerts from indicators, like explained in the SampleBoolSeries NT8 example.

      //buy signal
      if (trend[0] == 1 && trend[1] == -1)
      {


      Draw.ArrowUp(this, "mytag1"+CurrentBar, true, 0, Low[0] - (10 * 1), Brushes.Green);
      Draw.Text(this, "txttag"+CurrentBar, " ST-BY ", 0, Low[0] - (10 *4));

      buySignal[0] = (true);
      sellSignal[0] = (false);
      Print(Time[0].ToString());
      Print("Long condition = " + buySignal[0]);

      }

      //sellSignal = trend == -1 and trend[1] == 1

      if (trend[0] == -1 && trend[1] == 1)
      {

      Draw.ArrowDown(this, "mytag1"+CurrentBar, true, 0, High[0] + (10 * 1), Brushes.OrangeRed);
      Draw.Text(this, "txttag"+CurrentBar, " ST-SL ", 0, High[0] + (10 * 4));

      sellSignal[0] = (true);
      buySignal[0] = (false);
      Print(Time[0].ToString());
      Print("short condition = " + sellSignal[0]);
      }

      Comment


        #4
        Hello radhmu978,

        The condition appears to be if (trend[0] == 1 && trend[1] == -1)

        A print for this would appear as:
        Code:
        Print(string.Format("{0} | trend[0]: {1} == 1 && trend[1]: {2} == -1", Time[0], trend[0], trend[1]));
        If the issue is from an indicator, the debugging process would need to be done in that indicator.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi Chelsea ,

          I added plots to my indicator, also able to build a custom strategy using the strategy builder. Still not able to place limit orders, signals from indicators are received by strategy.. Please check the traces and strategy code attached.

          Thanks,
          Murali

          Attached Files

          Comment


            #6
            Hello Murali,

            I am not able to debug the script on your behalf. And I am not able to understand this output as it does not show what is being compared in the conditions with labels.

            Have a look at the output in the post on using prints to understand behavior.

            The code above does not appear to be in this script at all.

            If this is the script in question, add a print for all of the values used in the condition in this script to understand why it is true or false.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hi Chelsea ,

              Please ignore, after adding plots, I'm able to get the signals. Also, minimum bar needed to trade was set to 20, so it took sometime to get 20 Bars, after that the orders got placed.

              I have one other question, My strategy is designed to work "On Bar Close", so I get the signal BUY/SELL, I enter the order in next bar which is in progress. I want my order to get filled at the open price of the recent bar which is in progress, How to get the open price of the bar in-progress? I'n backtesting, strategy builder always assume that the entry is at opening of the new candle, but in real world scenario, that is not the case. Coudl you please give me some examples here?

              Thankyou,
              Murali

              Comment


                #8
                Hi Chelsea,

                I see one more issue, my exit signal names are missing. I want the strategy to exit a particular position based on the reversal signal, but in this case NT8 is doing automatic reversals based on EnterLongLimit and EnterShortLimit. Only the entry signals are taken, exit signals are not taken. If i have multiple entry orders with different signal names, I should be able to exit one particular order using the exitShort right?

                EnterLongLimit(Convert.ToInt32(DefaultQuantity), lastP, "LongST1");
                EnterLongLimit(Convert.ToInt32(DefaultQuantity), lastP, "LongST2");

                ExitShortLimit(Convert.ToInt32(DefaultQuantity), lastP, "ExitShortST1", @"LongST1");
                Attached Files

                Comment


                  #9
                  Please check the post #7 and #8, script issue resolved. But I need clarification on the open questions.

                  Comment


                    #10
                    Hello radhmu978,

                    Is there an exit order for the log position or only for the short position?

                    Do you have multiple exit orders?

                    The ExitShortLimit would not be able to exit a long position. For this you would need ExitLongLimit() and this would need a limit price above the current bid.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      ignore the script and help me with the questions posted in post #7

                      My strategy is designed to work "On Bar Close", so I get the signal BUY/SELL, I enter the order in next bar which is in progress. I want my order to get filled at the open price of the recent bar which is in progress, How to get the open price of the bar in-progress? I'n backtesting, strategy builder always assume that the entry is at opening of the new candle, but in real world scenario, that is not the case. Coudl you please give me some examples here?




                      Comment


                        #12
                        Hello Murali,

                        Orders can be submitted intra-bar with 1-tick intra-bar granularity and TickReplay.

                        Below is a link to a forum post with details.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Hi Chelsea,

                          ok, I will check this and revert back.

                          ##

                          Is there an example for OCO order? I want to set a high offset stoploss and move the stoploss to a price limit based on my exit strategy. Currently enterLong and enterShort orders are doing reversal trading and totally out of sync if i close any one of the orders in between to take profit. Please review the example listed below.

                          ##example##

                          i have 2 entry orders

                          EnterLongLimit(Convert.ToInt32(1),CloseP, "LongHA1");
                          EnterLongLimit(Convert.ToInt32(1),CloseP, "LongHA2");


                          I'm closing 1 position based on my short timeframe exit signal

                          ExitLongLimit(Convert.ToInt32(1), CloseP, "ExitLongHA1", "LongHA1");

                          For the second position, I close it based on my default timeframe exit signal

                          ExitLongLimit(Convert.ToInt32(1), CloseHAP, "ExitLongHA1", "LongHA2");

                          but my exitLongLimit is not getting executed, instead EnterShortLimit is closing LongHA2 position and opening only one position on short side - "ShortHA1"

                          EnterShortLimit(Convert.ToInt32(1), CloseHAP, "ShortHA1");
                          EnterShortLimit(Convert.ToInt32(1), CloseHAP, "ShortHA2");


                          I have set my entries per direction as 2 in settings, I'm calling EnterShortLimit / EnterLongLimit twice with different signal names, but still the entry order is not taken. Because of this issue, entire strategy is going async. If i try to take profit and close one position in between, based on my smaller timeframe signal, then by regular scalping is getting impacted. Is it a known platform issue or this is how the NT8 is designed to work?

                          Thanks,
                          Murali

                          Comment


                            #14
                            Hello Murali,

                            OCO would need to be used with the unmanaged approach. Below is a link to an example specifically of OCO.


                            The ProfitChaseStopTrailUnmanagedExample_NT8 linked below also demonstrates an OCO set of orders used for the stop loss and profit target.


                            When using the managed approach and there is a long position open and the ExitLongLimit is working , I would not expect that the EnterShortLimit could be submitted as this would violate the internal order handling rules.

                            From the help guide;
                            "Methods that generate orders to enter a position will be ignored if:
                            A position is open and an order submitted by a non market order exit method (ExitLongLimit() for example) is active and the order is used to open a position in the opposite direction"

                            I think you have too many orders.
                            The managed approach managed the position. Meaning calling an entry in the opposite direction of the position will trigger NinjaTrader to submit a 'Close position' order to close the position, then enter the opposite position with the method order.
                            See this post about overfills:


                            ​​​​​​​It might be beneficial to use the unmanaged approach if you are planning these kind of orders at the same time.
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Hi Chelsea,

                              I keep getting this error " An Enter() method to submit an entry order at '1/18/2022 2:00:00 PM' has been ignored. Please search on the term 'Internal Order Handling Rules' in the Help Guide for detailed explanation."

                              I have 2 long positions open

                              EnterLongLimit(Convert.ToInt32(1),CloseP, "LongHA1");
                              EnterLongLimit(Convert.ToInt32(1),CloseP, "LongHA2");

                              Based on reversal signal, I'm trying to exit the position

                              ExitLongLimit(Convert.ToInt32(1), CloseHAP, "ExitLongHA1", "LongHA1");
                              ExitLongLimit(Convert.ToInt32(1), CloseHAP, "ExitLongHA2", "LongHA2");

                              ### after 10 seconds delay## implemented using the example => https://ninjatrader.com/support/foru...lay-for-orders

                              wait for 10 seconds to allow the Exit orders to get filled and then I'm sending Entry orders in opposite direction

                              EnterShortLimit(Convert.ToInt32(1), CloseSTP,"EntryShortHA1");
                              EnterShortLimit(Convert.ToInt32(1), CloseSTP,"EntryShortHA2");

                              But sometime my 10 sec time works good, but sometimes it fails with error An Enter() method to submit an entry order at '1/18/2022 2:00:00 PM' has been ignored. Please search on the term 'Internal Order Handling Rules' in the Help Guide for detailed explanation."

                              ## is there an option to check for order status, any callback methods available to execute my order based on order fill status? Based on the market volatality and volume, I understand that my limit order may take some time to get filled, but, if there is a mechanism to get the order fill status, based on that I can release my order in other direction. My strategy uses 15min chart on NQ and based on my experience, most of the cases, my limit orders are getting filled.

                              Thanks,
                              Murali


                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by kaywai, 09-01-2023, 08:44 PM
                              5 responses
                              601 views
                              0 likes
                              Last Post NinjaTrader_Jason  
                              Started by xiinteractive, 04-09-2024, 08:08 AM
                              6 responses
                              22 views
                              0 likes
                              Last Post xiinteractive  
                              Started by Pattontje, Yesterday, 02:10 PM
                              2 responses
                              18 views
                              0 likes
                              Last Post Pattontje  
                              Started by flybuzz, 04-21-2024, 04:07 PM
                              17 responses
                              230 views
                              0 likes
                              Last Post TradingLoss  
                              Started by agclub, 04-21-2024, 08:57 PM
                              3 responses
                              17 views
                              0 likes
                              Last Post TradingLoss  
                              Working...
                              X