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
EnterLongStop And EnterShortStop Together
Collapse
X
-
Hello Steve,
I've coded the script to only place orders in real-time because its easier to demonstrate that way.
(With the historical orders we wouldn't see the cancelled orders on a chart, so it wouldn't be clear whats going on)
OCO works historically too. You would just place the orders in OnBarUpdate.
An order can be part filled. If its filled in parts, each part fill before being fully filled would cause the order state to be OrderState.PartFilled until the order is fully filled and then it will be OrderState.Filled.
- Likes 1
-
Thanks, Chelsea. That's the confirmation I needed.
Couple of questions about the example and the unmanaged approach:
1) The example says it is not coded to work historically. I would like to be able to backtest and I'll only be working with minute bars or larger. Is there anything keeping me from testing unmanaged bracketed orders historically for my scenario?
2) OrderStatus.PartFilled. Is this an interim status before "Filled" or is it always a final status for the order indicating that a portion of the quantity was filled and there will be no additional executions associated with this order?
Thanks,
Steve
Leave a comment:
-
Hello Steve,
Bracketing working opposing entry orders with OCO is too advanced for the managed approach.
The unmanaged approach would need to be used.
Below is a link to an example.
https://ninjatrader.com/support/foru...926#post486926
Leave a comment:
-
EnterLongStop And EnterShortStop Together
I'm wanting to code a strategy that submits both an EnterLongStopMarket and an EnterShortStopMarket at the same time.
If price goes up enough I get stopped in long. If price goes down enough I get stopped in short.
However, it appears that the internal order handling rules are preventing this.
This page seems to discuss this under "Internal Order Handling Rules to Reduce Unwanted Positions."I've included my code sample below.
Is it possible to achieve what I'm wanting to do with a managed approach or does it require the unmanaged approach? Is there a way to tie the orders together ala OCO?
I'm testing on DAY bars, though I'm not sure that matters.
Thanks,
Steve
Code:#region Using declarations using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Input; using System.Windows.Media; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Gui; using NinjaTrader.Gui.Chart; using NinjaTrader.Gui.SuperDom; using NinjaTrader.Gui.Tools; using NinjaTrader.Data; using NinjaTrader.NinjaScript; using NinjaTrader.Core.FloatingPoint; using NinjaTrader.NinjaScript.Indicators; using NinjaTrader.NinjaScript.DrawingTools; #endregion Using declarations //This namespace holds Strategies in this folder and is required. Do not change it. namespace NinjaTrader.NinjaScript.Strategies.Barz { public class TestEntryStopsStrategy : Strategy { protected override void OnBarUpdate() { if (CurrentBar < BarsRequiredToTrade) { return; } if (Position.MarketPosition == MarketPosition.Flat) { if (Range()[1] > Range()[2] && ADX(15)[0] > 20) { EnterLongStopMarket(MAX(High, 10)[0]); EnterShortStopMarket(MIN(Low, 10)[0]); } } else { if (BarsSinceEntryExecution() > 10) { ExitLong(); ExitShort(); } } } protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Test simultaneous EnterLongStopMarket and EnterShortStopMarket."; Name = "Test - Entry Stops"; Calculate = Calculate.OnBarClose; EntriesPerDirection = 10; EntryHandling = EntryHandling.AllEntries; IsExitOnSessionCloseStrategy = false; IsFillLimitOnTouch = false; MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix; OrderFillResolution = OrderFillResolution.Standard; Slippage = 0; StartBehavior = StartBehavior.WaitUntilFlat; TimeInForce = TimeInForce.Gtc; TraceOrders = false; RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose; StopTargetHandling = StopTargetHandling.PerEntryExecution; BarsRequiredToTrade = 50; // Disable this property for performance gains in Strategy Analyzer optimizations // See the Help Guide for additional information IsInstantiatedOnEachOptimizationIteration = true; TraceOrders = true; } else if (State == State.Configure) { } } } }
Last edited by Steve L; 06-01-2019, 02:27 PM.Tags: None
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by HalTech, Today, 02:11 PM
|
2 responses
11 views
0 likes
|
Last Post
![]()
by HalTech
Today, 03:09 PM
|
||
Started by Gianpiero, Today, 01:41 PM
|
1 response
9 views
0 likes
|
Last Post
|
||
Started by Vern10, Today, 10:51 AM
|
3 responses
19 views
0 likes
|
Last Post
|
||
Started by josh18955, Today, 11:16 AM
|
1 response
14 views
0 likes
|
Last Post
![]() |
||
Started by Malexander2023, Today, 04:40 AM
|
1 response
14 views
0 likes
|
Last Post
|
Leave a comment: