SampleOnOrderUpdate strategy - NinjaTrader Programming | futures io social day trading
futures io futures trading


SampleOnOrderUpdate strategy
Updated: Views / Replies:1,187 / 3
Created: by zeller4 Attachments:2

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you dont need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 
Thread Tools Search this Thread
 

SampleOnOrderUpdate strategy

  #1 (permalink)
Elite Member
Florida
 
Futures Experience: Intermediate
Platform: NT7
Favorite Futures: CL, NQ, NG
 
Posts: 456 since Jun 2009
Thanks: 1,359 given, 383 received

SampleOnOrderUpdate strategy

Hello,

I'm trying to work with this sample code to add a second entry order. I'm stuck at this point of adding another parameter :

 
Code

#region Variables

private IOrder entryOrder1 = null; // This variable holds an object representing our entry order
private IOrder entryOrder2 = null; // This variable holds an object representing our entry order
private IOrder stopOrder1 = null; // This variable holds an object representing our stop loss order
private IOrder stopOrder2 = null; // This variable holds an object representing our stop loss order
private IOrder targetOrder1 = null; // This variable holds an object representing our profit target order
private IOrder targetOrder2 = null; // This variable holds an object representing our profit target order



 
Code

protectedoverridevoid OnOrderUpdate(IOrder order)
{
// Handle entry orders here. The entryOrder object allows us to identify that the order that is calling the OnOrderUpdate() method is the entry order.
if (entryOrder1 != null && 
entryOrder2 != null && 
entryOrder1.Token == order1.Token &&
entryOrder2.Token == order2.Token
)
{ 
// Reset the entryOrder object to null if order was cancelled without any fill
if (order1.OrderState == OrderState.Cancelled && 
order2.OrderState == OrderState.Cancelled && 
order1.Filled == 0 &&
order2.Filled == 0
)
{
entryOrder1 = null;
entryOrder2 = null;
 
}
}
}//end of OnOrderUpdate

so, the only thing (if i understand correctly) needing modifying is:
 
Code

