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

Limit orders..

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

    Limit orders..

    Hi,

    I have a strategy where primary dataseries is 1 minute and I added secondary data series of 1 tick to improve granularity.

    Code:
    				AddDataSeries(Data.BarsPeriodType.Tick, 1);
    I am calculating my entry signal based on 1 minute data series, and I am submitting my order on 1 tick tick data series.

    Code:
    				if(XYZ[0] < Entry)
    				{
    				EnterLongLimit(1,false,Convert.ToInt32(DefaultQuantity), GetCurrentBid(0), @"b1");
    				}
    Strategy Analyzer (SA) is givning me good results but I disagree with the results because of the following:

    As you can see, I'm sending my limit order to GetCurrentBid. However, after reviewing many trades during my SA, and comparing those trades with bid/ask/last TICK data, it seems SA is actually giving me fills on "last tick" price rather than bid. Is this normal behaviour? Will I need to add additional data series for bid/ask?? And then submit my orders on those?

    Code:
    				AddDataSeries("NZDUSD", Data.BarsPeriodType.Tick, 1, Data.MarketDataType.Ask);
    				AddDataSeries("NZDUSD", Data.BarsPeriodType.Tick, 1, Data.MarketDataType.Bid);
    The above behaviour is during SA. Now onto playback:

    However, when I run the strategy on playback, my orders indeed are being sent to bid/ask. Even though, I have COBC=true, my bid/ask limit orders are changing as each incoming tick data comes and the bid/ask changes respectively, which makes sense, since I am sending my order on the secondary data series of tick data. But please help me wrap my head on this:

    If I submit my order at bid, say 100, and my bid limit price is changing with each incoming tick data, how can I ever possibly get a fill? The only scenario I can think of is that the bid/ask spread would have to converge in order for me to get a fill? Which is basically impossible, so how is NT actually giving me fills? In other words, since I submitted my original limit order at 100, the next tick, the bid changed to 99, hence my limit order also changed to 99, and so on, given that I am trying to BUY this security (forex), my broker will NEVER give me a fill to buy unless ask = limit order, and my limit order should theoretically never equal ask because my limit order (in the scenario described in this post) is derived from each incoming bid tick data! So again, how is NT actually giving me fills?

    I originally had thought that when I submit a limit order at price X, it does not get changed as new data is comes in, but since I've added 1 tick data to reduce discrepancies between real time execution and back-test execution, now I'm left with this issue.

    I've read all the guides, spent the entire day going through posts after posts and I'm basically not sure what is going on anymore. At each step of developing a strategy in NT results in some mysterious behaviour.

    Sorry for always typing up long posts: in short:

    Code:
    	if(XYZ[0] < Entry)
    				{
    				EnterLongLimit(1,false,Convert.ToInt32(DefaultQuantity), GetCurrentBid(0), @"b1");
    				}
    1) why is the above giving me fills at "last traded tick price" (in real life this would never happen bc forex orders are executed on bid/ask) rather than my limit order of getcurrentbid price/
    2) and realistically speaking, I cannot imagine any scenario where i'd get a fill for the situation described above for the market replay.
    Last edited by staycool3_a; 12-18-2017, 07:58 PM.

    #2
    i think the big problem with NT is that it's designed for equities rather than forex.

    In equities, suppose you have a order at bid to purchase, and the "last" trade was a market order to sell (it hit bid).. in equities you may get a partial fill as you might be the only person who is "providing" the bid at that moment.

    In forex, however, this is NOT how it works. In forex, orders are routed to your broker, who gives you a bid/ask and they fill those orders only at bid/ask. for example, say you want to BUY, and send a limit order, your order will ONLY be executed if the ASK equals your limit order.

    So tying this back to my original post, when in NT you design a system and backtest it, even though I am sending a LIMIT order at bid, NT during backtest is executing that order at LAST.. and assuming that it will get filled, even though it never would based on bid/ask spread. Perhaps this is something you guys need to fix.. unless I am missing something.

    another issue, forget limit orders limitations, even a market order in NT8 for a forex pair will get executed at "LAST traded price" rather than Ask price.... even though in real life, a market buy order in forex will always be filled at ASK. And in order to emulate a realistic forex environment for market orders, i suppose one would have to add additional bid/ask data series to you strategies and use those to execute your orders....

    for example:

    Code:
    				AddDataSeries("NZDUSD", Data.BarsPeriodType.Tick, 1, Data.MarketDataType.Ask);
    				AddDataSeries("NZDUSD", Data.BarsPeriodType.Tick, 1, Data.MarketDataType.Bid);
    buy at ask (aka market order in forex):

    Code:
    				if(XYZ[0] < Entry)
    				{
    				EnterLong([B]1[/B],Convert.ToInt32(DefaultQuantity),  @"b1");
    				}
    short at market (aka sell bid):

    Code:
    if(XYZ[0] > Exit)	
    			{
    				EnterShort(2,Convert.ToInt32(DefaultQuantity),  @"s1");
    			}
    I know i've said a lot in this thread but i'd appreciate it if someone can actually go through it and provide a good feedback
    Last edited by staycool3_a; 12-18-2017, 08:23 PM.

    Comment


      #3
      Hello calhawk01,

      Thank you for your note.

      Yes, if you wanted to submit an order to the current bid price historically then you’d need to add this series. It would be expected that if an order was filled, it was filled at the tick price, as that was the price that actually traded. If you were trading back months of an illiquid contract and worked an order at the bid, you should not expect to get filled unless the price actually traded at the bid or through your bid.

      Using playback consists of live real time data, which includes an order book, which would contain both bid and asks as well as volume. The strategy analyzer consists only of the data you pass it, in this case just a tick series. Playback would provide the most accurate backtesting results.

      Please read more about playback at the following link,


      In the scenario where you submit your order at the current bid at 100, I suggest you add prints to the script for both the current bid as well as the current tick. Since you are not passing a bid series, and you are getting filled, its likely current bid is defaulting to the tick series but I encourage you to test this on your end.

      I’ve provided a link to a youtube video which covers an example of using prints to understand behavior:
      Dive into manipulating C# code from within an unlocked NinjaScript strategy using the NinjaScript Editor.NinjaTrader 7 is an award winning end to end online ...


      If you do not pass the script a bid or ask series, but your script tries to call this information, it would be expected it would have no idea what the current bid or ask is. I would encourage you to add these two data series and test the behavior.

      You added a secondary tick series to your script, how are you controlling which bar series your conditions are being ran on? For example please see the following sample, and its use of BarsInProgress. Does your script have such logic?

      You can submit orders to different Bars objects. This allows you the flexibility of submitting orders to different timeframes. Like in live trading, taking entry conditions from a 5min chart means executing your order as soon as possible instead of waiting until the next 5min bar starts building. You can achieve this by



      I look forward to your reply.
      Alan P.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by geddyisodin, Today, 05:20 AM
      5 responses
      32 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by bmartz, Today, 09:30 AM
      2 responses
      12 views
      0 likes
      Last Post bltdavid  
      Started by f.saeidi, Today, 11:02 AM
      1 response
      4 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by geotrades1, Today, 10:02 AM
      4 responses
      12 views
      0 likes
      Last Post geotrades1  
      Started by rajendrasubedi2023, Today, 09:50 AM
      3 responses
      16 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Working...
      X