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

Default position size

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

    #16
    Hello jjaffa,

    Thanks for your post.

    The signal of the indicator is likely only going to be 1 for a single bar and then 0 for many bars after.

    What indicator is the input to the ColorThePlot indicator?

    What bar type and bar size are you testing this on?

    Are you testing on live data, playback with market replay data or Historical data on a chart or historical data in the strategy analyzer?

    What is the strategies Calculate setting? (Calculate.OnBarClose, Calculate.OnEachTick, Calculate.OnPriceChange)

    Your code is exiting the trade on the next bar after the entry and you can see that it is trying to exit when there is no position to exit (This was an exit order but no position exists to exit'). You may want to rethink your strategy coding so that you are only exiting when there is a position to exit. One approach to this is to check to see if you are in a market position and then exit that position rather than exiting without first seeing you are in a position.

    Reference: https://ninjatrader.com/support/help...etposition.htm
    Paul H.NinjaTrader Customer Service

    Comment


      #17
      It's coded (or so I thought) if the indicator plots sideways or 0 signal or yellow on the plot line, it exits whatever position it's in. Otherwise it goes long for up or 1 or green, and short for down or -1 or red (for the plot line). I would think, even if the signal only goes off for the first bar of a trend, there's nothing in the logic to signal closing the position. Say if it signaled 1 and it entered long, it wouldn't signal 0 at the next green plotted bar. I'm running this on renko 2 pip block size. I'm wondering if there's something in the defaults, I don't understand what they all mean and most are left at default.

      Code:
      Calculate = Calculate.OnBarClose;
      EntriesPerDirection = 1;
      EntryHandling = EntryHandling.AllEntries;
      IsExitOnSessionCloseStrategy = true;
      ExitOnSessionCloseSeconds = 30;
      IsFillLimitOnTouch = false;
      MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
      OrderFillResolution = OrderFillResolution.Standard;
      Slippage = 0;
      StartBehavior = StartBehavior.WaitUntilFlat;
      TimeInForce = TimeInForce.Gtc;
      TraceOrders = true;
      RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
      StopTargetHandling = StopTargetHandling.PerEntryExecution;
      BarsRequiredToTrade = 20;

      Comment


        #18
        Hello jjaffa,

        Thanks for your reply.

        From the ColotThePlot indicator there are actually two signals provided. From the code of the indicator it shows:

        AddPlot(Brushes.Transparent, "Signal"); // signal change of direction (for duration of bar)
        AddPlot(Brushes.Transparent, "Direction"); // provides +1 while in up direction or -1 while in down (Flat is part of direction until changed)

        The plot "Signal" will only be +1 or -1 when there is a signal and for all other bars it will be zero meaning there is no change of direction.

        The plot "Direction" will be +1 for up direction and will stay that way on every bar until the direction has changed, to -1

        Perhaps what you want is the Direction plot instead.
        Paul H.NinjaTrader Customer Service

        Comment


          #19
          I did this and it was promising when I backtest. I can see the entries are holding until the direction change. When I run it on a live chart it looks like it tries to keep entering a new position for each consecutive bar of the same direction afterward. This throws me an error and output that I think says the same (Ill attach the error and output). I'm thinking I need to figure add some logic having to do with IF the previous signal/direction/plot is the same THEN do nothing.

          Attached Files

          Comment


            #20
            Hello jjaffa,

            Thanks for your post.

            You might want to only enter a new position when the strategy market position is flat to go along with only exiting a position when you are in a position.

            Paul H.NinjaTrader Customer Service

            Comment


              #21
              Hi Paul,

              How is it possible to create an input for the quantity? From the unlocked strategy?

              I tried adding
              Code:
              [INDENT]Qty = 2;[/INDENT]
              to the (State == State.SetDefaults) scope,

              and
              Code:
              [INDENT][NinjaScriptProperty][/INDENT][INDENT][Range(1, int.MaxValue)]
              [Display(Name="Qty", Order=1, GroupName="Parameters")]
              public int Qty
              { get; set; }[/INDENT]
              to the properties.

              and
              Code:
              [INDENT]Qty = 2;[/INDENT]
              to the protected override void OnBarUpdate() scope.

              But the trades executed only 1 unit.

              Then I deleted the
              Code:
              [INDENT]Qty = 2;[/INDENT]
              from the protected override void OnBarUpdate() scope, leaving it in the (State == State.SetDefaults) scope, and keeping the
              Code:
              [INDENT][NinjaScriptProperty]
              [Range(1, int.MaxValue)]
              [Display(Name="Qty", Order=1, GroupName="Parameters")]
              public int Qty
              { get; set; }[/INDENT]
              in the properties.

              It's working but I'm not sure why and if it's the right way to do it in view of your recommendation from post #13:

              The Qty field display in the strategy window and on the chart:


              I also have the orders quantity set like this:
              Code:
              EnterLong(Convert.ToInt32(Qty));
              Code:
              [INDENT]
              ExitLongStopMarket(Convert.ToInt32(Qty) ... [/INDENT]

              Do you recommend any other more efficient way to do it? How would you do it yourself?

              Thanks a lot for your help!

              Comment


                #22
                Hello Cormick,

                Thanks for your post.

                Regarding EnterLong(Convert.ToInt32(Qty)); you can use that but it is somewhat redundant to use Convert.ToInt32() since you are already creating Qty as a public int type. The use of the Convert method would be useful when you are calculating a quantity from various data types and want to ensure that only a whole number is provided.

                You can simplify to EnterLong(Qty);
                Paul H.NinjaTrader Customer Service

                Comment


                  #23
                  Hi Paul,

                  All right thanks a lot for the great info! I'll adjust as your advice now.

                  Comment


                    #24
                    How come when I change:

                    EnterLong((DefaultQuantity==1));
                    or
                    EntriesPerDirection = 1;

                    in something like the strategy analyzer it always stays with 1 share? thanks

                    Comment


                      #25
                      Hello ezrollin,

                      Thanks for your post.

                      Entries per direction and Default quantity are two different things.

                      Entries per direction is discussed here: https://ninjatrader.com/support/help...rdirection.htm

                      In the Strategy Analyzer, by default, the default quantity will be up to the Strategy itself. The Strategy Analyzer's "Set Order Quantity" field will be set to "Strategy" meaning the quantity values used in the strategy itself will be applied. So if the strategy is set to 100 then the analyzer will trade 100.

                      You can change the Strategy Analyzer "Set Order Quantity" field to "Default quantity" which will be 1 but you can then set it to any integer value you wish. In this mode when the strategy places an order it will be at the quantity specified by the analyzer.


                      Paul H.NinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by wzgy0920, 04-20-2024, 06:09 PM
                      2 responses
                      26 views
                      0 likes
                      Last Post wzgy0920  
                      Started by wzgy0920, 02-22-2024, 01:11 AM
                      5 responses
                      32 views
                      0 likes
                      Last Post wzgy0920  
                      Started by wzgy0920, Yesterday, 09:53 PM
                      2 responses
                      49 views
                      0 likes
                      Last Post wzgy0920  
                      Started by Kensonprib, 04-28-2021, 10:11 AM
                      5 responses
                      191 views
                      0 likes
                      Last Post Hasadafa  
                      Started by GussJ, 03-04-2020, 03:11 PM
                      11 responses
                      3,230 views
                      0 likes
                      Last Post xiinteractive  
                      Working...
                      X