protectedoverridevoid OnOrderUpdate(IOrder order)
{
thanks for your help.
Kirk


Last edited by zeller4; January 16th, 2010 at 09:56 AM.
Reply With Quote
 
  #2 (permalink)
Elite Member
Wrocław, Poland
 
Futures Experience: Intermediate
Platform: NinjaTrader, Racket
Favorite Futures: Ockham's razor
 
gregid's Avatar
 
Posts: 651 since Aug 2009
Thanks: 321 given, 605 received

Hi Kirk,

I modified the SampleOnOrderUpdate strategy to allow multiple entries. Take a look at the attached example, but bear in mind it was written and exported in NT7. To make it work in NT6.5, the main change you will have to make is to compare Tokens instead of Orders directly (as it is advised for NT7)

So for example instead of (NT7)
entryOrder_1a == order

you need to compare (NT6.5):

entryOrder_1a.Token == order.Token

(just refer to original sample)

BTW: here is where the problem is in your code:
order1.Token

it should be just:
order.Token

Attached Files
Register to download File Type: zip IOrdersMulti_Zeller.zip (2.5 KB, 45 views)
Reply With Quote
The following 2 users say Thank You to gregid for this post:
 
  #3 (permalink)
Elite Member
Florida
 
Futures Experience: Intermediate
Platform: NT7
Favorite Futures: CL, NQ, NG
 
Posts: 456 since Jun 2009
Thanks: 1,359 given, 383 received


Awesome, gregid,

thanks so much for your help.

I didn't know that two orders would both use the order.Token and i also didn't know it would be similar for execution.Order.Token.

BTW, what would be a sample of using IPosition now in this code?

I asked the question on another thread if programmers are going fully into v7 strategies or sticking with v6.5 for the moment. What are your thoughts (I haven't checked the other thread yet if you already answered there - will check.

thanks again,
Kirk

Attached Files
Register to download File Type: cs IOrdersMulti_Zeller_v6_5.cs (9.1 KB, 26 views)
Reply With Quote
 
  #4 (permalink)
Elite Member
Switzerland
 
Futures Experience: Intermediate
Platform: Tradestation, Python
Favorite Futures: Forex
 
Posts: 8 since Aug 2014
Thanks: 1 given, 1 received

I am submitting the following condition on the strategy attached above but it is not responding at all. It is entering
the market immediately and it is ignoring the time and if the current open is above yesterday highs.

Can someone help me how to make this conditions active. Bellow is the whole code.

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Submit an entry limit order if we currently don't have an entry order open
[B] if (entryOrder_1a == null && entryOrder_1b == null
&& CurrentDayOHL().CurrentOpen[0] >= PriorDayOHLC().PriorHigh[0]
&& ToTime(Time[0]) > ToTime(8, 30, 0)
&& ToTime(Time[0]) < ToTime(8, 46, 0))
{
/* The entryOrder object will take on a unique ID from our EnterLong()
that we can use later for order identification purposes in the OnOrderUpdate() method. */
entryOrder_1a = EnterLong(1, "Enter Long - Scout");
entryOrder_1b = EnterLong(1, "Enter Long - Runner");
Print("Entered A and B");








// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
/// <summary>
/// Sample demonstrating the use of the OnOrderUpdate() method.
/// </summary>
[Description("Sample strategy demonstrating a use case involving the OnOrderUpdate() method")]
public class SampleOnOrderUpdate : Strategy
{
#region Variables
private IOrder entryOrder_1a = null; // This variable holds an object representing our entry order
private IOrder entryOrder_1b = null; // This variable holds an object representing our entry order
private IOrder stopOrder_1a = null; // This variable holds an object representing our stop loss order
private IOrder stopOrder_1b = null; // This variable holds an object representing our stop loss order
private IOrder targetOrder_1a = null; // This variable holds an object representing our profit target order
private IOrder targetOrder_1b = null; // This variable holds an object representing our profit target order

#endregion

/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
CalculateOnBarClose = true;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.UniqueEntries;
ClearOutputWindow();
TraceOrders = true;
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Submit an entry limit order if we currently don't have an entry order open
if (entryOrder_1a == null && entryOrder_1b == null && CurrentDayOHL().CurrentOpen[0] >= PriorDayOHLC().PriorHigh[0] && ToTime(Time[0]) > ToTime(8, 30, 0) && ToTime(Time[0]) < ToTime(8, 46, 0))
{
/* The entryOrder object will take on a unique ID from our EnterLong()
that we can use later for order identification purposes in the OnOrderUpdate() method. */
entryOrder_1a = EnterLong(1, "Enter Long - Scout");
entryOrder_1b = EnterLong(1, "Enter Long - Runner");
Print("Entered A and B");

}

/* If we have a long position and the current price is 4 ticks in profit, raise the stop-loss order to breakeven.
We use (7 * (TickSize / 2)) to denote 4 ticks because of potential precision issues with doubles. Under certain
conditions (4 * TickSize) could end up being 3.9999 instead of 4 if the TickSize was 1. Using our method of determining
4 ticks helps cope with the precision issue if it does arise. */
if (Position.MarketPosition == MarketPosition.Long && Close[0] >= Position.AvgPrice + (80 * (TickSize / 2)))
{
// Print("Stop order 1a: "+(stopOrder_1a.StopPrice == null? "null" : stopOrder_1a.StopPrice.ToString()) );

// Checks to see if our Stop Order has been submitted already
if (stopOrder_1a != null && stopOrder_1a.StopPrice < Position.AvgPrice)
{
// Modifies stop-loss to breakeven
stopOrder_1a = ExitLongStop(0, true, stopOrder_1a.Quantity, Position.AvgPrice, "Stop Scout", "Enter Long - Scout");

}
if (stopOrder_1b != null && stopOrder_1b.StopPrice < Position.AvgPrice)
{
// Modifies stop-loss to breakeven
stopOrder_1b = ExitLongStop(0, true, stopOrder_1b.Quantity, Position.AvgPrice, "Stop Runner", "Enter Long - Runner");

}
}
}

/// <summary>
/// Called on each incoming order event
/// </summary>
protected override void OnOrderUpdate(IOrder order)
{
// Handle entry orders here. The entryOrder object allows us to identify that the order that is calling the OnOrderUpdate() method is the entry order.
if (entryOrder_1a != null && entryOrder_1a == order)
{
// Reset the entryOrder object to null if order was cancelled without any fill
if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
{
entryOrder_1a = null;
}
}
if (entryOrder_1b != null && entryOrder_1b == order)
{
// Reset the entryOrder object to null if order was cancelled without any fill
if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
{
entryOrder_1b = null;
}
}
}

/// <summary>
/// Called on each incoming execution
/// </summary>
protected override void OnExecution(IExecution execution)
{
/* We advise monitoring OnExecution to trigger submission of stop/target orders instead of OnOrderUpdate() since OnExecution() is called after OnOrderUpdate()
which ensures your strategy has received the execution which is used for internal signal tracking. */
if (entryOrder_1a != null && entryOrder_1a == execution.Order)
{
if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
{
// Stop-Loss order 4 ticks below our entry price
stopOrder_1a = ExitLongStop(0, true, execution.Order.Filled, execution.Order.AvgFillPrice - 48 * TickSize, "Stop Scout", "Enter Long - Scout");

// Target order 8 ticks above our entry price
targetOrder_1a = ExitLongLimit(0, true, execution.Order.Filled, execution.Order.AvgFillPrice + 168 * TickSize, "Target Scout", "Enter Long - Scout");

// Resets the entryOrder object to null after the order has been filled or partially filled
if (execution.Order.OrderState != OrderState.PartFilled)
{
entryOrder_1a = null;
}
}
}
if (entryOrder_1b != null && entryOrder_1b == execution.Order)
{
if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
{
// Stop-Loss order 4 ticks below our entry price
stopOrder_1b = ExitLongStop(0, true, execution.Order.Filled, execution.Order.AvgFillPrice - 48 * TickSize, "Stop Runner", "Enter Long - Runner");

// Target order 8 ticks above our entry price
// for this strategy targetOrder_1b will be disabled
targetOrder_1b = ExitLongLimit(0, true, execution.Order.Filled, execution.Order.AvgFillPrice + 168 * TickSize, "Target Runner", "Enter Long - Runner");

// Resets the entryOrder object to null after the order has been filled or partially filled
if (execution.Order.OrderState != OrderState.PartFilled)
{
entryOrder_1b = null;
}
}
}

// Reset our stop order and target orders' IOrder objects after our position is closed.
if ((stopOrder_1a != null && stopOrder_1a == execution.Order) || (targetOrder_1a != null && targetOrder_1a == execution.Order))
{
if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled)
{
stopOrder_1a = null;
targetOrder_1a = null;
}
}
if ((stopOrder_1b != null && stopOrder_1b == execution.Order) || (targetOrder_1b != null && targetOrder_1b == execution.Order))
{
if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled)
{
stopOrder_1b = null;
targetOrder_1b = null;
}
}

}

/// <summary>
/// Called on each incoming position event
/// </summary>
protected override void OnPositionUpdate(IPosition position)
{
// Print our current position to the lower right hand corner of the chart
DrawTextFixed("MyTag", position.ToString(), TextPosition.BottomRight);
}

#region Properties
#endregion
}
}

Reply With Quote

Reply



futures io > > > > > SampleOnOrderUpdate strategy

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Call ATM Strategy on an automated strategy to control position jsengxx NinjaTrader Programming 7 May 31st, 2016 05:51 PM
Utility To Transpose Optimized Strategy Values From Excel Output to Actual Strategy mercuryfx NinjaTrader 5 April 7th, 2012 04:59 PM
Ninjatrader7 ATM Strategy combine with Strategy Wizard Ninja Script schuster21 NinjaTrader Programming 4 July 4th, 2011 05:39 PM
Ninja Strategy multi-timeframe issue/Strategy to indicator nw123 NinjaTrader Programming 2 December 20th, 2009 07:24 PM


All times are GMT -4. The time now is 04:56 PM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts
Page generated 2017-12-13 in 0.14 seconds with 20 queries on phoenix via your IP 54.90.92.204