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:	132
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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    57 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    78 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    41 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    101 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    61 views
    0 likes
    Last Post PaulMohn  
    Working...
    X