Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

"Correct" or "proper" way to incorporate spread into [forex] strategies

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

    "Correct" or "proper" way to incorporate spread into [forex] strategies

    Good afternoon,

    While I do have historical bid and ask from my data provider, I understand that by default, NT7 uses the "Last" data when backtesting. To make my backtest more realistic, I would have to always buy at the ask price and sell at the bid price. Well, I think doing this may be complicated.

    First, I would have to add a few data streams, e.g.
    Code:
    Add(Symbol1, PeriodType.Minute, 1, MarketDataType.Ask);
    Add(Symbol1, PeriodType.Minute, 1, MarketDataType.Bid);
    Second, I would have to open the trade from the bid or ask, depending on whether I'm selling or buying, respectively.

    Third, I don't think I'd be able to use SetProfitTarget and SetStopLoss properly, as they probably use only the primary DataSeries (please do correct me if I'm wrong). So if I used the ask stream to get long, now I'd need the bid data series to sell (close the position).

    Finally, if I run my strategy for multiple instruments, these complications increase tenfold. I don't want to hardcode the instrument name into the strategy.

    Should I use the "Unmanaged approach"? Am I unnecessarily complicating things here? Why doesn't NT7 handle the bid/ask issue internally? I understand that not all data providers support historical bid/ask - but the fact is that some do.

    Thanks in advance for your help!

    #2
    Hello Shahar,

    Thank you for your first post and welcome to the NinjaTrader forums!

    This approach of adding two additional instruments for the bid and ask market data is the most straight forward work-around for accessing this data in a backtesting environment.

    Regarding trading from the ask, bid and SetStopLoss() and SetProfitTarget(), they will work on the primary series but it should not be too unwieldy to handle. You can set them with your second and third series' data with Closes[][] or by setting them in a BarsInProgress check for the appropriate series. The same goes for order entry, you can pass the 2nd or 3rd data series' current close value for ask/bid.

    You could use the unmanaged order approach, but with some minor work on setting your order entries, stops and profit targets, you can achieve what you are trying to do. This is assuming you want to only work with one currency pair at a time - EUR/USD, with EUR/USD bid and EUR/USD ask added for example.

    If you do not want to add 2 data series for back testing ask and bid, testing with market replay would be a better alternative for this as level 2 data will be available if recorded/downloaded, with only 1 instrument in your strategy. You can set the replay speed to 500x to quickly test some days worth of data tick by tick.

    Please let me know if I can assist you any further.
    DexterNinjaTrader Customer Service

    Comment


      #3
      Thank you for your quick reply.

      It is really disappointing that NT7 does not have an option to "automatically" buy at ask and sell at bid, when historical data are available. Please consider incorporating this feature in future releases.

      I understand how to enter with a secondary series, as EnterLong and EnterShort, for example, have a barsInProgressIndex parameter. However, SetStopLoss and SetProfitTarget do not have this parameter. How exactly do I make sure that a short position is closed when SetProfitTarget/SetStopLoss reach the ask price, rather than the bid price?

      Would something like
      Code:
      if (BarsInProgress == 2)
                      {
                          stoploss = Close[0] + (stopLossDistance);
                          takeProfit = Close[0] - (takeProfitDistance);
                          SetStopLoss("Sell", CalculationMode.Price, stoploss, false);
                          SetProfitTarget("Sell", CalculationMode.Price, takeProfit);                
                      }
      ensure these are triggered by the ask price?

      Where would this then fit in the code, assuming you entered the short position on the bid stream? I assume you would first have to check your MarketPosition - this gets ever so complicated for the simplest of strategies.

      Again, please seriously consider having a built-in feature for this in the next release.
      Thanks!
      Last edited by Shahar; 05-10-2011, 03:19 PM. Reason: Changed signal name

      Comment


        #4
        Hi Shahar,

        The code you posted would have the stop loss and profit target set based on the 3rd series price, that is correct. The managed order approach will automatically submit them once you're in a position.

        If you want them to be based off the price but not dynamically update each tick/bar, you could set them in OnOrderUpdate() or OnExecution() after getting a fill. This would submit them at your default, then update them to your desired price based on the ask/bid immediately after.

        SetProfitTarget(), SetStopLoss() and SetTrailingStop() apply to all series in strategy. If you would like to manage exits on a finer per series basis, ExitShortStop(), ExitShort() etc can do this with a bars in progress index parameter.

        Please let me know if I can assist you any further.
        DexterNinjaTrader Customer Service

        Comment


          #5
          Shahar, did you get it working?

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by funk10101, Today, 09:43 PM
          0 responses
          6 views
          0 likes
          Last Post funk10101  
          Started by pkefal, 04-11-2024, 07:39 AM
          11 responses
          37 views
          0 likes
          Last Post jeronymite  
          Started by bill2023, Yesterday, 08:51 AM
          8 responses
          44 views
          0 likes
          Last Post bill2023  
          Started by yertle, Today, 08:38 AM
          6 responses
          26 views
          0 likes
          Last Post ryjoga
          by ryjoga
           
          Started by algospoke, Yesterday, 06:40 PM
          2 responses
          24 views
          0 likes
          Last Post algospoke  
          Working...
          X