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

Strategy is ignoring my conditions

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

    Strategy is ignoring my conditions

    I'll be as brief as possible. I made 2 indicators that work fine. Their results leave my charts when I refresh, but I'm working on that. They create 2 independent numbers, neg or pos, during every bar. My goal: if both those numbers are above my user defined pos numbers, go long; if both those numbers are below my user defined neg numbers, go short.

    I watched the strategy video where an SMA crossover is created, so I attempted to do this using my indicators. In 'user defined inputs' I made all as double, even stop/target, since I can get neg results. If this is wrong, let me know. Where my strategy differs from the SMA strategy is in the condition builder. In the SMA video on the left side a value was put in the 'my input' line. I have no user inputs to put on the left side. The indicator creates a value based on its time frame, I use tick charts, and that value is compared to the right side. When I backtest this strategy, using current day only, it takes a trade at every bar, ignoring my conditions.

    I assume when the indicator is chosen on the left side the value it calculates is compared to the user input value on the right. Is this correct? Can you tell where I'm going wrong?
    Is there a detailed strategy video that demonstrates what I'm trying to do?

    Thank you very much.

    #2
    Hello imalil,

    Thank you for your inquiry.

    Just to clarify, is it that both indicators generate both negative and positive numbers, or is it that just one indicator creates negative numbers and the other creates positive numbers?

    If it's the former case, can you please clarify what you mean by "if both those numbers are above my user defined pos numbers, go long; if both those numbers are below my user defined neg numbers, go short"?

    You would be able to specify negative numbers in User Defined Inputs in either int or double. Just remember that ints can only be whole numbers and doubles can have a decimal.

    In the Condition Builder, the value on the left side of the window is compared to the value of the right side of the window.

    In order to assist further, can you please provide a screenshot of the conditions you have defined in the Conditions and Actions page?

    To send a screenshot with Windows 7 or newer I would recommend using Window's Snipping Tool.

    Click here for instructions

    Alternatively to send a screenshot press Alt + PRINT SCREEN to take a screen shot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save as a jpeg file and send the file as an attachment.

    Click here for detailed instruction
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Both inds can create neg and pos numbers and work independently. The conditions I need, for example: if ind #1 creates a number > 3 (or whatever I choose), AND ind #2 creates a number > 100 (or whatever I choose), during one bar, go long. Alternatively, if ind #1 creates a number < -3 (or whatever I choose), AND ind #2 creates a number < -100 (or whatever I choose), during one bar, go short. Does that clarify? I can't get you screenshots until tomorrow.

      Thank you.

      Comment


        #4
        Hello imalil,

        Thank you for your response.

        To do this, you'll want to have two set conditions.

        In your first set, you'll want to add two conditions:
        • Select your first indicator from the left side of the Condition Builder. Ensure that ">" is selected in the middle drop down. To the right side of the Condition Builder, select either a User Defined Variable (if you wish for this value to be changed through the strategy's properties) or Misc -> Numeric value with a value of 3 (if you wish to hard code this into your strategy).

        • Select your second indicator from the left side of the Condition Builder. Ensure that ">" is selected in the middle drop down. To the right side of the Condition Builder, select either a User Defined Variable (if you wish for this value to be changed through the strategy's properties) or Misc -> Numeric value with a value of 100 (if you wish to hard code this into your strategy).

        Under the Do the following section, you'll want to enter long.

        In your second set, you'll want to add two conditions:
        • Select your first indicator from the left side of the Condition Builder. Ensure that "<" is selected in the middle drop down. To the right side of the Condition Builder, select either a User Defined Variable (if you wish for this value to be changed through the strategy's properties) or Misc -> Numeric value with a value of -3 (if you wish to hard code this into your strategy).

        • Select your second indicator from the left side of the Condition Builder. Ensure that "<" is selected in the middle drop down. To the right side of the Condition Builder, select either a User Defined Variable (if you wish for this value to be changed through the strategy's properties) or Misc -> Numeric value with a value of -100 (if you wish to hard code this into your strategy).

        Under the Do the following section, you'll want to enter short.

        Just to clarify, do your indicators create two different plots, one for positive and one for negative, or do the indicators only have one plot that plots both a negative and positive number?
        Zachary G.NinjaTrader Customer Service

        Comment


          #5
          Reading your instructions, I believe I did all this. My user-defined variables are probably the issue. I'll experiment with this.

          "Just to clarify, do your indicators create two different plots, one for positive and one for negative, or do the indicators only have one plot that plots both a negative and positive number?" The pos numbers get plotted below the bar, neg numbers plotted above, if that's what you mean. Is this a problem?

          Thanks for the info.

          Comment


            #6
            Hello imalil,

            No, this shouldn't be a problem. I only wanted to clarify if your indicators created two different lines (one only for positive numbers and one only for negative numbers) or if they created only one line (accounting for both positive and negative numbers).

            The reason why I asked is because having an indicator with two different plots would mean that you would also need to select the corresponding plot you would like to use from your indicators for your conditions in the Strategy Wizard.

            Please, let me know if I can be of further assistance.
            Zachary G.NinjaTrader Customer Service

            Comment


              #7
              "The reason why I asked is because having an indicator with two different plots would mean that you would also need to select the corresponding plot you would like to use from your indicators for your conditions in the Strategy Wizard."

              I believe you're right. How is this accomplished?

              Thanks for the help.

              Comment


                #8
                Let me clarify something: the ind creates neg and pos numbers in OnMarketData, in OnBarUpdate the neg numbers are printed on one part of the chart, the pos numbers are printed on a different part. The data are then cleared, and OnMarketData starts again on the new bar.

                Thanks.

                Comment


                  #9
                  Let me further clarify: in my ind, under initialize I have one plot:
                  Add(new Plot(Color.Green, "Plot0")); Overlay = true;

                  Under OnBarUpdate I have my answer calculated by the ind, and language that says:

                  "if the number > 3, Drawtext...etc." that places it below the bar. This is my first plot.

                  "if the number < -3, Drawtext...etc." that places it above the bar. This is my second plot.

                  So it appears to be setup with one plot. If this is the problem, is there a simple fix?

                  Thank you for the help.

                  Comment


                    #10
                    Hello imalil,

                    Thank you for the additional information.

                    When the values are generated by OnMarketData() and OnBarUpdate(), are the plots being assigned to these values?

                    You can create another plot in Initialize() by just using Add().

                    Example
                    Code:
                    Add(new Plot(....));
                    Just for further clarification on my end, can you please post your indicator's script file to your response? You can find the .cs file for your indicator in (My) Documents\NinjaTrader 7\bin\Custom\Indicator.

                    If you prefer not to post it on the forum, you can send it to platformsupport [AT] ninjatrader [DOT] com with a link to this thread and my name referenced.
                    Zachary G.NinjaTrader Customer Service

                    Comment


                      #11
                      "When the values are generated by OnMarketData() and OnBarUpdate(), are the plots being assigned to these values?"

                      The values are generated by OnMarketData. In OnBarUpdate these values (numbers) themselves, if they meet my conditions, are printed on my chart, above or below the bar, using the Drawtext command. So the OnMarketData generated numbers are printed on my charts. That's as clear as I can make it.

                      I made this ind with a programmer friend of mine and I'm not allowed to send it out, I hope you understand.

                      As for adding new plots in initialize, how do I tie the Drawtext print commands in OnBarUpdate to the new plots? I assume I need only two plots, one for each ind, specified in conditions.

                      Thank you for the help.

                      Comment


                        #12
                        Here is how the ind gets printed.

                        if ((+ imbalance) > 0)
                        {
                        DrawText("imbalance" + CurrentBar, AutoScale, (+ imbalance).ToString(), 0, Low[0], -47,
                        Color.Pink, ChartControl.Font, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);}

                        How do I tie this command to a new plot in initialize? Everything seems straightforward except for this one point.

                        Thank you.

                        Comment


                          #13
                          Hello imalil,

                          I would suggest creating a variable that will hold the value that is being drawn by DrawnText();

                          In order to assign your plots to a value and allow another indicator/strategy to access these plot values, you would need to ensure that you have created two DataSeries for your plots and use the Set() method to assign values to these plots.

                          Example:
                          Code:
                          protected override void Initialize()
                          {
                               Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0")); // plot 1
                               Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0")); // plot 2
                          }
                          
                          protected override void OnBarUpdate()
                          {
                               Plot0.Set(Close[0]); // set plot 0 to the value of Close[0]
                               Plot1.Set(Close[1]); // set plot 1 to the value of Close[1]
                          }
                          
                          #region Properties
                          [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
                          [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
                          public DataSeries Plot0
                          {
                               get { return Values[0]; }
                          }
                          
                          [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
                          [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
                          public DataSeries Plot1
                          {
                               get { return Values[1]; }
                          }
                          #endregion
                          Zachary G.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Segwin, 05-07-2018, 02:15 PM
                          12 responses
                          1,785 views
                          0 likes
                          Last Post Leafcutter  
                          Started by poplagelu, Today, 05:00 AM
                          0 responses
                          3 views
                          0 likes
                          Last Post poplagelu  
                          Started by fx.practic, 10-15-2013, 12:53 AM
                          5 responses
                          5,407 views
                          0 likes
                          Last Post Bidder
                          by Bidder
                           
                          Started by Shai Samuel, 07-02-2022, 02:46 PM
                          4 responses
                          98 views
                          0 likes
                          Last Post Bidder
                          by Bidder
                           
                          Started by DJ888, Yesterday, 10:57 PM
                          0 responses
                          8 views
                          0 likes
                          Last Post DJ888
                          by DJ888
                           
                          Working...
                          X