NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 02-19-2009, 12:14 PM   #1
zacharydw00
Member
 
Join Date: Jul 2008
Posts: 78
Thanks: 0
Thanked 0 times in 0 posts
Default 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 at 12:20 PM.
zacharydw00 is offline  
Reply With Quote
Old 02-19-2009, 12:22 PM   #2
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

zacharydw00,

You can only get individual fill prices if you use IOrder objects. Please see the Help Guide article on IOrder for more information.
NinjaTrader_Josh is offline  
Reply With Quote
Old 02-19-2009, 02:33 PM   #3
zacharydw00
Member
 
Join Date: Jul 2008
Posts: 78
Thanks: 0
Thanked 0 times in 0 posts
Default

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.
zacharydw00 is offline  
Reply With Quote
Old 02-19-2009, 02:41 PM   #4
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

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);
NinjaTrader_Josh is offline  
Reply With Quote
Old 02-19-2009, 11:48 PM   #5
zacharydw00
Member
 
Join Date: Jul 2008
Posts: 78
Thanks: 0
Thanked 0 times in 0 posts
Default

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?
zacharydw00 is offline  
Reply With Quote
Old 02-20-2009, 07:20 AM   #6
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

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.
NinjaTrader_Josh is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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


All times are GMT -6. The time now is 06:02 PM.