Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SamplePriceModification problem

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

    SamplePriceModification problem

    I am using SamplePriceModification for my strategy. It is simple strategy where if condition is met Profit target is set to 80 ticks, stop loss at 40 ticks and if price hit above 30 ticks
    stop is set to breakeven. My problem is when two or more positions are open they are all closed when one of the positions hits stop or profit target. How can the others position stay
    opened until they met their targets?

    This is my code:


    /// </summary>
    protected override void Initialize()
    {
    /* There are several ways you can use SetStopLoss and SetProfitTarget. You can have them set to a currency value
    or some sort of calculation mode. Calculation modes available are by percent, price, and ticks. SetStopLoss and
    SetProfitTarget will submit real working orders unless you decide to simulate the orders. */
    SetStopLoss(CalculationMode.Ticks, stoplossticks);
    SetProfitTarget(CalculationMode.Ticks, profittargetticks);

    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Resets the stop loss to the original value when all positions are closed
    if (Position.MarketPosition == MarketPosition.Flat)
    {
    SetStopLoss(CalculationMode.Ticks, stoplossticks);
    }

    // If a long position is open, allow for stop loss modification to breakeven
    else if (Position.MarketPosition == MarketPosition.Long)
    {
    // Once the price is greater than entry price+50 ticks, set stop loss to breakeven
    if (Close[0] > Position.AvgPrice + 40 * TickSize)
    {
    SetStopLoss(CalculationMode.Price, Position.AvgPrice);
    }
    }

    // Condition set 1
    if (CurrentDayOHLC().CurrentOpen[0] > PriorDayOHLC().PriorHigh[0]
    && ToTime(Time[0]) > ToTime(8, 10, 0)
    && ToTime(Time[0]) < ToTime(8, 31, 0))
    {
    EnterLong(DefaultQuantity, "");
    }
    }

    #region Properties
    /// <summary>
    /// </summary>
    [Description("Numbers of ticks away from entry price for the Stop Loss order")]
    [Category("Parameters")]
    public int StopLossTicks
    {
    get { return stoplossticks; }
    set { stoplossticks = Math.Max(0, value); }
    }

    /// <summary>
    /// </summary>
    [Description("Number of ticks away from entry price for the Profit Target order")]
    [Category("Parameters")]
    public int ProfitTargetTicks
    {
    get { return profittargetticks; }
    set { profittargetticks = Math.Max(0, value); }
    }
    #endregion
    }
    }

    #2
    Hi flexi, the concept would need to be extended to using multiple entry signals names to scale in, so you would be able then to scale out later of your position and have also different stop / target adjustment possible happen per each unique signal used. Here's an example you can review and then incorporate in your own code - http://www.ninjatrader.com/support/f...ead.php?t=3751
    BertrandNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Lumbeezl, 01-11-2022, 06:50 PM
    31 responses
    817 views
    1 like
    Last Post NinjaTrader_Adrian  
    Started by xiinteractive, 04-09-2024, 08:08 AM
    5 responses
    14 views
    0 likes
    Last Post NinjaTrader_Erick  
    Started by swestendorf, Today, 11:14 AM
    2 responses
    6 views
    0 likes
    Last Post NinjaTrader_Kimberly  
    Started by Mupulen, Today, 11:26 AM
    0 responses
    6 views
    0 likes
    Last Post Mupulen
    by Mupulen
     
    Started by Sparkyboy, Today, 10:57 AM
    1 response
    6 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Working...
    X