Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Reference Entry Price
Collapse
X
-
Reference Entry Price
I am working on creating a pyramid of orders that trigger a entry order based on a set of conditions. Say I want to enter 10 additional shares upon the stock close >= (1.05 * entry price). So buy 10 shares when the price is 5% greater than the original entry price. What methods and properties would I use? Obviously the if function. Thank you.Tags: None
-
Hi cfree5119,
You'll need the execution price of the order, which is available with IExecution interface. You access this from OnExecution() handler.
Scaling behavior will depend on these two properties as well as the signal names you provide for your entries:
EntryHandling and EntriesPerDirectionRyan M.NinjaTrader Customer Service
-
You're welcome, cfree5119. This sample is a good one for working with those advanced order handlers like OnExecution() :
The OnOrderUpdate() and OnExecution() methods are reserved for experienced programmers. Instead of using Set() methods to submit stop-loss and profit target orders, you can submit and update them manually through the use of IOrder and IExecution objects in the OnOrderUpdate() and OnExecution() methods. The OnOrderUpdate()Ryan M.NinjaTrader Customer Service
Comment
-
To get the execution price of a specific order requires IOrder objects and those advanced handlers. If this part is critical to your idea, that's the only approach for it.
If you have limited time or programming experience but want to get something developed for you, please consider working with our 3rd party NinjaScript consultants.
Ryan M.NinjaTrader Customer Service
Comment
-
If its okay, I may have some questions along the way trying to develop what I am looking at. It is relatively simple what I am trying to do, just very foreign to me. For instance,
is defined under the method OnBarUpdate(). However, I would like to use it under the OnExecution handler but it is telling me it is does not exist in current context. Do I need to define it again? I am using it as such. See below.Code:double trailingLongStopATR = Close[0] - (NAtr * n);
Code:stopOrder1 = SetStopLoss("LongPosition1", CalculationMode.Price, trailingLongStopATR, false);
Comment
-
Sure, we're willing to help but won't be able to completely design and spec your strategy idea.
If you want variables available within the whole scope of the script, declare in variables region.
private double trailingStopATR;
Then access in code with the name of the variable;
trailingStopATR = Close[0] - (NAtr * n);Ryan M.NinjaTrader Customer Service
Comment
-
I added the mods you suggested. I declared it in the region of variables and then gave it its value OnBarUpdate(). Now I am receiving an error CS0029 'cannot implicitly convert void.'
This is the line of code I am receiving the error on under OnExecution().
stopOrder1 = SetStopLoss("LongPosition1", CalculationMode.Price, trailingLongStopATR, false);
Comment
-
SetStopLoss() and SetProfitTarget() cannot be assigned to an IOrder object. They're basically convenience methods for allowing the strategy to place these protective orders upon entry execution. If you want to monitor their properties, there's a separate technique for this detailed here:
To use IOrder for equivalent orders, you'd have to use the standard NinjaScript exit methods, like ExitLongStop(), ExitLongLimit(), etc. The technique for using these methods to place protective orders upon entry execution is shown in this sample:
The OnOrderUpdate() and OnExecution() methods are reserved for experienced programmers. Instead of using Set() methods to submit stop-loss and profit target orders, you can submit and update them manually through the use of IOrder and IExecution objects in the OnOrderUpdate() and OnExecution() methods. The OnOrderUpdate()Ryan M.NinjaTrader Customer Service
Comment
-
Another question Ryan. I have worked on getting my entries setup within the managed approach. However, I cannot get this line of code to fire. Do you see anything where I may have gone wrong? Tis under profitTaker1 variable.
Code:protected override void OnExecution(IExecution execution) { if (entryOrder1 != null && entryOrder1 == execution.Order) { if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0)) { // Stop-Loss stopOrder1 = ExitLongStop(0, true, execution.Order.Filled, execution.Order.AvgFillPrice - trailingStopATR, "MyStopLoss", "LongPosition1"); // Profit Taker if (Close[0] <= DonchianChannelATR(ExitPeriod).LowerLine[1]) profitTaker1 = ExitLong("MyProfitTaker", "LongPosition1");
Comment
-
Ryan M.NinjaTrader Customer Service
Comment
-
I am struggling to find where I went wrong and have put a couple of hours into it. On my previous code, the first of the two entries fires first and the other is left behind. Also, when I print the values of profitTaker stop price under OnExecution() I get only 5 values compared to the numerous values under OnBarUpdate(). I cannot make sense of the values output for longExitPrice under OnExecution(). Nothing showed on my trace orders in regard to my profitTaker because no order ever fired. See my full code attached. Maybe you could offer some insight since I am running into a dead end.Last edited by cfree5119; 02-27-2012, 07:57 AM.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
603 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
349 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
104 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
560 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
560 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|
Comment