• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Scalling in positions when losing

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

    Scalling in positions when losing

    Hi,

    Is there a way to open new positions every 20 ticks from initial position (same direction) when it is still open and losing?

    Example:
    If my initial position is still open and 20 ticks losing, then open additional position 1, if my initial position is still open and 40 ticks losing, then open additional position 2, etc...

    Thank you very much in advance.

    #2
    Hello YakusaTrader,

    Thanks for your post.

    There are some internal rules to opening positions in the opposite direction when you are already in position, however these rules would not effect entering another position in the same direction.

    The strategy would just have to have Entries Per Direction and EntryHandling to be set to allow multiple entries in the same direction. The logic would then need to be defined to control your entries and subsequent entries.

    I've included documentation resourced on these items as well the Managed Approach's Internal Rules for further reading.

    Entry Handling - https://ninjatrader.com/support/help...ryhandling.htm

    Entries Per Direction - https://ninjatrader.com/support/help...rdirection.htm

    Managed Approach Internal Rules - https://ninjatrader.com/support/help...antedPositions

    Please let us know if we can be of further assistance.
    Last edited by NinjaTrader_Jim; 09-13-2018, 12:33 PM.
    JimNinjaTrader Customer Service

    Comment


      #3
      I appreciate your help.

      I put something together -- it's working thank you!

      #region Using declarations
      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.ComponentModel.DataAnnotations;
      using System.Linq;
      using System.Text;
      using System.Threading.Tasks;
      using System.Windows;
      using System.Windows.Input;
      using System.Windows.Media;
      using System.Xml.Serialization;
      using NinjaTrader.Cbi;
      using NinjaTrader.Gui;
      using NinjaTrader.Gui.Chart;
      using NinjaTrader.Gui.SuperDom;
      using NinjaTrader.Gui.Tools;
      using NinjaTrader.Data;
      using NinjaTrader.NinjaScript;
      using NinjaTrader.Core.FloatingPoint;
      using NinjaTrader.NinjaScript.Indicators;
      using NinjaTrader.NinjaScript.DrawingTools;
      #endregion

      //This namespace holds Strategies in this folder and is required. Do not change it.
      namespace NinjaTrader.NinjaScript.Strategies
      {
      public class ScallingUp : Strategy
      {
      private double Counter;


      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = @"Enter the description for your new custom Strategy here.";
      Name = "ScallingUp";
      Calculate = Calculate.OnBarClose;
      EntriesPerDirection = 100;
      EntryHandling = EntryHandling.UniqueEntries;
      IsExitOnSessionCloseStrategy = true;
      ExitOnSessionCloseSeconds = 30;
      IsFillLimitOnTouch = false;
      MaximumBarsLookBack = MaximumBarsLookBack.Infinite;
      OrderFillResolution = OrderFillResolution.High;
      OrderFillResolutionType = BarsPeriodType.Minute;
      OrderFillResolutionValue = 1;
      Slippage = 0;
      StartBehavior = StartBehavior.WaitUntilFlatSynchronizeAccount;
      TimeInForce = TimeInForce.Gtc;
      TraceOrders = false;
      RealtimeErrorHandling = RealtimeErrorHandling.IgnoreAllErrors;
      StopTargetHandling = StopTargetHandling.PerEntryExecution;
      BarsRequiredToTrade = 20;
      // Disable this property for performance gains in Strategy Analyzer optimizations
      // See the Help Guide for additional information
      IsInstantiatedOnEachOptimizationIteration = true;
      Distance = 20;
      QTY = 1;
      Profit = 10;
      }
      else if (State == State.Configure)
      {
      }
      }

      protected override void OnBarUpdate()
      {
      if (BarsInProgress != 0)
      return;

      if (CurrentBars[0] < 20)
      return;



      // Set 1
      if (Close[0] > Close[1] && (Position.MarketPosition == MarketPosition.Flat))
      {
      EnterLong(QTY, "");
      Counter = 1;
      }

      // Set 2
      if ((Position.MarketPosition != MarketPosition.Flat)
      && (Close[0] <= (Position.AveragePrice - (Distance * TickSize * Counter))))
      {
      EnterLong(QTY, "");
      Counter += 1;
      }

      if ((Position.MarketPosition != MarketPosition.Flat)
      && (Close[0] >= (Position.AveragePrice + (Profit * TickSize))))
      {
      ExitLong();
      }



      if (Position.MarketPosition == MarketPosition.Flat)
      {
      Counter = 0;
      }

      Print("Counter is : " + Counter);
      Print(Time[0]);
      Print("Quantity is : " + Position.Quantity);

      }

      #region Properties
      [NinjaScriptProperty]
      [Range(0, int.MaxValue)]
      [Display(Name="Distance", Order=1, GroupName="Parameters")]
      public int Distance
      { get; set; }

      [NinjaScriptProperty]
      [Range(1, int.MaxValue)]
      [Display(Name="QTY", Order=2, GroupName="Parameters")]
      public int QTY
      { get; set; }

      [NinjaScriptProperty]
      [Range(1, int.MaxValue)]
      [Display(Name="Profit", Order=3, GroupName="Parameters")]
      public int Profit
      { get; set; }

      #endregion

      }
      }

      Comment


        #4
        Position.AveragePrice is the average entry price of all opened positions, is there a way to identify the initial entry position?

        Comment


          #5
          Hello YakusaTrader,

          Thank you for your response.

          You would need to manually track the first execution through OnExecutionUpdate() as there is not a direct access to the initial entry for the position.

          Please visit the following link for details on OnExecutionUpdate(): https://ninjatrader.com/support/help...tionupdate.htm

          Please let me know if you have any questions.
          Patrick H.NinjaTrader Customer Service

          Comment


            #6
            Tnx, I was working on it.
            https://ninjatrader.com/support/foru...ead.php?t=7499

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by bomanpbm, Yesterday, 09:27 PM
            0 responses
            2 views
            0 likes
            Last Post bomanpbm  
            Started by tgn55, Yesterday, 08:47 AM
            0 responses
            8 views
            0 likes
            Last Post tgn55
            by tgn55
             
            Started by ballboy11, 05-04-2019, 10:26 AM
            6 responses
            58 views
            0 likes
            Last Post Kermit
            by Kermit
             
            Started by mrlucky1x, 06-14-2019, 10:01 PM
            0 responses
            15 views
            0 likes
            Last Post mrlucky1x  
            Started by roger556, 06-14-2019, 09:22 PM
            0 responses
            8 views
            0 likes
            Last Post roger556  
            Working...
            X