Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Changing offset

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

    Changing offset

    The following code produces the error that an offset cannot appear in the code as + or -. Instead, the offset has to be applied to the price. I know how to do this in the wizard but the wizard is no longer available:

    // Condition set 1
    if (Position.MarketPosition == MarketPosition.Flat
    && CrossAbove(LinReg(Close,
    15), (LinReg(Close, 2) + aBuff), 1))
    {
    EnterLong(n,
    "B.LRx");
    }

    How do I chang aBuff (my offset) to an offset of LinReg(Close)? Do I do this directly in the code? If yes, how?

    Thanks.

    #2
    CrossAbove(LinReg(Close, 15), (LinReg(Close, 2)[0] + aBuff), 1)
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Trailing stop

      Thanks, Josh. That worked. Another question:


      The following code is in the Initialize method:

      SetTrailStop("BLRX", CalculationMode.Percent, 10, true);
      SetTrailStop(
      "SSLRX", CalculationMode.Percent, 10, true);

      I would like to make the trailing stop conditional, as in the Easy Language code I have been translating to C#:

      If PositionProfit >= Mn then SetDollarTrailing(STS)

      If I write:

      // Condition set 7
      if Position.GetProfitLoss(Close[0],PerformanceUnit.Points > MN

      {
      SetTrailStop("BLRx"), CalculationMode.Currency, 10, true);
      SetTrailStop("SSRx") , CalculationMode,Currency, 10, true) ;
      }

      If I do this, I will have changed the location of the trailing stop code from Initialize to OnBarUpdate.

      Is the above code correct?
      Is the changed location OK?

      Thanks for your help.

      Comment


        #4
        For a 10% stop you should use 0.10 instead of 10.

        The change looks fine at a glance. Remember that you will need to reset your changes afterwards if you want it to go back to what was in Initialize(). Please also see this reference: http://www.ninjatrader-support2.com/...ead.php?t=3222
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Syntax Errors

          For code indicated below, I am getting 1502 and 1503 error messages but can't figure out why:

          1502: The best overloaded method match for NinjaTrader Strategy.Base.SetTrailStop(double) has some invalid arguments.

          1503: Argument '1' cannot be convert from 'string' to 'double'.

          Code:
          SetTrailStop(
          "B.LRx") (CalculationMode.Price[0], 50 );

          (The name in the quotes ("") is the name of the entry signal to which this stop applies.)

          Comment


            #6
            skat100, it looks like you an incorrect sequence of paramters in your SetTrailStop call - please try this -

            Code:
             
            SetTrailStop("B.LRx", CalculationMode.Price, 50, false);
            BertrandNinjaTrader Customer Service

            Comment


              #7
              New syntax error

              After eliminating all compilation errors, I noticed that although all my input variables were declared upfront, each one was repeated in Properties.

              After I added input variable double STS, I got a new error message indicating that I was duplicating the STS definition.

              I don't want to delete the Properties entry because then STS will be the only input variable not listed under Properties.

              What should I do? Delete the STS Properties entry I made? All the other Properties were created by the compiler. If I delete STS in Properites, will the compiler then re-create the entry?

              I used the same capitalization for the Properties STS entry as in the other Properties entries.

              Comment


                #8
                skat100,

                When you make your own please be extremely mindful of what letters are capitalized and which ones are not. Please take a look at your wizard generated ones as a guideline you should follow.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Misinterpretation

                  Hi, Josh,

                  Thanks for the response. However, I believe my message was misinterpreted. I was asking why the compiler did not include in Properties the new input variable (STS) that I had added.

                  When I saw that the compiler did not add a new Property after I added the new input variable, I created my own Property for that input variable (STS).

                  Now, the compiler is displaying the error, "The type NinjaTrader.Strategy.LinRegX already contains a definition for STS"

                  If I remove the property that I added, to get rid of the error message, then that input variable will be the only one that is not repeated in Properties.

                  What should I do?

                  Comment


                    #10
                    skat100, please post the code you have now - for adding additional user defined inputs, please follow the steps listed here - http://www.ninjatrader-support2.com/...ead.php?t=5782

                    Please check step 4 for the proper capitalization needed.
                    BertrandNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by DayTradingDEMON, Today, 09:28 AM
                    3 responses
                    19 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by Stanfillirenfro, Today, 07:23 AM
                    9 responses
                    23 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by George21, Today, 10:07 AM
                    0 responses
                    8 views
                    0 likes
                    Last Post George21  
                    Started by navyguy06, Today, 09:28 AM
                    1 response
                    7 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Started by cmtjoancolmenero, Yesterday, 03:58 PM
                    8 responses
                    33 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Working...
                    X