Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trying to use Signal Names to scale out of a position.

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

    Trying to use Signal Names to scale out of a position.

    Hi,

    Relatively new to C# and NT. I am trying to implement a simple example of scaling out of a position.

    The example I'm using is a 5 lot initial position with a set stop of 15 ticks.

    I want to exit out of the first position at a profit of 10 ticks, 2nd profit of 20 ticks, 3rd at 30 ticks and 4th at 40 ticks.

    I would like to also use a trailing stop on the 5th position at 15 ticks when the position is up 40 ticks, not sure how to do that.

    I would also like to set stops to Breakeven on all 5 when the first price target is hit at +10 ticks, not sure how to do that either.

    I used the strategy builder.. The signal name for the initial stop loss of 15 ticks was generated on the SetStopLoss(@"" .

    I wasn't sure if that syntax was correct and meant all positions of incorrect.

    When I ran it it looked like it was basically working but received an error message on the orders that basically shut the strategy down.

    I and trying to rerun to get the text of the error messaged,

    Thank to anyone that can lend a hand?

    Glen


    SetProfitTarget(@"LE1", CalculationMode.Ticks, 10);
    SetProfitTarget(@"LE2", CalculationMode.Ticks, 20);
    SetProfitTarget(@"LE3", CalculationMode.Ticks, 30);
    SetProfitTarget(@"LE4", CalculationMode.Ticks, 40);


    SetStopLoss(@"", CalculationMode.Ticks, InitStop, false);
    SetTrailStop(@"LE5", CalculationMode.Ticks, TStop, false);



    /* ------Entry COndition Criteria met --------------------------------------------------------------------------------------------- */


    {
    EnterLong(Convert.ToInt32(DefaultQuantity), @"LE1");
    EnterLong(Convert.ToInt32(DefaultQuantity), @"LE2");
    EnterLong(Convert.ToInt32(DefaultQuantity), @"LE3");
    EnterLong(Convert.ToInt32(DefaultQuantity), @"LE4");
    EnterLong(Convert.ToInt32(DefaultQuantity), @"LE5");

    #2
    Hello demarcog,

    Thank you for your post.

    The SetStopLoss() method can NOT be used concurrently with the SetTrailStop() or SetParabolicStop() method for the same position, if any methods are called for the same position (fromEntrySignal) the SetStopLoss() will always take precedence. You can however, use all three methods in the same strategy if they reference different signal names.

    So trying to use SetStopLoss() with no signal name, which would fire for all of the entries, with SetTrailStop would not work.

    The logic you're wanting to achieve is really too complex for using SetStopLoss for your stops in the Strategy Builder - you'd have more flexibilty if you were manually coding. However, you can use Exit methods to mimic the action of SetStopLoss and use your own logic to move those stops as you wish.

    Examples of this approach can be found on this post from an older forum thread:

    https://ninjatrader.com/support/foru...84#post1103384

    I'd recommend starting small and getting your functionality for each entry working one at a time, then adding further logic for each additional entry.

    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Hi Kate,

      Thank you very much for the response that link you provided to an earlier post was very useful and pretty ingenious solution.

      It's not a problem coding outside of the strategy builder but If I can have a baseline program that stays in the Strategy Builder compatible for the most part that works too.

      Other languages that I used did not have a property definition and get/set functions as does C# and I'm just getting familiar with that aspect of the language, and general C# references or specific Ninja Script C# resources would be appreciated.



      Thanks again,

      glen

      Comment


        #4
        Hello demarcog,

        Thank you for your reply.

        This page of our help guide may be helpful in understanding Attributes for Properties:

        https://ninjatrader.com/support/help...attributes.htm

        I'd recommend taking a look at this publicly available documentation from Microsoft that goes into detail about Properties:

        https://docs.microsoft.com/en-us/dot...cts/properties

        Please let us know if we may be of further assistance to you.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Kate,

          Thanks for the links.

          Glen
          Last edited by demarcog; 04-15-2021, 02:07 PM.

          Comment


            #6
            Originally posted by demarcog View Post
            Other languages that I used did not have a property definition and get/set functions as does C# and I'm just getting familiar with that aspect of the language, and general C# references or specific Ninja Script C# resources would be appreciated.
            Apparently, you've managed to bypass the world of Java.



            The era of Microsoft .NET and C# was born in late 1990s
            because Microsoft wanted to better control their own destiny
            (which was still heavily tied to Windows) and the darling language
            of the new internet era (aka, Java) could not be adequately
            subsumed into Windows.

            Microsoft had wanted to better customize Java for Windows,
            and Sun Microsystems said no.

            C# properties, and terminology like "getter" and "setter",
            come from the world of Java.

            Comment


              #7
              Hello demarcog,

              Thank you for your reply.

              Does the strategy you've copied and pasted this code into have an added data series? I notice you're referring to Closes[1] in your code sample, but you don't mention if the strategy has an added series for that to be referencing.

              Thanks in advance; I look forward to assisting you further.
              Kate W.NinjaTrader Customer Service

              Comment


                #8
                Hi Kate,

                That is a very timely reminder I was just testing the version that did not access the additional series.

                I did put add these statements into the strategy:


                AddDataSeries(Data.BarsPeriodType.Minute, 15);
                AddDataSeries(Data.BarsPeriodType.Minute, 30);

                Do I need to further identify the symbol or anything else in the strategy.

                Is there a way of adding Renko or Unirenko as additional series?

                And of course I'd like to add different symbols in a similar manner?

                BTW regarding Properties, I am somewhat familiar with Java and have had to copy and paste my way through a few programs but wasn't sure if Java was a taboo topic on the forum given the history. I'm sure the choice to write NT in .net was a complicated and difficult one. IB runs about the largest application I know of In Java and there are performance issues and IB's plaatform has maybe 5 % of the functionality of NT, so it may not have been a serious consideration.

                What was amazing about Java was the true platform independence which obviously MS could never get behind, I had applications that ran on $10 million dollar IBM Mainframe's Java Virtual Machine that I could literally also run Windows/Mac laptop JVM or even my samsung phone's which I always thought was the most striking feature of Java.

                Thank you
                glen

                Comment


                  #9
                  Hello demarcog,

                  Thank you for your reply.

                  If you're adding a data series of one of the basic types using AddDataSeries, if you don't specify the instrument the primary instrument will be used. Renko bars can be added using AddRenko(). You can add a custom BarsType which is installed on your system by casting the registered enum value for that BarsPeriodType. For example: AddDataSeries((BarsPeriodType)14, 10); You would need to know the registered enum for that type.

                  You can also specify a different instrument for the added series from the primary series:

                  AddDataSeries("ES 09-16", BarsPeriodType.Tick, 100);

                  Information about AddDataSeries() can be found in our help guide here:
                  https://ninjatrader.com/support/help...dataseries.htm

                  Please let us know if we may be of further assistance to you



                  Kate W.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by wooofad, 06-15-2020, 01:08 PM
                  8 responses
                  92 views
                  0 likes
                  Last Post echoxray  
                  Started by bubblegum, Today, 12:00 AM
                  0 responses
                  2 views
                  0 likes
                  Last Post bubblegum  
                  Started by eseorvuda, Yesterday, 10:28 PM
                  0 responses
                  2 views
                  0 likes
                  Last Post eseorvuda  
                  Started by ctrent, Yesterday, 09:58 PM
                  0 responses
                  5 views
                  0 likes
                  Last Post ctrent
                  by ctrent
                   
                  Started by cxbnbvc, Yesterday, 09:25 PM
                  0 responses
                  2 views
                  0 likes
                  Last Post cxbnbvc
                  by cxbnbvc
                   
                  Working...
                  X