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:	108
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 Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    559 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    546 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X