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

How to write a time period in wizard?

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

    How to write a time period in wizard?


    I have problem to write a time period in wizard. For example, I would like to enter long position between 17:00 to 21:00. But it would enter long position in any time.

    // Condition set 1
    if (ToTime(Time[Buy]) > ToTime(17, 0, 0)
    && ToTime(Time[Buy]) < ToTime(
    21, 0, 0)
    && ToDay(Time[
    0]) > ToDay(2007, 6, 13))
    {
    EnterLong(DefaultQuantity,
    "");
    }

    Would you please tell me what I should do?
    Thanks

    #2
    Instead of Time[Buy] try Time[0].
    RayNinjaTrader Customer Service

    Comment


      #3
      I had tried to change the Time[0], but the same result, it enter long anytime. Is the time series including the date? If how add this restriction?
      Thanks
      Last edited by Jenny; 06-13-2007, 01:36 PM.

      Comment


        #4
        Hi Jenny,

        Please see the attached strategy. This strategy will only enter a long position on the first bar after 10 AM and between 12:00 PM. I just verified that this works as expected.

        You can save this in the following folder and open it and compile.
        Attached Files
        RayNinjaTrader Customer Service

        Comment


          #5
          Whick folder I should save to? It is a .php file, can I compile using NinjaTrader? It look much different from Ninjarscript.
          Thanks
          Last edited by Jenny; 06-13-2007, 02:42 PM.

          Comment


            #6
            My Documents\NinjaTrader 6\bin\Custom\Strategy
            RayNinjaTrader Customer Service

            Comment


              #7
              I can't compile it, it is .php file, not the same as .cs file.
              thanks

              Comment


                #8
                If you click on the file, you should be able to save as a .cs file.
                RayNinjaTrader Customer Service

                Comment


                  #9
                  Is &quot;Enter optional stop loss and....&quot; the same as...

                  In the wizard, is "Enter optional stop loss and...." the same as function as "Enter Long/short position by a stop limid order"?
                  How can I set up 2 trailling stop triggered by 2 kind of profit (like in SuperDOM)?

                  Thanks

                  Comment


                    #10
                    No this is not the same.

                    Enter() methods submit orders to enter a position. Exit() method submit orders to exit a position.

                    The optional Stop Loss/Profit Target orders are used to submit orders on the opening of a position. They are just a different form of Exit() methods since they submit orders immediately instead of on the close of a bar.

                    Creating a multi-stop trail stop needs to be done programmatically instead of through the wizard. However, you can use a SetTrailStop() which trails immediately.
                    RayNinjaTrader Customer Service

                    Comment


                      #11
                      Could you please write the code for "multi-stop trail stop " for us? So that we can copy and paste after we finish program using wizard?

                      I really appreciate that.
                      Jenny

                      Comment


                        #12
                        Hi Jenny,

                        Thats a good idea and I will put that on our list of actions. Unfortunately I can not provide this sample any time soon as we are restricted right now on resource bandwidth. Thanks for understanding.
                        RayNinjaTrader Customer Service

                        Comment


                          #13
                          I would like to try by myself if you are too busy. But I couldn't find any information about the function SetTrailStop() from here http://www.ninjatrader-support.com/H...ManagingOrders

                          Can you tell me where I can find it?

                          Thanks

                          Comment


                            #14
                            No problem.

                            RayNinjaTrader Customer Service

                            Comment


                              #15
                              I just try a code after your link, thanks.
                              I couldn't compile this one, can you tell me why,
                              #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.Strategy;
                              #endregion
                              // This namespace holds all strategies and is required. Do not change it.
                              namespace NinjaTrader.Strategy
                              {
                              ///<summary>
                              /// Enter the description of your strategy here
                              ///</summary>
                              [Description("Enter the description of your strategy here")]
                              [Gui.Design.DisplayName(
                              "SeptStop2")]
                              publicclass SeptStop2 : Strategy
                              {
                              #region Variables
                              // Wizard generated variables
                              privateint 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>
                              protectedoverridevoid Initialize()
                              {
                              CalculateOnBarClose =
                              true;
                              }
                              ///<summary>
                              /// Called on each bar update event (incoming tick)
                              ///</summary>
                              protectedoverridevoid OnBarUpdate()
                              {
                              // Sets a trail stop of 12 ticks
                              SetTrailStop(CalculationMode.Ticks, 12);
                              if (Position.MarketPosition != MarketPosition.Flat)
                              &&
                              if (Position.GetProfitLoss(Close[0], PerformanceUnit.Points) )>= 4;
                              {
                              int stopLoss = 2;
                              Print(
                              "Setting stop to "+stopLoss+" in "+instrumentName+" at "+Time[0]);
                              SetTrailStop(OrderName, CalculationMode.Ticks, stopLoss,
                              false);
                              }
                              #region Properties
                              [Description(
                              "")]
                              [Category(
                              "Parameters")]
                              publicint MyInput0
                              {
                              get { return myInput0; }
                              set { myInput0 = Math.Max(1, value); }
                              }
                              #endregion
                              }
                              }

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by warreng86, 11-10-2020, 02:04 PM
                              5 responses
                              1,356 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by Perr0Grande, Today, 08:16 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post Perr0Grande  
                              Started by elderan, Today, 08:03 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post elderan
                              by elderan
                               
                              Started by algospoke, Today, 06:40 PM
                              0 responses
                              10 views
                              0 likes
                              Last Post algospoke  
                              Started by maybeimnotrader, Today, 05:46 PM
                              0 responses
                              12 views
                              0 likes
                              Last Post maybeimnotrader  
                              Working...
                              X