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

Just need help being pointed in the right direction

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

    Just need help being pointed in the right direction

    I have an indicator I'd like to build a strategy out of. In the strategy builder I'm not seeing the option to open a trade for the single indicator trade condition I want. Basically I need it to buy on the up signals and close the trade and sell on the down signals. Always in a trade. The other thing is being able to set a trade size as a percentage- say 1% of the account risked on each trade. There would be stop losses on each trade in case my computer crashes or internet goes out but I can probably find that. The indicator is ColorThePlot, which was posted by NinjaTrader Paul H.

    ps I did do some searching around for the answers or resources first. Any help is appreciated

    #2
    Hello jjaffa,

    Thank you for your post.

    That indicator has three plots, the plot that contains the values for the line itself (CTPPlot), and then 2 hidden plots. These hidden plots are "Signal" that provides a +1, 0, or-1 for direction change and "direction" for the current direction, +1 for up, -1 for down.

    So if you want to buy based on a direction change to up, you'd want to make sure the Signal plot is selected and then compare that to a numeric value under the misc folder. If it equals 1, that's up, so submit a buy order.

    It would not be possible to create an entry with the quantity based on a percentage of your account size via the Strategy Builder. This would require accessing the Account class which the builder cannot do, you'd have to manually code the logic to get the account, access the account value and calculate a position size based on the account. Further information about manually coding based on Account values can be found in our help guide here:



    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Thank you. Am I looking at a strategy like that being on one script or a strategy calling on the separate indicator script?

      Comment


        #4
        Hello jjaffa,

        Thank you for your reply.

        If you wanted to code the logic from the indicator into a manually coded strategy you certainly could, however, you'd just be calling an instance of the indicator within your strategy and seeing what it returns for the Signal and Direction plots.

        Please let us know if we may be of further assistance to you.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          I've got the logic written out in plain english and plan on slowly converting it using the guide. I can't find where to start a new strategy from scratch. I can open sample strategies and delete the code but i'm not finding a blank slate anywhere. I previously messed around with nt7 and could find it there.

          Comment


            #6
            Hello jjaffa,

            Thank you for your reply.

            To start a new strategy, you can open a NinjaScript Editor window, then right click on the Strategies folder in the NinjaScript Explorer and select "New Strategy". This will bring up the strategy wizard, which will allow you to set your basic setup for the strategy, including user inputs. Proceed through the Wizard screens and click done, and you'll be presented with the basic outline of your strategy which you can then fill in with your logic.

            Please let us know if we may be of further assistance to you.
            Kate W.NinjaTrader Customer Service

            Comment


              #7
              i think i've got the position size figured out. i'll have to fix how it an round to a whole lot number that that's about it. now if i want the strategy to trade based on the colortheplot indicator do i need to have the indicator code in the strategy? or should i modify the code in the indicator to generate buy/sell/close signals and have the strategy pick up on them ?

              thanks for your help

              Comment


                #8
                Hello jjaffa,

                Thank you for your reply.

                It would not be necessary to pull all the indicator's logic into your own script, instead what I'd recommend is setting that logic up in a separate Strategy Builder strategy to see how that's set up to check whether the Signal plot is returning a 1, 0, or -1, as I outlined in post #2, then enter in the appropriate direction based on the value returned. You can then unlock that code, and integrate it with what you have set up to establish the lot size.

                Please let us know if we may be of further assistance to you.

                Kate W.NinjaTrader Customer Service

                Comment


                  #9
                  so if i have the indicator running on the chart and activate the strategy, the strat script will just read the plot points on the chart? It would be just if signal = 1 then buy? or is the strategy running on the indicator and not the chart?

                  Comment


                    #10
                    I've gone through the setup for a new strategy and I see what you're saying. This gave me a lot to work with. Thank you

                    Comment


                      #11
                      Hello jjaffa,

                      Thank you for your reply.

                      No, a strategy would not be able to just read plot points on the chart drawn by an instance of the indicator that was applied manually to the chart. The indicator would need to be called from within the strategy. This will create it's own instance of the strategy that's not necessarily rendered to the chart, but that the strategy will access for its calculations.

                      Here is a simple example of what I've set up in an example strategy using the Strategy Builder that I've then unlocked, that calls the ColorThePlot Indicator, have it displayed on the chart automatically from the Strategy itself, check the Signal plot to see if it's a 1, and if so, to enter long.

                      Code:
                       private ColorThePlot ColorThePlot1;
                      
                      protected override void OnStateChange()
                      {
                      if (State == State.SetDefaults)
                      {
                      Description = @"Enter the description for your new custom Strategy here.";
                      Name = "MyCustomStrategy";
                      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 = false;
                      RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
                      StopTargetHandling = StopTargetHandling.PerEntryExecution;
                      BarsRequiredToTrade = 20;
                      // Disable this property for performance gains in Strategy Analyzer optimizations
                      // See the Help Guide for additional information
                      IsInstantiatedOnEachOptimizationIteration = true;
                      }
                      else if (State == State.Configure)
                      {
                      }
                      else if (State == State.DataLoaded)
                      {
                      ColorThePlot1 = ColorThePlot(Close, true, Brushes.Green, Brushes.Gold, Brushes.Red, 2, NinjaTrader.NinjaScript.PlotStyle.Line, NinjaTrader.Gui.DashStyleHelper.Solid, 3);
                      ColorThePlot1.Plots[0].Brush = Brushes.CornflowerBlue;
                      ColorThePlot1.Plots[1].Brush = Brushes.Transparent;
                      ColorThePlot1.Plots[2].Brush = Brushes.Transparent;
                      AddChartIndicator(ColorThePlot1);
                      }
                      }
                      
                      protected override void OnBarUpdate()
                      {
                      if (BarsInProgress != 0)
                      return;
                      
                      if (CurrentBars[0] < 1)
                      return;
                      
                      // Set 1
                      if (ColorThePlot1.Signal[0] == 1)
                      {
                      EnterLong(Convert.ToInt32(DefaultQuantity), "");
                      }
                      
                      }
                      Please let us know if we may be of further assistance to you.
                      Kate W.NinjaTrader Customer Service

                      Comment


                        #12
                        Here's what I have. I'm just not positive that the signals are going to close the opposite trades. In other words, if it enters a long trade and then gets a short signal, is it going to close the long trade before opening a short?

                        This should be last question: Where it says DefaultQuantity in the code, can I replace that with the variable I created that calculates lot size?

                        Comment


                          #13
                          Also, I'm having trouble getting AccountItem.CashValue to work in an equation. I'm getting a cannot convert type to double. Do I need another line to print and store the number when needed?

                          Comment


                            #14
                            Hello jjaffa,

                            Thank you for your reply.

                            It should be noted that you should not call both an exit order for a position and an entry order for the opposite direction in the same bar. This is because EnterLong() and EnterShort() will automatically submit an order to close the current position if one exists prior to entering, so if you also submit an Exit order, you'll end up with the opposite position doubled.

                            For example, let's say you're in a long position and trying to reverse to a short position. If you call both ExitLong() and EnterShort() at the same time, exit long will submit a short market order to bring you back to a flat position, but since that order hasn't been processed yet, EnterShort() will submit both a short market order to exit the long position, and then another short market order to get you to what it thinks should be a 1 short position. The end result is you'd be in a 2 short position rather than the 1 short you'd expect.

                            For your second question, could you provide the code in question that's not working for you?

                            Thanks in advance; I look forward to assisting you further.

                            Kate W.NinjaTrader Customer Service

                            Comment


                              #15
                              Thanks, that simplifies things a lot. The code or syntax I'm getting an error with is AccountItem.CashValue. I want to create a variable using an equation involving calling that number (or value). So something like
                              Code:
                              double n = (AccountItem.CashValue * .01)
                              That would give me one percent of the amount of cash in the account. I still need to factor in leverage and how to get a solid number so there are no errors with the trade amount.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Taddypole, 04-26-2024, 02:47 PM
                              2 responses
                              14 views
                              0 likes
                              Last Post Taddypole  
                              Started by futtrader, 04-21-2024, 01:50 AM
                              6 responses
                              58 views
                              0 likes
                              Last Post futtrader  
                              Started by sgordet, Today, 11:48 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post sgordet
                              by sgordet
                               
                              Started by Trader146, Today, 11:41 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post Trader146  
                              Started by jpapa, 04-23-2024, 07:22 AM
                              2 responses
                              22 views
                              0 likes
                              Last Post rene69851  
                              Working...
                              X