![]() |
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Jul 2008
Posts: 78
Thanks: 0
Thanked 0 times in 0 posts
|
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 at 12:20 PM.
|
|
|
|
|
|
#2 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Member
Join Date: Jul 2008
Posts: 78
Thanks: 0
Thanked 0 times in 0 posts
|
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 at 02:37 PM.
|
|
|
|
|
|
#4 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Member
Join Date: Jul 2008
Posts: 78
Thanks: 0
Thanked 0 times in 0 posts
|
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? |
|
|
|
|
|
#6 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to make backtested orders fill at the next traded price on gaps? | ChiTrader2000 | Strategy Development | 19 | 02-27-2009 09:16 AM |
| ATM Strategy on average fill price | Quantrade | ATM Strategies (Discretionary Trading) | 3 | 10-29-2008 01:52 PM |
| Fill Price Issues from IB | arbifox | Automated Trading | 2 | 09-23-2008 11:46 AM |
| Is signalName passed to broker | Big D | Strategy Development | 2 | 03-18-2008 10:13 AM |
| Accessing order fill price and quantity | NinjaTrader_Ray | Strategy Development | 2 | 01-03-2008 12:16 AM |