Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop out question Forex

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

    Stop out question Forex

    I am working a strategy in demo mode, but I am noticing some issues with trades being stopped out.

    As you will see in the image, I was in a short position and the stop was 1 tick above the top of the pink region. I was stopped out but the market never actually traded that level. I assume this had something to do with the bid/ask at the current time, possibly the ask went above the stop level?

    The stop loss in my code for the strategy is using a "SetStopLoss" with a calculation mode of that price level.

    Do I need to re-write the code to say something like only exit if the bid is above my stop for a short (ask is below my stop for a long)?

    Essentially the trade should not have stopped out at that level. Maybe is just a sim trading issue. Definitely don't want to see that happen in real trading.

    Thanks
    Attached Files

    #2
    Hello CMillz,

    Thanks for writing in.

    It is possible that the Ask price got you out with your stop loss.

    You could add your own exit logic that can get you out of your position when the Bid is at a certain price instead of having the Ask get you out. You could use OnMarketData to get realtime Bid/Ask information, or you could add a 1 tick data series for the Bid and Ask. This will also allow you to view the exact market data where that price would have met the your stop loss.

    OnMarketData() - https://ninjatrader.com/support/help...marketdata.htm

    Historical Bid/Ask (Additional Data Series) - https://ninjatrader.com/support/help..._ask_serie.htm

    Order Methods documentation (to be used in place of SetStopLoss()) - https://ninjatrader.com/support/help...er_methods.htm

    Please let me know if I may be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      Here's some code from my OrderProxy class which shows how to factor the spread into your orders. It won't work as-is as you don't have any of those classes or Enums but it shows the business logic required:

      Code:
      		
                     public async Task<double> FactorSpreadToStopPrice(ActiveOrder order)
      		{
      			if (order.TradeDirection == TradeDirection.Long) return order.StopPrice;
      
      			var spread = await order.MarketDataProxy.GetSpread();
      			return order.StopPrice + spread;
      		}
      
      		public async Task<double> FactorSpreadToTargetPrice(ActiveOrder order)
      		{
      			if (order.TradeDirection == TradeDirection.Long) return order.TargetPrice;
      
      			var spread = await order.MarketDataProxy.GetSpread();
      			return order.TargetPrice - spread;
      		}
      
      		public async Task<double> FactorSpreadToEntryPrice(ActiveOrder order)
      		{
      			if (order.TradeDirection == TradeDirection.Short) return order.EntryPrice;
      			var spread = await order.MarketDataProxy.GetSpread();
      			return  order.EntryPrice + spread;
      		}
      and here's a handy extension method for getting the spread ( just place in the strategy folder and you can get the spread from any indicator or strategy by calling this.GetSpread())

      Code:
      using System.Reactive;
      using System.Collections.Generic;
      using System.Diagnostics;
      using System.Linq;
      using System.Text;
      using NinjaTrader.Cbi;
      using NinjaTrader.Data;
      using NinjaTrader.Gui.Chart;
      using NinjaTrader.Gui.NinjaScript;
      using NinjaTrader.NinjaScript;
      
      
      namespace NinjaTrader.Custom.ExtensionMethods
      {
      	public static class NinjaScriptExtensionMethods
      	{
      		public static double GetSpread(this NinjaScriptBase ninjaScript, int bar = 0)
      		{
      			return ninjaScript.GetCurrentAsk(bar) - ninjaScript.GetCurrentBid(bar);
      		}
             }
      }

      Comment


        #4
        I probably should have just wrote it out in pseudo code:

        Short Exits, and long entries, get filled at the ask. All others are filled at the bid. Forex charts are driven by the bid; therefore:

        for entry:
        if long, add spread

        for stop:
        if short add spread

        for target
        if short subtract spread

        Target really depends on whether you're targeting a Risk/Reward ratio or a price point. If you're targeting a price point you're better to add otherwise you might miss the target.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CortexZenUSA, Today, 12:53 AM
        0 responses
        1 view
        0 likes
        Last Post CortexZenUSA  
        Started by CortexZenUSA, Today, 12:46 AM
        0 responses
        1 view
        0 likes
        Last Post CortexZenUSA  
        Started by usazencortex, Today, 12:43 AM
        0 responses
        5 views
        0 likes
        Last Post usazencortex  
        Started by sidlercom80, 10-28-2023, 08:49 AM
        168 responses
        2,265 views
        0 likes
        Last Post sidlercom80  
        Started by Barry Milan, Yesterday, 10:35 PM
        3 responses
        11 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X