Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
stop loss & profit target order settings with the unamanaged approach?
I am developing a new strategy with the unmanaged approach. When I enter a long/short position, I don't know how to exit this position, then set a stop loss order and a profit target order because everytime I run my script below, NinjaTrader doesn't respond.
Here is the script :
public class SStrategy : Strategy
{
#region Variables
// User defined variables (add any user defined variables below)
private int quantity = 1;
private int target = 30;
/// <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;
Unmanaged = true;
// TraceOrders = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Buying condition
if (Close[0] < Bollinger(2, 14).Lower[0])
{
longOrder = SubmitOrder(0,OrderAction.Buy,OrderType.Market,quantity,0,0,"","ELong");
// SubmitOrder(0,OrderAction.Sell,OrderType.StopLimit,quantity,0,0,"","XLong");
}
// Resets the longOrder and shortOrder objects to null after the order has been filled
// if (execution.Order.OrderState != OrderState.PartFilled)
// {
// longOrder = null;
// shortOrder = null;
// }
// Reset our stop order and target orders' IOrder objects after our position is closed.
if ((stopLossOrder != null && stopLossOrder == execution.Order) || (profitTargetOrder != null && profitTargetOrder == execution.Order))
{
if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled)
{
stopLossOrder = null;
profitTargetOrder = null;
}
}
}
#region Properties
[Description("Quantity of the underlying asset")]
[GridCategory("Parameters")]
public int Quantity
{
get { return quantity; }
set { quantity = Math.Max(1, value); }
}
[Description("Target of this position")]
[GridCategory("Parameters")]
public int Target
{
get { return target; }
set { target = Math.Max(1, value); }
}
#endregion
}
Could anyone help me, please?
Thank you!
PS: Excuse my English.
Can you help answer these questions from other members on NexusFi?
Hi stevien - sorry I'm not familiar enough with NT to answer your specific question, but I would have thought that the platform must allow for some sort or bracket order where you automatically set a stop loss and a target?
I may be wrong but shouldn't use to be using ChangeOrder() instead of SubmitOrder() when trying to set the stop loss/breakeven in the Unmanaged approach as mentioned here?
Regardless of OrderType, you always use SubmitOrder() at least one time. You
always want to save the reference to the IOrder object returned by SubmitOrder.
Then, if you need to update the order later (aka, move the stop, to achieve either
a BreakEven or Trailing effect) you then call ChangeOrder() and pass the saved
reference from SubmitOrder() as the first argument.
So, when entering the stop loss order, you first use SubmitOrder. You save that IOrder
reference returned by SubmitOrder, and use it with ChangeOrder later ... if you need to.
In other words, you would not call ChangeOrder unless you first had an IOrder reference
returned to you from SubmitOrder.
Hey Stevien I'm having the EXACT same issue. I'm assuming you now know how to close an open order using Unmanaged, SubmitOrder. How did you go about closing open orders?