• 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

  • YakusaTrader
    started a topic Scalling in positions when losing

    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.

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

    Leave a comment:


  • NinjaTrader_PatrickH
    replied
    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.

    Leave a comment:


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

    Leave a comment:


  • YakusaTrader
    replied
    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

    }
    }

    Leave a comment:


  • NinjaTrader_Jim
    replied
    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.

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by indy73, Yesterday, 10:52 PM
0 responses
3 views
0 likes
Last Post indy73
by indy73
 
Started by martyn73, Yesterday, 07:04 PM
0 responses
5 views
0 likes
Last Post martyn73  
Started by sergey_z, Yesterday, 02:56 PM
1 response
10 views
0 likes
Last Post NinjaTrader_Jesse  
Started by samir, Yesterday, 02:46 PM
1 response
20 views
0 likes
Last Post NinjaTrader_Kate  
Started by neoikon, Yesterday, 02:24 PM
1 response
8 views
0 likes
Last Post NinjaTrader_ChristopherJ  
Working...
X