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

scaling out of longstoplimit order?

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

    scaling out of longstoplimit order?

    my goals:
    1. enter with qty 2
    2. exit with 1st target 10 ticks
    3. trail stop 10 ticks

    from what I've read so far, I would need the following:

    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.UniqueEntries;

    SetProfitTarget("Long 1a", CalculationMode.Ticks, 10);
    SetTrailStop(CalculationMode.Ticks, 10);

    EnterLong("Long 1a");
    EnterLong("Long 1b");

    I've tried inputting these but have gotten errors. I think it's from my labelling "Long 1a" in the wrong lines....

    My working code so far (with qty 1):
    {
    #region Variables
    // Wizard generated variables
    private int 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>
    protected override void Initialize()
    {
    Add(WMA(30));
    SetStopLoss("", CalculationMode.Ticks, 20, false);

    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (Close[0] > WMA(30)[0])
    {
    EnterLongStopLimit(DefaultQuantity, High[0] + 2 * TickSize, High[0] + 2 * TickSize, "");
    }

    // Condition set 2
    if (Close[0] < EMA(9)[0])
    {
    ExitLong("", "");
    }
    }

    Thank you in advance

    #2
    Hello benww604,

    Thank you for your post.

    Are you changing the DefaultQuantity property when running the backtest?

    This would default to a value of 1 unless changed.

    Additionally, are the orders getting placed when entering, or are the orders not filling as expected?
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Thanks Cal, using the samplescaleout I was able to figure it out. I used a simple entry/exit to understand

      protected override void Initialize()
      {
      EntriesPerDirection = 1;
      EntryHandling = EntryHandling.UniqueEntries;

      CalculateOnBarClose = true;

      SetProfitTarget("long1", CalculationMode.Ticks, 10);
      SetTrailStop("", CalculationMode.Ticks, 10, false);

      }

      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {
      // Condition set 1
      if (CrossAbove(Close, EMA(3), 1))
      {
      if (Position.MarketPosition == MarketPosition.Flat)
      {
      EnterLong("long1");
      EnterLong("long2");
      }
      }

      }

      Comment


        #4
        maybe I spoke too soon, or have gotten myself confused lol

        I've successfully coded with 2 qty @ market order, exit at 2 different targets with:
        SetProfitTarget("long1", CalculationMode.Ticks, 8);
        SetProfitTarget("long2", CalculationMode.Ticks, 15);
        &
        EnterLong("long1");
        EnterLong("long2");

        now how do I do the same with a EnterLongStopLimit?

        I know how to enter 1 qty as
        EnterLongStopLimit(DefaultQuantity, High[0] + 2 * TickSize, High[0] + 2 * TickSize, "");

        Thanks again

        Comment


          #5
          It works now if I edit the code to:
          EnterLongStopLimit(1, High[0] + 2 * TickSize, High[0] + 2 * TickSize, "long1");
          EnterLongStopLimit(1, High[0] + 2 * TickSize, High[0] + 2 * TickSize, "long2");

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Carolscogginsi, Yesterday, 10:45 PM
          0 responses
          6 views
          0 likes
          Last Post Carolscogginsi  
          Started by RaddiFX, Yesterday, 10:15 AM
          2 responses
          15 views
          0 likes
          Last Post RaddiFX
          by RaddiFX
           
          Started by patrickmlee007, Yesterday, 09:33 AM
          2 responses
          18 views
          0 likes
          Last Post patrickmlee007  
          Started by magnatauren, 08-15-2020, 02:12 PM
          5 responses
          208 views
          0 likes
          Last Post RaddiFX
          by RaddiFX
           
          Started by rene69851, 05-02-2024, 03:25 PM
          1 response
          23 views
          0 likes
          Last Post rene69851  
          Working...
          X