Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to get the fill price of a signalName?

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

    How to get the fill price of a signalName?

    I need to get the fill price for signalName "BuyMktT2" and "BuyMktT3". Position.AvgPrice will not give the correct price if "BuyLmt1" and "BuyLmt2" are filled. I have read; SamplePriceModification, SampleOnOrderUpdate, SampleScaleOut, and help sections; IOrder, OnPositionUpdate(), OnExecution(), and Client class. But, I haven't found any examples to fit this exact case. How do I set BuyMktT2Fill to the fill price of signalName "BuyMktT2", or should I not use a variable? Is there a ?.AvgFillPrice client class I should use, if so, how? Please include any information as to what may need to be added to the Variables and Initialize() sections. Below is an excerpt of my strategy.
    Thanks!


    #region Variables
    private int stoplosstk = 40; // Default setting for Stoploss
    private int target1 = 4; // Default setting for Target1
    private double target2 = 8; // Default setting for Target2
    private int target3 = 11; // Default setting for Target3
    private double BuyMktT2Fill = 0; // Fill price of "BuyMktT2"
    private double BuyMktT3Fill = 0; // Fill price of "BuyMktT3"
    #endregion

    protected override void Initialize()
    {
    SetProfitTarget("BuyMktT1", CalculationMode.Ticks, Target1);
    SetProfitTarget("BuyMktT2", CalculationMode.Ticks, Target2);
    SetProfitTarget("BuyMktT3", CalculationMode.Ticks, Target3);
    SetProfitTarget("BuyLmt1", CalculationMode.Ticks, 5);
    SetProfitTarget("BuyLmt2", CalculationMode.Ticks, 6);
    SetStopLoss("", CalculationMode.Ticks, Stoplosstk, false);

    Add(PeriodType.Tick, 150); // Add a 150 TICK Bars object to the strategy

    CalculateOnBarClose = true;
    }

    // LONG Condition 1
    {
    SetStopLoss(CalculationMode.Ticks, stoplosstk); // Resets the STOPLOSS to the original value
    EnterLong(1,6, "BuyMktT1"); // Sold at 4 ticks profit from entry
    EnterLong(1,2, "BuyMktT2"); // Sold at 8 ticks profit from entry
    EnterLong(1,2, "BuyMktT3"); // Sold at 10 ticks profit from entry
    }

    // LONG Condition 2 - Extra contracts on 3pt candle
    {
    SetStopLoss(CalculationMode.Ticks, stoplosstk); // Resets the STOPLOSS to the original value
    EnterLongLimit(1,5, Close[0] - 3 * TickSize, "BuyLmt1"); // Sold at 5 ticks profit from entry
    EnterLongLimit(1,5, Close[0] - 4 * TickSize, "BuyLmt2"); // Sold at 4 ticks profit from entry
    DrawDiamond("BuyLmtDiamond" + CurrentBar, false, 0, Low[0] + -16 * TickSize, Color.Green);
    }

    // Checks if OnBarUpdate() is called from an update on 150 TICK Bars
    if (BarsInProgress == 1)
    {
    // If a long position is open, allow for stop loss modification to breakeven
    if (Position.MarketPosition == MarketPosition.Long)
    {
    // If 150 tick price is greater than BuyMktT2 entry price + 7 ticks, set stoploss to breakeven
    if (High[0] >= BuyMktT2Fill + 8 * TickSize) <<<--- HERE IS WHERE I NEED HELP !!!!!
    {
    SetStopLoss(CalculationMode.Price, BuyMktT2Fill); // set stoploss to b/e
    }
    }
    }
    Last edited by zacharydw00; 02-19-2009, 01:20 PM.

    #2
    zacharydw00,

    You can only get individual fill prices if you use IOrder objects. Please see the Help Guide article on IOrder for more information.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Is this how to go about getting the fill price of "BuyMktT2"?

      #region Variables
      private IOrder entryMktT2Order = null;

      protected override void OnBarUpdate()
      {
      EnterLong(2, "BuyMktT1");
      entryMktT2Order = EnterLong(2, "BuyMktT2");
      entryMktT3Order = EnterLong(2, "BuyMktT3");

      Will entryMktT2Order.AvgFillPrice contain the EnterLong fill price for "BuyMktT2" only?
      Last edited by zacharydw00; 02-19-2009, 03:37 PM.

      Comment


        #4
        Yup, but remember before you can access any properties you need to check for null reference.

        Code:
        if (entryMktT2Order != null)
             Print("Fill Price: " + entryMktT2Order.AvgFillPric);
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          And..... to make sure I understand the process, entryMktT2Order will equal null until the order is filled and the next OnBarUpdate is processed?

          Also what if entryMktT2Order was capturing a Limit order, on a 5 minute bar strategy with Calculateonbarclose=True?

          For example:
          OnBarUpdate()
          entryMktT2Order = EnterLongLimit(2, "BuyMktT2");

          Is the order data passed to entryMktT2Order after the bar closes(next time OnBarUpdate is processed) or as soon as the order is filled?

          Comment


            #6
            The IOrder is null until you set it to something. The moment you do entryMktT2Order = EnterLongLimit(2, "BuyMKT2") it takes on the order. It does not need to wait for another OnBarUpdate() event. It also does not need to wait for the order to fill. You can use the IOrder the moment you set it and check for order status and watch it through the whole process.
            Josh P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            633 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            364 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            105 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            567 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            568 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X