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!
See more
See less

Partner 728x90

Collapse

ParabolicStop Error

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

    ParabolicStop 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
    }
    }
    }

Latest Posts

Collapse

Topics Statistics Last Post
Started by trilliantrader, 04-18-2024, 08:16 AM
4 responses
18 views
0 likes
Last Post trilliantrader  
Started by mgco4you, Today, 09:46 PM
1 response
7 views
0 likes
Last Post NinjaTrader_Manfred  
Started by wzgy0920, Today, 09:53 PM
0 responses
9 views
0 likes
Last Post wzgy0920  
Started by Rapine Heihei, Today, 08:19 PM
1 response
10 views
0 likes
Last Post NinjaTrader_Manfred  
Started by Rapine Heihei, Today, 08:25 PM
0 responses
10 views
0 likes
Last Post Rapine Heihei  
Working...
X