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

Adding the spread

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

    Adding the spread

    Forex Price data is driven by the bid price, so I am accustomed to adding-on the spread for any buy orders (short exits/long entries) and have code in my strategy to do this.

    Am I actually required to do this, or is it handled under-the-hood for me by Ninjatrader? Just wanted to make sure that I am not adding-on double the spread.

    Can anyone advise?

    Thanks,

    Kevin.

    #2
    Hello reach4thelasers, and thank you for your question.

    While I wasn't quite sure how to answer, as I did not know how in your strategy logic you were using the spread or what was meant by adding it in, I did create a strategy which takes the ask, bid, and "last" price feeds coming in, printed out all their OHLC values, and printed out the spread as each price comes in. What this reveals as far as how Ninja operates :

    • The last and bid prices represent the same feed
    • The spread, therefore, for the last price, is the spread at the time the bid price is placed

    This script should contain enough information for you to read, manipulate, and display spread data however you as the developer desire. Please let us know if there are any other ways we can help.
    Attached Files
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Thanks For the sample Jessica. What I mean is that say I place a short entry at £1.5000 and aim to exit with a target of 50 pips - so £1.4950 and a stop of 10 pips so £1.5010.

      Forex is driven by the bid price so I've worked out those prices from the bid chart either by drawing a line or using an indicator value driven by the bid prices. The exit orders from a short are buy orders so will get filled at the Ask price.

      Say my spread is 3 pips. So this means unless the spread is taken into consideration my stop gets hit when the ask price reaches £1.5010. The ask price is 3 pips higher than the bid. So if I enter into my short position at a bid price of 1.5000 and exit at the ask price of £1.5010 then my distance to the stop is actually only 7 pips. Since the ask price is 3 pips higher than the bid due to the spread.

      In manual trading I am accustomed to adding on the spread myself to take this into account.

      I'd like to know if Ninjatrader does it for me or if I still need to add the spread in my strategy.

      My spreads aren't that high in actual fact but I just want to make sure my risk is accurately managed.

      Comment


        #4
        Thank you for this clarification.

        If you are using SetProfitTarget and SetStopLoss to place profit target and stop loss orders, you are correct as to how they will work. However, if you are using Exit methods for your profit target and stop loss, then you have some more options. To gain full control over which of the two prices you are reading, and which of the two prices you are placing orders on, you can create a multi-series strategy similar to the provided example, and use the entry and exit method overrides which take a BarsInProgress index. This would allow you to set up your exit orders to track and place orders using the ask price alone, and similarly to use the bid exclusively for your entry orders.

        Here is an example which sets up a profit target and stop loss order 3 pips away.

        Code:
        [FONT=Courier New]
        int bidSeriesIndex = 1, askSeriesIndex = 2;
        bool isLiveUntilCanceled = false;
        EnterShort(bidSeriesIndex, DefaultQuantity, "");
        ExitShortMIT(askSeriesIndex, isLiveUntilCancelled, DefaultQuantity, Closes[askSeriesIndex][0] - TickSize * 3, "", "");
        ExitShortStopMarket(askSeriesIndex, isLiveUntilCancelled, DefaultQuantity, Closes[askSeriesIndex][0] + TickSize * 3, "", "");[/FONT]
        Setting up your strategy this way, Ninja would then automatically take spread into account.
        Jessica P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by traderqz, Today, 12:06 AM
        10 responses
        18 views
        0 likes
        Last Post traderqz  
        Started by algospoke, 04-17-2024, 06:40 PM
        5 responses
        46 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by arvidvanstaey, Today, 02:19 PM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_Zachary  
        Started by mmckinnm, Today, 01:34 PM
        3 responses
        5 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by f.saeidi, Today, 01:32 PM
        2 responses
        9 views
        0 likes
        Last Post f.saeidi  
        Working...
        X