protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 2)
return;
// Set 1
if ((Close[0] > Close[1])
&& (Position.MarketPosition == MarketPosition.Flat)
&& (CrossAbove(Close, EMA1, 1))
&& (ATR1[0] > ATRLength))
{
Targetprice = (ATR1[0] / 2) ; // store a target price to exit
Stopprice = (Low[2] - 0.25) ; // store a stop price to exit
SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.Market, 1, 0, 0, "oco1", "emascalp"); // entr long if the criteria is met
}
if ((Position.MarketPosition == MarketPosition.Long)) // if long position established
{
SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.Limit, 1, Targetprice, 0, "oco1", "emascalp"); //submit oco profit booking order
SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.StopMarket, 1, Stopprice, 0, "oco1", "emascalp");// submit oco loss booking order
}
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Help with OCO order in a strategy
Collapse
X
-
Help with OCO order in a strategy
Plz help me correct this code. It compiles but unable to enable the strategy. My goals is to enter long based on some criteria and as soon i am long, want to place OCO order to book profit or loss.
Code:Tags: None
-
Hello percy3687,
Thank you for your post.
If your strategy is getting automatically disabled, what is the full error being shown in the Log tab of the Control Center?
Please note that OCO strings should not be reused. Use unique strings for each OCO group, and reset after orders in that group are filled/canceled.
Below is also a link to a sample script which demonstrates submitting orders using the Unmanaged Approach:
Hi, Is there a collection of sample/reference strategies that illustrates how to use the unmanaged order approach in advanced scenarios which also illustrates all the things one would need to be concerned about vs using the managed approach? Is there something like that you can point me to? Thanks, FaaastEddy
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Yesterday, 05:17 AM
|
0 responses
61 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
134 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
75 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
45 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
50 views
0 likes
|
Last Post
|
Comment