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:
-
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 FrancisMorro, Today, 03:24 AM
|
0 responses
1 view
0 likes
|
Last Post
by FrancisMorro
Today, 03:24 AM
|
||
Net Change
by Segwin
Started by Segwin, 05-07-2018, 02:15 PM
|
10 responses
1,770 views
0 likes
|
Last Post
by Leafcutter
Today, 03:01 AM
|
||
Change colour of Stop market and limit orders to red and green via indicator script
by Rapine Heihei
Started by Rapine Heihei, 04-23-2024, 07:51 PM
|
2 responses
31 views
0 likes
|
Last Post
by Max238
Today, 02:25 AM
|
||
Started by Shansen, 08-30-2019, 10:18 PM
|
24 responses
944 views
0 likes
|
Last Post
by spwizard
Today, 01:29 AM
|
||
Started by Max238, Today, 01:28 AM
|
0 responses
11 views
0 likes
|
Last Post
by Max238
Today, 01:28 AM
|
Leave a comment: