Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

basic help on program a strategy

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

    basic help on program a strategy

    if I just wanted to create a strategy in which,

    at a particular time (editable), open 1 position (long or short) with a limit of X and stop of Y...
    then close the position if limit has not been reached and position is still in the green (has made a slight gain) by a particular time.


    thanks

    #2
    Welcome to the forum.

    I suspect you are new to strategy development with NinjaTrader? What I would suggest is starting off with the strategy development tutorials in the Help Guide. There are two in there that will help you get started.

    If you are not a programmer and will be using the Strategy Wizard, check out the Help Guide sections on the Strategy Wizard. There are many basic examples along with some video tutorials.

    Once you have done this, start off small and create a strategy that has only one condition in it. Then add layer onto layer until you finally reach what you want.
    RayNinjaTrader Customer Service

    Comment


      #3
      thanks for the reply...

      I actually went through the help files...

      how do I get the condition builder to create a true condition statement at 9:30am go long and then at 4:15 close position...

      would that mean... select the time with a value of 9:30am and the symbol "==" to the time with a value of 9:30am
      then add the action to go long?

      and then do the same for 4:15? I'm a little confused but then go short?

      Comment


        #4
        I'm willing to pay someone to teach me a few basics...
        sorta in a hurry to learn...

        Comment


          #5
          Hi z32000,

          Please check out this reference sample here. http://www.ninjatrader-support.com/v...ead.php?t=3226

          It demonstrates a similar concept to what you want that you can copy paste and tweak. What you want to do is apply a time filter to your trades basically.

          Code:
          if(ToTime(Time[0]) == 93000)
          {
               EnterLong();
          }
          if(ToTime(Time[0]) == 161500)
          {
               ExitLong();
          }
          To create this through the condition builder you would want to select the Time series value on the left hand side and input a Time value on the right hand side. At the moment this will not work because there is a bug with the condition builder, but in the next release it should be fixed.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            optimizing

            Thanks Josh, actually I figured this out over the weekend. In regards to optimizing this strategy to get the most profit by testing various times to enter and exit a position. How do I go about doing this? Thanks for the help


            Originally posted by Josh View Post
            Hi z32000,

            Please check out this reference sample here. http://www.ninjatrader-support.com/v...ead.php?t=3226

            It demonstrates a similar concept to what you want that you can copy paste and tweak. What you want to do is apply a time filter to your trades basically.

            Code:
            if(ToTime(Time[0]) == 93000)
            {
                 EnterLong();
            }
            if(ToTime(Time[0]) == 161500)
            {
                 ExitLong();
            }
            To create this through the condition builder you would want to select the Time series value on the left hand side and input a Time value on the right hand side. At the moment this will not work because there is a bug with the condition builder, but in the next release it should be fixed.

            Comment


              #7
              Create a user definable parameter for enterTime and exitTime. Then instead of the previous code I pasted try using this:
              Code:
              if (ToTime(Time[0]) == enterTime)
              {
                   EnterLong();
              }
              if (ToTime(Time[0]) == exitTime)
              {
                   ExitLong();
              }
              Then use the Strategy Analyzer's optimize on those parameters. I would imagine it would take quite awhile optimize and it might come up with funky results because you are running strictly on time intervals.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                thanks very much Josh

                I'm assuming by user definable parameter, you mean something like
                int enterTime=930000; //does this go in OnBarUpdate()?

                also, I've tried to run backtests on simple code...for some reason, it does not always seem to put in a position on ES futures a few minutes after midnight or where the volume is low. Is there an option to force it to enter that trade even with a low volume. I don't think there is a mistake in the code since the trade would work at hours times except when the volume is low.


                Originally posted by Josh View Post
                Create a user definable parameter for enterTime and exitTime. Then instead of the previous code I pasted try using this:
                Code:
                if (ToTime(Time[0]) == enterTime)
                {
                     EnterLong();
                }
                if (ToTime(Time[0]) == exitTime)
                {
                     ExitLong();
                }
                Then use the Strategy Analyzer's optimize on those parameters. I would imagine it would take quite awhile optimize and it might come up with funky results because you are running strictly on time intervals.

                Comment


                  #9
                  In the Variables section add:
                  private int enterTimeFrame = 93000;

                  in the Properties section near the end add:
                  [Description("Starting Time for Trading (HHMMSS)")]
                  [Category("Parameters")]
                  public int EnterTimeFrame
                  {
                  get { return enterTimeFrame; }
                  set { enterTimeFrame = Math.Max(0, value); }
                  }

                  I don't know what your code is exactly. You can check volume by running comparisons against the volume series.
                  Code:
                  if (Volume[0] > 10000)
                       EnterLong();
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    this sounds like a basic question...

                    but say if I wanted to get the current date of the first day...

                    so for example

                    FirstTradingDay=(ToDay(ToTime[0]));

                    where do I put this in order for it to only run once (instead of having it update the current day in the OnBarUpdate function all the time)?

                    Thanks

                    Comment


                      #11
                      Add it in the OnBarUpdate() but have a bool variable that prevents it from running multiple times. Or you can also use the CurrentBar variable to check.

                      Code:
                      if (firstBar == true)
                      {
                           FirstTradingDay = ToDay(Time[0]);
                           firstbar = false;
                      }
                      Josh P.NinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      566 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      330 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by Mindset, 02-09-2026, 11:44 AM
                      0 responses
                      101 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                      0 responses
                      547 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      548 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X