Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

trying to create a strategy comparing the open and close of a bar

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

    trying to create a strategy comparing the open and close of a bar

    I'm trying to create a strategy that says that if the close of the 940 bar on a 10 minute chart is higher than the open of the 940 bar then.......

    I'm new at this but I've tried using the wizard several times and in several different ways but when I run the backtest, it always picks up trades that it shouldn't have (i.e. the close was lower than the open but it took the trade anyway) If anyone can get me started on the right track, I'd sure appreciate.

    Thanks, Carl

    #2
    Hi Carl,

    Thank you for your post and welcome to our forums.

    Was able to do this using the condition builder.
    Two conditions.
    If Time -- Time Series == Time -- Time Value (Set the Value)
    &&
    If Price Data -- Close > Price Data -- Open

    Let us know how you have it setup and we can assist further.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      trying to create a strategy comparing the open and close of a bar

      Thanks Ryan but I'm still having trouble. I think I entered everything the way you said (but maybe not) and this is how it looked totime(time[0]) = = totime(9,40,0) && close[0] >open[0]

      It gave an error message CS0021 which says that the indicator was called without its required parameter arguments

      Thanks again, Carl

      Comment


        #4
        Carl, are you working in the strategy wizard or directly via custom code as you attempt to programm this?

        For custom programming please try this snippet -

        Code:
         
        if (ToTime(Time[0]) == ToTime(9,40,0) && Close[0] > Open[0])
        For the wizard, please post a screenshot of how you have it setup in the condition builder.

        Comment


          #5
          I'm using the wizard but I'll unlock the code and enter what you sent. I'm not sure how do send a screenshot. If you can give me some steps I'll try that.

          Thanks again, Carl

          Is this what you need:
          #region Using declarations
          using System;
          using System.ComponentModel;
          using System.Diagnostics;
          using System.Drawing;
          using System.Drawing.Drawing2D;
          using System.Xml.Serialization;
          using NinjaTrader.Cbi;
          using NinjaTrader.Data;
          using NinjaTrader.Indicator;
          using NinjaTrader.Gui.Chart;
          using NinjaTrader.Strategy;
          #endregion

          // This namespace holds all strategies and is required. Do not change it.
          namespace NinjaTrader.Strategy
          {
          /// <summary>
          /// 950
          /// </summary>
          [Description("950")]
          public class My950 : Strategy
          {
          #region Variables
          // Wizard generated variables
          private int myInput0 = 1; // Default setting for MyInput0
          // User defined variables (add any user defined variables below)
          #endregion

          /// <summary>
          /// This method is used to configure the strategy and is called once before any strategy method is called.
          /// </summary>
          protected override void Initialize()
          {
          SetStopLoss("", CalculationMode.Ticks, 4, false);
          SetProfitTarget("", CalculationMode.Ticks, 6);

          CalculateOnBarClose = false;
          }

          /// <summary>
          /// Called on each bar update event (incoming tick)
          /// </summary>
          protected override void OnBarUpdate()
          {
          // Condition set 1
          if (ToTime(Time[0]) == ToTime(9, 40, 0)
          && Close[0] > Open[0])
          {
          EnterLong(2, "");
          }
          }
          Last edited by cpearce; 02-08-2010, 03:50 PM. Reason: additional info

          Comment


            #6
            Carl, does your posted code work for you?

            If not, what issues do you see?

            For the wizard, I'll attach a screenshot of the needed setup to this post.
            Attached Files

            Comment


              #7
              That's what the wizard puts in for the code but I still get the error code Cs0021 and it won't let me finish the strategy. The error code refers to the line that has the code for time. Let me know what I can do to explain it to you better. I'm new at this so I'm not sure what info you might need.

              Thanks, Carl

              I think it's working now. I finally deleted all of the strategies I had tried to create and started over. When I tried to delete them, it seemed like they were somehow tied together. At first, I couldn't delete them. When I finally deleted one particular strategy, then I was able to delete the rest of them. Maybe that was part of my problem all along. Thanks for the help. You were very helpful

              Thanks again,

              Carl
              Last edited by cpearce; 02-09-2010, 10:20 AM. Reason: additional info

              Comment


                #8
                2 profit targets on the strategy wizard

                As I've gotten along in the strategy wizard I've ran into another problem. When I try to use 2 profit targets by using the "signal name" feature and naming the 2 targets "Long1" and "Long2", only Long1 shows up on the chart when I run the backtest. That's all I see in the execution tab, also, so I'm assuming that the 2nd profit target isn't being calculated in the backtest. Any ideas?

                Thanks,

                Carl

                Comment


                  #9
                  Carl,

                  Please pardon the delay in response time today. We were having some technical issues on our end. Thank you for your continual patience.

                  When you create the targets, the name you provide is not the name of the target you are making, but rather the name of the entry order you want this target to tie to. If you are trying to scale-out with two targets, you would have had to scale-in first with two different signal names. Your entry orders need to have the signal name of "long 1" and "long 2". Then you can attach separate targets to each one of them.

                  When you run your strategy, you will also need to ensure that you increase the EntriesPerDirection from 1 to at least 2 so it will allow you to scale-in.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    Thanks. I hadn't changed the number of trades in each direction. You guys have been a great help. Thanks again. Carl

                    Comment


                      #11
                      Strategy Analyzer won't update

                      When I make changes to my strategy in the 'wizard' the update and show up when I run the backtest, again, as it should.
                      However, once I've unlocked the code, when I make the changes the analyzer doesn't update anything for the backtest. I've even tried saving the change as a completely new strategy but, when I do that, it shows up in the list of strategies on the strategy analyzer page but not as an option when I right click on an instrument and select backtest. When I make a change, such as the number of contracts, it changes when I view the code but not when I run the backtest. After the backtest, when I go back to view the code the changes are still there but they weren't reflected in the backtest. I guess I'm not savingthe changes correctly, although, they appear in the code as though they are changed.

                      Any help is appreciated.

                      Carl

                      Comment


                        #12
                        Hi Carl,

                        If you make any changes to a strategy in code view be sure to hit F5 to compile.

                        You will then have to reapply any instances of the strategy after making changes. This means running another backtest or removing and adding to a chart.
                        Ryan M.NinjaTrader Customer Service

                        Comment


                          #13
                          Thanks Ryan. F5 did the trick!
                          Carl

                          Comment


                            #14
                            I'm writing a strategy for the e-mini s&p and I want to say that if the open of a bar between 1800 and 2000 is higher than the highest high of any bar between 1630 and 1730, enter long.
                            I seem to have it set for the correct time period and I'm using MAX(High, 60) to find the highest high but I can't figure out how to tell it to look at the highest high between 1630 and 1730 every time.
                            When I put a number in brackets such as [2] it seems to look back 60 bars from 2 bars from the current bar. I need it to look at the 60 bars between 1630 and 1730 regardless of which bar is the current bar.
                            Any ideas?

                            Thanks,

                            Carl

                            Comment


                              #15
                              Hi Carl,

                              Please see the reference sample below for one way to do this.

                              Calculating the highest high or lowest low for a specified time range.
                              Ryan M.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              648 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              369 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              109 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              573 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              575 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X