Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
type of SetProfitTarget
Collapse
X
-
type of SetProfitTarget
Hi, I'm toying with passing some order methods to an externl class and the simpler ones, like EnterLong(), work out okay. However, I'm stuck with passing SetProfitTarget() and SetStopLoss() methods as I can't determine their return types. It's neither IOrder, not bool, nor void, so what is it then? The docs are silent about this...Tags: None
-
They have no return type. If you wish max control over such things like profit targets and stop losses we recommend you to use ExitLongStop() or ExitLongLimit() as an IOrder via the OnOrderUpdate(), OnExecution() etc methods.
Please see this reference sample: http://www.ninjatrader-support.com/v...ead.php?t=7499
This reference may be of some use too: http://www.ninjatrader-support.com/v...ead.php?t=5790Josh P.NinjaTrader Customer Service
-
For some reason it doesn't work:
protected override void OnBarUpdate() {
.....
string name = "Buy" + CurrentBar;
IOrder order = EnterLong( 1, name );
ExitLongLimit( 1, Close[0] + 2, name + "_lmt" , name );
// I also tried ExitLongLimit( 1, Close[0] + 2, name + "_lmt" , order.Name );
}
Is this because I am using it in OnBarUpdate() ?
Comment
-
What part doesn't work? Please provide the error message from the Control Center logs and the TraceOrders output.
It is recommended you create the IOrder object in the variables section and set it to null as demonstrated in the reference sample. Also, Close[0] + 2 is not the close price and 2 ticks its the close price and 2. You may want to use Close[0] + 2 * TickSize if you were intending it to be ticks.Josh P.NinjaTrader Customer Service
Comment
-
Hi Josh, thanks for the hint about the price values, turned out that it was setup properly. What goes wrong is the limit order is not being placed after position has been entered.
I've declared the IOrder variable as a class member and re-run the strategy with traceOrder enabled. Here's the output for the first two trades in a session (basically, all the error messages I am getting after the second error are the same as the second one, the first one being different):
7/10/2008 10:31:00 AM Entered internal PlaceOrder() method at 7/10/2008
10:31:00 AM: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Buy0' FromEntrySignal=''
7/10/2008 10:31:00 AM Entered internal PlaceOrder() method at 7/10/2008 10:31:00 AM: Action=Sell OrderType=Limit Quantity=1 LimitPrice=664.5 StopPrice=0 SignalName='Buy0_Lmt' FromEntrySignal='Buy0'
7/10/2008 10:31:00 AM Ignored PlaceOrder() method: Action=Sell OrderType=Limit Quantity=1 LimitPrice=664.5 StopPrice=0 SignalName='Buy0_Lmt' FromEntrySignal='Buy0' Reason='This was an exit order but no position exists to exit'
7/10/2008 10:32:00 AM Entered internal PlaceOrder() method at 7/10/2008 10:32:00 AM: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Buy1' FromEntrySignal=''
7/10/2008 10:32:00 AM Entered internal PlaceOrder() method at 7/10/2008 10:32:00 AM: Action=Sell OrderType=Limit Quantity=1 LimitPrice=665.4 StopPrice=0 SignalName='Buy1_Lmt' FromEntrySignal='Buy1'
7/10/2008 10:32:00 AM Ignored PlaceOrder() method at 7/10/2008 10:32:00 AM: Action=Sell OrderType=Limit Quantity=1 LimitPrice=665.4 StopPrice=0 SignalName='Buy1_Lmt' FromEntrySignal='Buy1' Reason='SignalName does not have a matching FromEntrySignal to exit'
.....................
These traces are the same when I use "name" or "order.Name" as the fromSignalName variable.Last edited by billitin; 07-10-2008, 10:07 PM.
Comment
-
This is the source of your problems. 'This was an exit order but no position exists to exit'
You need to now go find where your strategy is exiting your position beforehand.
In general you would simply just do this as your lines of pseudocode:
condition 1
EnterLong()
if (Position.MarketPosition == MarketPosition.Long)
ExitLongLimit()Josh P.NinjaTrader Customer Service
Comment
-
I've tried wrapping up ExitLongLimit() in the condition for open market position and indeed it works. However, a check for an existing position means that I can't attach a stop/limit to an order when it's entered all at the same time and I'll have to do such attachment outside of onBarUpdate(). Then this is inconvenient considering I may be entering several different long positions on one bar close. How would I create a bracket order in one go?
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by bortz, 11-06-2023, 08:04 AM
|
47 responses
1,606 views
0 likes
|
Last Post
by aligator
Today, 07:22 PM
|
||
Started by jaybedreamin, Today, 05:56 PM
|
0 responses
8 views
0 likes
|
Last Post
by jaybedreamin
Today, 05:56 PM
|
||
Started by DJ888, 04-16-2024, 06:09 PM
|
6 responses
18 views
0 likes
|
Last Post
by DJ888
Today, 05:12 PM
|
||
Started by Jon17, Today, 04:33 PM
|
0 responses
4 views
0 likes
|
Last Post
by Jon17
Today, 04:33 PM
|
||
Started by Javierw.ok, Today, 04:12 PM
|
0 responses
13 views
0 likes
|
Last Post
by Javierw.ok
Today, 04:12 PM
|
Comment