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

Create new condition

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

    Create new condition

    Hi, i have one question:

    Is it possible insert a new condition(for example: Close[0] > Close [1]) from the edit strategy or similar menů?

    I try to create two variable in this way:

    #region properties

    private string condition1a = "Close";
    private string condition1b = "Close";
    private BoolSeries condition1;

    #endregion

    condition1.Set( condition1a[0] < condition1b[1] ? true : false );// in OnBarUpdate!

    if( condition1 == true )

    EnterLong();

    But it doesn't work. Other Idea?

    #2
    Originally posted by bergimax View Post
    ... But it doesn't work. Other Idea?
    What does that mean?

    Any error message? How is the behavior unexpected for you?

    Comment


      #3
      Thank's for the replay Koganam!

      There isn't error. Inspired of the example below, i would like to enterLong if Close[0] is < of Close [1], but it enter Long even if Close[0] is > of Close [1].

      The condition is ever true.

      Comment


        #4
        Originally posted by bergimax View Post
        Thank's for the replay Koganam!

        There isn't error. Inspired of the example below, i would like to enterLong if Close[0] is < of Close [1], but it enter Long even if Close[0] is > of Close [1].

        The condition is ever true.
        There should be an error in your log. What is it?

        Comment


          #5
          Originally posted by bergimax View Post
          #region properties

          private string condition1a = "Close";
          private string condition1b = "Close";
          private BoolSeries condition1;

          #endregion

          condition1.Set( condition1a[0] < condition1b[1] ? true : false );// in OnBarUpdate!

          if( condition1 == true )

          EnterLong();
          i would like to overwrite conditiona and conditionb with Close or other code indicator from the edit strategy. The code above it's ever true. i don't know if it's possible, but i try to do it.

          I don't know if I explained well what I'm going to do.

          Comment


            #6
            Hello bergimax,

            You are not checking if Close[0] < Close[1].

            You are checking if condition1a[0] < condition1b[1]. These are both strings, containing "Close". You are getting the int value of char 'C' from condition1a and char 'l' from condition1b, which are 67 and 108 respectively.

            If you want to store Close[0] and Close[1] to a variable, you need to make these variables doubles.

            Example:
            Code:
            private double condition1a = 0;
            private double condition1b = 0;
            
            protected override void OnBarUpdate()
            {
                 if (CurrentBar < 1) // we need to do this check to ensure that we have at least two bars or else we'll run into a run-time error when checking for Close[1] when the script is running on the first bar
                      return;
            
                 condition1a = Close[0];
                 condition1b = Close[1];
            }
            Zachary G.NinjaTrader Customer Service

            Comment


              #7
              Thank's for the replay _ZacharyG!

              My question is: How can i import a code( it can be, for example, Close[0] > Close[1] ) from the edit strategy into my script? Is it possible?

              Comment


                #8
                Hello bergimax,

                Just to clarify, are you speaking of the Strategy Wizard or from a different script that you can see the code for?

                If you are speaking of the Strategy Wizard, you can click on the "View Code" button to take a look at the code.

                I'm not entirely clear about what you are trying to import. You can simply write:

                Code:
                if (Close[0] > Close[1])
                     EnterLong();
                if you would like to enter a long position if the current close price is more than the previous close price for example.
                Zachary G.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Barry Milan, Yesterday, 10:35 PM
                5 responses
                16 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by DanielSanMartin, Yesterday, 02:37 PM
                2 responses
                13 views
                0 likes
                Last Post DanielSanMartin  
                Started by DJ888, 04-16-2024, 06:09 PM
                4 responses
                13 views
                0 likes
                Last Post DJ888
                by DJ888
                 
                Started by terofs, Today, 04:18 PM
                0 responses
                12 views
                0 likes
                Last Post terofs
                by terofs
                 
                Started by nandhumca, Today, 03:41 PM
                0 responses
                8 views
                0 likes
                Last Post nandhumca  
                Working...
                X