Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unable to change order error

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Unable to change order error

    I'm running a ParabolicStop Strategy I made with the Strategy Builder and I keep getting errors during live trading when the Strategy tries to set a stop position on the wrong side. In an attempt to just close my position when this occurs but keep the strategy running I coded the below by unlocking the strategy and adding code found in the help files; will this work?

    I haven't been able to run this using the Playback Connection to test it out but would like to have it ironed out by Monday morning. Thanks for looking and any advice you can give.




    public class EMACrossOverParabolicStop : Strategy
    {
    private EMA EMA1;
    private SMA SMA1;
    private Order stopLossOrder = null;
    private Order entryOrder = null;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "EMACrossOverParabolicStop";
    Calculate = Calculate.OnBarClose;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.WaitUntilFlat;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.IgnoreAllErrors; //RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 20;

    // Disable this property for performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = true;
    }
    else if (State == State.Configure)
    {
    }
    else if (State == State.DataLoaded)
    {
    EMA1 = EMA(Close, 10);
    SMA1 = SMA(Close, 30);
    EMA1.Plots[0].Brush = Brushes.SeaShell;
    SMA1.Plots[0].Brush = Brushes.Yellow;
    AddChartIndicator(EMA1);
    AddChartIndicator(SMA1);
    SetParabolicStop(CalculationMode.Ticks, 30);
    }
    }

    protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice,
    OrderState orderState, DateTime time, ErrorCode error, string nativeError)
    {
    // Assign stopLossOrder in OnOrderUpdate() to ensure the assignment occurs when expected.
    // This is more reliable than assigning Order objects in OnBarUpdate,
    // as the assignment is not guaranteed to be complete if it is referenced immediately after submitting
    if (order.Name == "myStopLoss" && orderState == OrderState.Filled)
    stopLossOrder = order;

    if (stopLossOrder != null && stopLossOrder == order)
    {
    // Rejection handling
    if (order.OrderState == OrderState.Rejected)
    {
    ExitLong(); // Stop loss order was rejected !!!!
    ExitShort(); // Do something about it here
    }
    }
    }



    Tags: None


Latest Posts

Collapse

Topics Statistics Last Post
Started by NullPointStrategies, Yesterday, 05:17 AM
0 responses
54 views
0 likes
Last Post NullPointStrategies  
Started by argusthome, 03-08-2026, 10:06 AM
0 responses
130 views
0 likes
Last Post argusthome  
Started by NabilKhattabi, 03-06-2026, 11:18 AM
0 responses
72 views
0 likes
Last Post NabilKhattabi  
Started by Deep42, 03-06-2026, 12:28 AM
0 responses
44 views
0 likes
Last Post Deep42
by Deep42
 
Started by TheRealMorford, 03-05-2026, 06:15 PM
0 responses
49 views
0 likes
Last Post TheRealMorford  
Working...
X