Im trying to create a StopOrder and create his Profit Target on an unmanaged approach.
But gives me this errors:
Strategy 'PruebaOnOrderFill/206666250' submitted an order that generated the following error 'Unable to submit order'. Strategy has sent cancel requests, attempted to close the position and terminated itself.
Order can't be submitted: The OCO ID 'OcoGroup1' cannot be reused. Please use a new OCO ID.
Please find attached that errors.
Here is my 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
//This namespace holds Strategies in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Strategies
{
public class PruebaOnOrderFill : Strategy
{
public bool tradeCreado;
int contador;
private Order entryOrder = null;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "PruebaOnOrderFill";
Calculate = Calculate.OnEachTick;
EntriesPerDirection = 5;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = false;
ExitOnSessionCloseSeconds = 0;
IsFillLimitOnTouch = true;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 0;
StartBehavior = StartBehavior.WaitUntilFlat;
TimeInForce = TimeInForce.Gtc;
TraceOrders = true;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
BarsRequiredToTrade = 0;
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;
IsUnmanaged=true;
tradeCreado=false;
contador=1;
}
else if (State == State.Configure)
{
}
}
protected override void OnBarUpdate()
{
contador++;
if(contador>20 && !tradeCreado)
{
SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.StopMarket, 10000, 0,Close[0]-0.0030,"OcoGroup","EntryName");
tradeCreado=true;
Print("PrecioEntrada: "+ (Close[0]-00.0030));
}
}
protected override void OnExecutionUpdate(Cbi.Execution execution, string executionId, double price, int quantity,
Cbi.MarketPosition marketPosition, string orderId, DateTime time)
{
entryOrder= execution.Order;
if (entryOrder != null && execution.Order == entryOrder)
{
SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.Limit, 10000, Close[0]-0.0030, 0, "OcoGroup1", "profit target");
Print("TargetsFilled!");
}
}
}
}
Please, could you help me??
Thank you!
Comment