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

Logic for reversal bar in unmanaged approach?

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

    Logic for reversal bar in unmanaged approach?

    Hi i am using ninzarenko in one strategy and want to code logic for stoploss to be on reversal bar.
    currently my "sl" is double and it needs to stay as a double. but how do i make sl so that stop loss will be on the reversal bar? If i simply do Close[0] < Open[0] its a bool data type and wont work..
    Any ideas would be helpful


    Code:
     if (order.IsLong)
                    {
                        double tp = Instrument.MasterInstrument.RoundToTickSize(averageFillPrice + ProfitTarget * TickSize);
    
                        if (ProfitTarget > 0 && tp.ApproxCompare(ask) > 0)
                        {
                            targetOrder = SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.Limit, filled, tp, 0, oco, "PT");
                        }
                        double sl = Instrument.MasterInstrument.RoundToTickSize(averageFillPrice - StopLoss * TickSize);
    
                        if (StopLoss > 0 && sl.ApproxCompare(bid) < 0)
                        {
                            stopOrder = SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.StopMarket, filled, 0, sl, oco, "SL");
                        }
    
    
                    }​

    #2
    Hello, thanks for writing in. A strong reversal can be detected if at least two bars go in the opposite direction, so you will need to check for the reversal, then set up your stop and target orders. The strong reversal would be written as:

    if(Close[0] < Open[0] && Close[1] < Open[1])
    {
    //set stop loss and profit target.
    }

    The price you use for the stop and target need to be price values, so for long orders, the stop loss needs to be below the bid and the profit target needs to be below the ask. If you need someone to help directly with writing your strategy, the support team will not be able to spend time doing this. You would need to look for a developer in the NinjaTrader Ecosystem that will work one-on-one with you to write a custom strategy:

    Search trading apps & services to cusomize your NinjaTrader platform with trading indicators, signals and strategies.


    Disclaimer:
    The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      HI i have added that logic but SL still remains and position doenst get closed when bar reverses.
      See I have CloseOnReverse bool .

      ​if (order.IsLong)
      {
      double tp = Instrument.MasterInstrument.RoundToTickSize(averag eFillPrice + ProfitTarget * TickSize);


      if (ProfitTarget > 0 && tp.ApproxCompare(ask) > 0)
      {
      targetOrder = SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.Limit, filled, tp, 0, oco, "PT");
      }

      double sl = Instrument.MasterInstrument.RoundToTickSize(averag eFillPrice - StopLoss * TickSize);
      double slz = Instrument.MasterInstrument.RoundToTickSize(averag eFillPrice - 1 * TickSize);

      if(CloseOnReverse = true && Close[0] < Open[0])
      {
      stopOrder = SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.StopMarket, filled, 0, 1, oco, "SL");
      }


      else if (StopLoss > 0 && sl.ApproxCompare(bid) < 0)
      {
      stopOrder = SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.StopMarket, filled, 0, sl, oco, "SL");
      }


      }​

      Comment


        #4
        Hi, unfortunately, I will not be able to debug your code for you. By glancing at your bolded call to SubmitOrderUnmanaged(), the limit price and stop price are 0 and 1 which would likely not be a valid price for the instrument you are working with. We do have an example implemented in the unmanaged approach showing how to set up a OCO bracket that you can reference:

        Chris L.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by JoMoon2024, Today, 06:56 AM
        0 responses
        6 views
        0 likes
        Last Post JoMoon2024  
        Started by Haiasi, 04-25-2024, 06:53 PM
        2 responses
        19 views
        0 likes
        Last Post Massinisa  
        Started by Creamers, Today, 05:32 AM
        0 responses
        6 views
        0 likes
        Last Post Creamers  
        Started by Segwin, 05-07-2018, 02:15 PM
        12 responses
        1,786 views
        0 likes
        Last Post Leafcutter  
        Started by poplagelu, Today, 05:00 AM
        0 responses
        3 views
        0 likes
        Last Post poplagelu  
        Working...
        X