Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Price of pending orders

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

    Price of pending orders

    ​Hi, i am coding an indicator to place a buy stop order above the current price, but i get error.
    The price is calculated correctly.

    What am I missing?


    Code:
    if ( Close[1] > Open[1] )
                              longprice  = Close[1] + ((Close[1]-Open[1])/2) + (offset * TickSize);
                        else if ( Close[1] < Open[1] )
                              longprice  = Open[1] + ((Open[1]-Close[1])/2) + (offset * TickSize);
                        Print("Current ask  price : "+ GetCurrentAsk(0)+" , buy stop market should be placed at : "+longprice);
            TriggerCustomEvent(o =>
                    {
                        //Order stopOrder = null;
                
        
                        longOrder = myAccount.CreateOrder(Instrument,
                        OrderAction.Buy,
                        OrderType.StopMarket,
                        TimeInForce.Day,
                        nContractQuantity,
                        longprice,
                        0,
                        string.Empty,
                        "Entry",
                        null);
    
                        
                        NinjaTrader.NinjaScript.AtmStrategy.StartAtmStrategy(AtmStrategyName1, longOrder);
                        myAccount.Submit(new[] { longOrder });
                        }, null);
                    }​
    Click image for larger version

Name:	image.png
Views:	142
Size:	59.8 KB
ID:	1341220

    #2
    Hello gyilaoliver,

    You are supplying a price of 0 for the stop price.
    Also, you are supplying the longprice variable as the limit price, though this is a StopMarket order and not a limit order.

    myAccount.CreateOrder(Instrument, OrderAction.Buy, OrderType.StopMarket, TimeInForce.Day, nContractQuantity, longprice, 0, string.Empty, "Entry", null);​

    CreateOrder(Instrument instrument, OrderAction action, OrderType orderType, OrderEntry orderEntry, TimeInForce timeInForce, int quantity, double limitPrice, double stopPrice, string oco, string name, DateTime gtd, CustomOrder customOrder)
    Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CaptainJack, 05-29-2026, 05:09 AM
    0 responses
    236 views
    0 likes
    Last Post CaptainJack  
    Started by CaptainJack, 05-29-2026, 12:02 AM
    0 responses
    150 views
    0 likes
    Last Post CaptainJack  
    Started by charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    162 views
    1 like
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    243 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    198 views
    0 likes
    Last Post CarlTrading  
    Working...
    X