Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Coding in Displacement for Bollinger Visual Plot?

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

    #16
    Hey Chelsea,

    Thanks for the reply, hope you had a great holiday weekend and everything is well.

    I took your advice and implemented your provided code. Comparing the current strategy results to a set of signals that I've verified from live trading, the signals do not match up. It seems like what's still happening is that the signal happens one bar too late (forward).

    I'm not sure if this has to do with displacement or this topic, but I noticed at the current bar (in strategy analyzer chart), there is no value for a non displaced MA. Instead, the value ends at the bar previous to it, and for a displaced Bollinger of -2, two bars previous to that. Could this be why some of the signals above are not lining up? It seems like all the signals I'm given in Strategy Analyzer are moved one bar forward.

    Thanks again and I look forward to your response.

    Comment


      #17
      Hello ComfyCouch,

      With the inquiry of orders being on the next bar, this happens if the order is submitted after the bar is closed. Meaning Calculate is OnBarClose, or this is historical data without intra-bar granularity and tick replay.
      https://ninjatrader.com/support/foru...992#post782992
      https://ninjatrader.com/support/foru...377#post773377

      Displacement is a visual thing only. It doesn't change the bar values, it just changes how forward or backward that plot value appears visually on the chart. You have access to the same plot values. You can use them whenever you want. If you want to wait a few bars after the plot value appears you can. If you want to use values from previous bars, you can.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #18
        Hi Chelsea,

        Thank you for the reply, and I hope you had a great start to the year.

        I think you've addressed pretty much all of what I've had trouble with in this thread, and I thank you for that. I do have one other question/problem, that I'd like to ask help with.

        I wanted to test my strategies results with different entries. To do that, I decided to default back to Calculate.OnBarClose and try to implement a limit order (both Long and Short) at the price of the open of the previous candle (the candle that is right before the default entry candle) by using the syntax of EnterLongLimit/EnterShortLimit. However, when compiling, I'm getting what looks to be like random entries rather than what I want. I used the following to enter a limit position (and EnterLongLimit for a long):

        protected override void OnBarUpdate()
        {

        if (CurrentBars[0] < 4)
        return;

        double entryprice = Open[1];

        // Set 1
        if (condition here)
        {
        ExitShort(Convert.ToInt32(DefaultQuantity), @"ES", "");
        EnterLongLimit(Convert.ToInt32(DefaultQuantity), entryprice, "EL");
        }

        // Set 2
        if (condition here)
        {
        ExitLong(Convert.ToInt32(DefaultQuantity), @"EL", "");
        EnterShortLimit(Convert.ToInt32(DefaultQuantity), entryprice, "ES");
        }

        }

        where entryprice is defined as Open[1] to represent the "previous candle" of the default entry candle (that NinjaTrader uses). What am I doing wrong here? Am I just completely off in my code? Furthermore, to follow up on this, I understand that all limit orders are likely not to be filled so in order to account for this, if my limit order is not filled, is it possible to make it so that it cancels that Limit order after 2 bars pass/till one of the conditions become true or is this done automatically?

        Thanks for your time and I look forward to your response.

        Comment


          #19
          Hello ComfyCouch, thanks for your reply.

          If the limit orders are not re-submitted by the strategy on every bar they will be canceled. To keep the order alive without needing to resubmit them on every bar they should be kept alive, use the special overload that takes a IsLiveUntilCanceled parameter e.g.

          https://ninjatrader.com/support/help...rlonglimit.htm
          EnterLongLimit(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double limitPrice, string signalName) //set IsLiveUntilCanceled to true to keep the order alive until canceled.

          To check if the order has been alive for over 2 bars, save the CurrentBar value at the time of order submission to an int property in the Indicator class, then check for if(CurrentBar == StoredValue+2)

          The entries are not random, use Print statements within the strategy to see why conditions are becoming true. This will be highly dependent on the conditions within the IF condition e.g.

          Code:
          // Set 1
          if (condition here)
          {
              Print("Long Limit Condition True, Submitting order " + Time[0]);
              ExitShort(Convert.ToInt32(DefaultQuantity), @"ES", "");
              EnterLongLimit(Convert.ToInt32(DefaultQuantity), entryprice, "EL");
          }
          
          // Set 2
          Print("Checking Short Limit Condition " + Time[0]);
          if (condition here)
          {
              Print("Short Limit Condition True, Submitting order " + Time[0]);
              ExitLong(Convert.ToInt32(DefaultQuantity), @"EL", "");
              EnterShortLimit(Convert.ToInt32(DefaultQuantity), entryprice, "ES");
          }
          Please let us know if we can assist any further.
          Chris L.NinjaTrader Customer Service

          Comment


            #20
            Hey ChrisL, thanks for replying back.

            I mentioned that early on that I'm not all experienced with C# and that's currently showing now: confused. I apologize.

            I think if I just plainly say what I'm trying to accomplish, it might be better for both of us.

            If my condition becomes true, I'd like to enter at the price of the previous candle's open. If the current candle does not reach the open price by the end of its close, then I'd like to cancel the order and wait for when the condition becomes true again. I'm not sure if the code that I gave two posts ago is correct in that it represents what I just said in this statement; please let me know whether or not it does and how I could correct this.

            Thank you for help thus far - the print function seemed to solve part of the entry problems (I think since I'm using ">" / "<" in my if conditions, it keeps the limit order active in each bar so long the condition stays true - - will changing to "crossAbove" and 'crossBelow" solve this?)

            Comment


              #21
              Hello ComfyCouch,

              If you are using the managed approach, you choose not to submit an order on a new bar and this will automatically be cancelled. Alternatively, you can supply the order object to CancelOrder().
              https://ninjatrader.com/support/help...ancelorder.htm

              Please note, C# programming education comes prerequisite to writing NinjaScript code. The Strategy Builder can be used to see how it generates C# syntax, but please be aware that it is not with our Scripting Support team's scope to provide programming education services or to check your syntax. We highly recommend getting further acquainted with C# through a formal class, or through educational resources that can be found external to NinjaTrader.


              The Print() is intended to give you, the developer, more information so that you understand why the behavior of the script is behaving as it is, so that you can take steps to redesign the code. Using a print is like listening to a car engine to diagnose an issue. Listening to a car engine does not fix the issue, but instead lets you further understand what the issue is.

              Below is a link to a forum post that demonstrates using prints to understand behavior.
              https://ninjatrader.com/support/foru...121#post791121
              Chelsea B.NinjaTrader Customer Service

              Comment


                #22
                Hi ChelseaB,

                I understand that a must prerequisite for NinjaScript is having the basic knowledge of C# and while having a very new entry level type experience to C#, I apologize if my previous post looked like a request for a handout. I'm grateful for the resources that NinjaTrader and it's wonderful support staff provide and have been using them every chance I get.

                I looked into ChrisL's post about isLiveUntilCancelled and saw the supplement of CancelOrder, and tried to to implement into my strategy to see if manually canceling the order changes anything in regards to my entries. After compiling, it seems that only one trade is made in the timespan of the backtest: where it enters at long condition and exits at exit condition (conditions are below). Afterwards, there are no further trades made, even though from sight, it is obvious other trades are possible. I figured at OnOrderUpdate, where myEntryOrder is set back to null, the strategy would "reset" and look for the next possible trade of when the long condition holds true, but however, it does not happen.

                With TraceOrder true, I decided to look at the debug and saw the following:

                With the first few minutes after BarsRequiredToTrade is met, when long condition is true, it rightfully takes a position at a limit price and then sells when exit condition is true, as shown by the gap between 6:22 and 6:38. This is also shown on the Chart, in Strategy Analyzer, with a long signal and exit signal. However, shown in the subsequent lines, long condition is met and a position should be taken and it looks like it kind of is (there's a gap shown in the time), but is not actually taken as shown by two things: no actual limit price listed and no buy signal shown in the chart of Strategy Analyzer. As a whole, in the span of two days (the time span of the quick backtest), it shows that only one trade (which is the first trade between 6:22 and 6:38) is taken in its whole duration.
                Is there something missing from when I added CancelOrder?

                Thanks for your time and help.

                12/7/2020 6:05:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:05:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='BarsRequiredToTrade has not been met'

                12/7/2020 6:06:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:06:00 PM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=3682.75 StopPrice=0 SignalName='Long' FromEntrySignal='' Reason='BarsRequiredToTrade has not been met'

                12/7/2020 6:07:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:07:00 PM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=3683.00 StopPrice=0 SignalName='Long' FromEntrySignal='' Reason='BarsRequiredToTrade has not been met'

                12/7/2020 6:08:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:08:00 PM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=3683.25 StopPrice=0 SignalName='Long' FromEntrySignal='' Reason='BarsRequiredToTrade has not been met'

                12/7/2020 6:10:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:10:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='BarsRequiredToTrade has not been met'

                12/7/2020 6:11:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:11:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='BarsRequiredToTrade has not been met'

                12/7/2020 6:12:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:12:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='BarsRequiredToTrade has not been met'

                12/7/2020 6:13:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:13:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='BarsRequiredToTrade has not been met'

                12/7/2020 6:14:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:14:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='BarsRequiredToTrade has not been met'

                12/7/2020 6:15:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:15:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='BarsRequiredToTrade has not been met'

                12/7/2020 6:16:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:16:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='BarsRequiredToTrade has not been met'

                12/7/2020 6:17:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:17:00 PM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=3682.50 StopPrice=0 SignalName='Long' FromEntrySignal='' Reason='BarsRequiredToTrade has not been met'

                12/7/2020 6:18:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:18:00 PM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=3682.50 StopPrice=0 SignalName='Long' FromEntrySignal='' Reason='BarsRequiredToTrade has not been met'

                12/7/2020 6:19:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:19:00 PM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=3683.00 StopPrice=0 SignalName='Long' FromEntrySignal='' Reason='BarsRequiredToTrade has not been met'

                12/7/2020 6:20:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:20:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='BarsRequiredToTrade has not been met'

                12/7/2020 6:21:00 PM Strategy '-': Entered internal SubmitOrderManaged() method at 12/7/2020 6:21:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal=''

                12/7/2020 6:21:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:21:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'

                12/7/2020 6:22:00 PM Strategy '-': Entered internal SubmitOrderManaged() method at 12/7/2020 6:22:00 PM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=3682.75 StopPrice=0 SignalName='Long' FromEntrySignal=''

                12/7/2020 6:38:00 PM Strategy '-': Entered internal SubmitOrderManaged() method at 12/7/2020 6:38:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal=''

                12/7/2020 6:39:00 PM Strategy '-': Entered internal SubmitOrderManaged() method at 12/7/2020 6:39:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal=''

                12/7/2020 6:39:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:39:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'

                12/7/2020 6:40:00 PM Strategy '-': Entered internal SubmitOrderManaged() method at 12/7/2020 6:40:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal=''

                12/7/2020 6:40:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:40:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'

                12/7/2020 6:41:00 PM Strategy '-': Entered internal SubmitOrderManaged() method at 12/7/2020 6:41:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal=''

                12/7/2020 6:41:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:41:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'

                12/7/2020 6:42:00 PM Strategy '-': Entered internal SubmitOrderManaged() method at 12/7/2020 6:42:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal=''

                12/7/2020 6:42:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:42:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'

                12/7/2020 6:49:00 PM Strategy '-': Entered internal SubmitOrderManaged() method at 12/7/2020 6:49:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal=''

                12/7/2020 6:49:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:49:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'

                12/7/2020 6:50:00 PM Strategy '-': Entered internal SubmitOrderManaged() method at 12/7/2020 6:50:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal=''
                12/7/2020 6:50:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:50:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'

                12/7/2020 6:51:00 PM Strategy '-': Entered internal SubmitOrderManaged() method at 12/7/2020 6:51:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal=''

                12/7/2020 6:51:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:51:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'

                12/7/2020 6:52:00 PM Strategy '-': Entered internal SubmitOrderManaged() method at 12/7/2020 6:52:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal=''

                12/7/2020 6:52:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:52:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'

                12/7/2020 6:53:00 PM Strategy '-': Entered internal SubmitOrderManaged() method at 12/7/2020 6:53:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal=''

                12/7/2020 6:53:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:53:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'

                12/7/2020 6:54:00 PM Strategy '-': Entered internal SubmitOrderManaged() method at 12/7/2020 6:54:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal=''

                12/7/2020 6:54:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:54:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'

                12/7/2020 6:55:00 PM Strategy '-': Entered internal SubmitOrderManaged() method at 12/7/2020 6:55:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal=''

                12/7/2020 6:55:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:55:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'

                12/7/2020 6:56:00 PM Strategy '-': Entered internal SubmitOrderManaged() method at 12/7/2020 6:56:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal=''

                12/7/2020 6:56:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:56:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'

                12/7/2020 6:57:00 PM Strategy '-': Entered internal SubmitOrderManaged() method at 12/7/2020 6:57:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal=''

                12/7/2020 6:57:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:57:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'

                12/7/2020 7:01:00 PM Strategy '-': Entered internal SubmitOrderManaged() method at 12/7/2020 7:01:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal=''

                {
                private Order myEntryOrder = null;
                private int barNumberOfOrder = 0;

                protected override void OnStateChange()
                {
                if (State == State.SetDefaults)
                {
                Description = @"-";
                Name = "-";
                Calculate = Calculate.OnBarClose;
                EntriesPerDirection = 1;
                EntryHandling = EntryHandling.AllEntries;
                IsExitOnSessionCloseStrategy = true;
                ExitOnSessionCloseSeconds = 30;
                IsFillLimitOnTouch = true;
                MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
                OrderFillResolution = OrderFillResolution.Standard;
                Slippage = 0;
                StartBehavior = StartBehavior.WaitUntilFlat;
                TimeInForce = TimeInForce.Gtc;
                TraceOrders = true;
                RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
                StopTargetHandling = StopTargetHandling.PerEntryExecution;
                BarsRequiredToTrade = 20;
                IsInstantiatedOnEachOptimizationIteration = true;

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

                if (CurrentBars[0] < 4)
                return;

                if (myEntryOrder == null && CrossAbove(long condition, 3))
                {
                EnterLongLimit(0, true, 1, Open[1], "Long");
                barNumberOfOrder = CurrentBar;

                }
                if (CurrentBar > barNumberOfOrder + 1)
                CancelOrder(myEntryOrder);


                if (*exit condition*)
                {
                ExitLong(Convert.ToInt32(DefaultQuantity), @"EL", "");
                }

                }
                protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
                {
                if (order.Name == "Long")
                myEntryOrder = order;
                if (myEntryOrder != null && myEntryOrder == order)
                {
                if (myEntryOrder.OrderState == OrderState.Cancelled)
                {
                myEntryOrder = null;
                }
                }
                }
                }
                }

                Comment


                  #23
                  Hello,

                  I'm trying to pick out the issue you are having. I'm reading "no actual limit price listed and no buy signal shown in the chart of Strategy Analyzer". Are you asking why an order that was submitted did not fill?

                  Are you asking why an order was not submitted?

                  Are you asking why an order was filled when you have attempted to cancel the order?

                  Are you asking why an order was automatically cancelled?
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #24
                    Hey Chelsea,

                    Thanks for the reply. The exact issue I have is that the strategy only took one trade and did not take anymore trades after. I'm asking as to why is this happening. The debugging log seems to show that it knows it should be taking a trade when respective conditions are true/false, but as shown in the log, a limit price is not shown (therefore showing no trade is taken) and from this chart, no signals are made (also showing no trade is taken).

                    Looking forward to your response.

                    Click image for larger version

Name:	SignalChart.png
Views:	12
Size:	32.7 KB
ID:	1136798

                    Comment


                      #25
                      Hello ComfyCouch,

                      At what time is the order being submitted that is not being filled?

                      I only see one place that the entry order 'Long' was submitted:

                      12/7/2020 6:22:00 PM Strategy '-': Entered internal SubmitOrderManaged() method at 12/7/2020 6:22:00 PM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=3682.75 StopPrice=0 SignalName='Long' FromEntrySignal=''

                      At what time are you seeing another Long order being submitted in the output from TraceOrders?


                      Can you save the output to a text file and include this as an attachment? This keeps your posts short and includes the full output from the output window.
                      (See the forum thread post on using prints for detailed steps on saving the output to a text file)

                      May I confirm you have watched the video under the label 'Below I am providing a link to videos that demonstrate adding prints to a script to get further information about the behavior of the script." in it's entirety? (You will need to follow the steps in this video to print the values to confirm a cross above)


                      Are you wanting to know why the conditions are not submitting the order again?

                      Use Prints() to understand the behavior as I have directed in post #13 and post #21.

                      For the condition:
                      Code:
                      if (myEntryOrder == null && CrossAbove(longcondition, 3))
                      Above add a print to confirm myEntryOrder is null:
                      Code:
                      if (myEntryOrder == null)
                      Print(Time[0].ToString() + " | myEntryOrder is null);
                      This will let you know you have properly set the myEntryOrder to null for a new entry.

                      Also print the current value of the longcondition series on the previous bar and current bar.
                      Code:
                      Print(string.Format("{0} | longcondition[1]: {1} < 3 && longcondition[0]: {2}  > 3", Time[0], longcondition[1], longcondition[0]));
                      May I confirm that longcondition is a Series object? Otherwise this code will not compile. The space is not allowed either. This looks to be invalid code.


                      Last edited by NinjaTrader_ChelseaB; 01-14-2021, 12:12 PM.
                      Chelsea B.NinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by fdalgoi, Today, 12:44 AM
                      0 responses
                      2 views
                      0 likes
                      Last Post fdalgoi
                      by fdalgoi
                       
                      Started by thomaswilleford, Today, 12:07 AM
                      0 responses
                      3 views
                      0 likes
                      Last Post thomaswilleford  
                      Started by dlygorivw, Yesterday, 10:55 PM
                      0 responses
                      2 views
                      0 likes
                      Last Post dlygorivw  
                      Started by dlygorivw, Yesterday, 10:53 PM
                      0 responses
                      4 views
                      0 likes
                      Last Post dlygorivw  
                      Started by janiyaconnelly, Yesterday, 10:41 PM
                      0 responses
                      3 views
                      0 likes
                      Last Post janiyaconnelly  
                      Working...
                      X