Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Corresponding method of close button in trader section of chart

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

    Corresponding method of close button in trader section of chart

    Hi,
    I am developing a strategy for NT8.

    Would you please tell me the corresponding method of close button in trader section of chart(attachment).
    Actually I use ExitLong and ExitShort methods but they open reverse order (Long->Sell & Short->BuyToCover) and this is not the functionality that I want.
    I need to close the position immediately.



    #2
    Hi bosajin, thanks for your question.

    If ExitLong or ExitShort is reversing your position that means the strategy position is out of sync with the account position. If the strategy is in sync the methods will work as expected. So the question now is why the strategy is not in sync with the account position, what is your start behavior set to?

    I look forward to hearing from you.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hi,
      Please take a look at both methods , I have nothing special in start.
      As I said , I am just looking for a method to close working position.


      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = @"Enter the description for your new custom Strategy here.";
      Name = "ReverseUniRenkoStratetegy";
      Calculate = Calculate.OnBarClose;
      EntriesPerDirection = 1;
      EntryHandling = EntryHandling.AllEntries;
      IsExitOnSessionCloseStrategy = true;
      ExitOnSessionCloseSeconds = 30;
      IsFillLimitOnTouch = false;
      MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
      OrderFillResolution = OrderFillResolution.Standard;
      Slippage = 0;
      StartBehavior = StartBehavior.WaitUntilFlat;
      TimeInForce = TimeInForce.Gtc;
      TraceOrders = false;
      RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
      StopTargetHandling = StopTargetHandling.PerEntryExecution;
      BarsRequiredToTrade = 10;
      // Disable this property for performance gains in Strategy Analyzer optimizations
      // See the Help Guide for additional information
      IsInstantiatedOnEachOptimizationIteration = true;
      LookbackOffset = 2;
      MaxProfit = 0;
      MaxLoss = 0;
      TakeProfit = 0;
      StopLoss = 0;
      ProfitPrice = 0;
      LossPrice = 0;
      PrintEnabled = false;
      MACDUpperBoundary = 0;
      MACDLowerBoundary = 0;
      }
      else if (State == State.Configure)
      {

      }
      else if (State == State.DataLoaded)
      {
      ClearOutputWindow();
      DayNetProfit = 0;
      LastTradeIndexProcessed = SystemPerformance.AllTrades.Count();
      sessionIterator = new SessionIterator(Bars);
      MyPrint(string.Format("Current Profit", SystemPerformance.AllTrades.TradesPerformance.Curr ency.CumProfit));
      InitMACD();
      }
      }

      void InitMACD()
      {
      if(MACDUpperBoundary != 0 || MACDLowerBoundary != 0)
      {
      macd = MyMACD(12, 26, 9, MACDLowerBoundary, MACDUpperBoundary);
      macd.Panel = 2;
      macd.Plots[0].Brush = Brushes.Transparent;
      macd.Plots[1].Brush = Brushes.Transparent;
      macd.Plots[2].Width = 4;
      AddChartIndicator(macd);
      }
      }

      Comment


        #4
        Hi bosajin, thanks for your reply.

        Are you starting up the strategy when your account already has an open position? There is something causing the strategy to go out of sync with the account position.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Hi ChrisL,

          No, I don't.
          But this is a good point. what should I do in this situation?
          and my question has not been responded yet ?

          Comment


            #6
            Hello bosajin, thanks for your reply.

            The Exit methods will close the position properly when the strategy is in sync with the account. We do have the CloseStrategy() method, which will act exactly like the Close button, including disabling the strategy so I'm assuming you do not want this to happen. If you have some kind of scenario when you enter the position manually, then start up the strategy to close that position, you must use the Adopt Account position startup behavior to do this.

            Best regards.
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              You mean , we don't have a method to behave exact same as close position in chart.right?
              Please take a look the attachment.(Important!)

              Comment


                #8
                Hi bosajin, thanks for your reply,

                If you click the close button while a strategy is running, it will disable the strategy. An equivalent method in a strategy would be the CloseStrategy() method. The Exit methods must be used to close out of a position. So we need to figure out why the account position is not in sync with the strategic position. Could you share details on your OnBarUpdate method?

                Best regards.
                Last edited by NinjaTrader_ChrisL; 07-30-2020, 10:17 AM.
                Chris L.NinjaTrader Customer Service

                Comment


                  #9
                  Hi ChrisL,

                  There is a misunderstanding.
                  When I trade manually and hit the close button(in chart trader panel) the working position is going to be closed immediately and basically I don't see any reverse position like Sell or BuyToCover
                  However , When in my strategy I use the ExitLong and ExitShort to close working position ,don't see the same behavior (see Sell and BuyToCover ) .
                  I don't click on close button when strategy is running and also I don't want to close the strategy as well.

                  Comment


                    #10
                    Hello bosajin, thanks for your reply.

                    I will need more details on the strategy. Could you Export it and send it to me at platformsupport at ninjatrader.com referencing "Attn ChrisL 2675634" in the body of the email.

                    I look forward to hearing from you.
                    Chris L.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi ChrisL,

                      I have sent the source code.

                      Please take a look at the following post.I need this functionality.

                      https://ninjatrader.com/support/foru...24#post1112224



                      Comment


                        #12
                        Hello bosajin, thank you, I'm taking a look now.
                        Chris L.NinjaTrader Customer Service

                        Comment


                          #13
                          Hi bosajin thanks for sending that in.

                          I can't run the strategy with the default settings so I can't test it. I see there are many layers of entry logic here, so did you program the strategy to reverse the position like this? Doing something like EnterLong, then subsequently calling ExitLong works fine.

                          Best regards.
                          Chris L.NinjaTrader Customer Service

                          Comment


                            #14
                            Hi,ChrisL

                            Thanks for your attention.
                            Yes,I take position with seeing any reverse movement in market therefore closing all current open positions and take new position is very very important.

                            please take a look at TakePosition.
                            the code is part of it to for taking long position.
                            I want of if condition is true take long position otherwise close all working positions immediately.
                            but sometime I see an active sell is working for long time(attachment).
                            I would like to have a method to close all orders and position as mentioned in functionality of close button (https://ninjatrader.com/support/foru...24#post1112224)



                            case BarStatus.Rising:
                            if (CurrentBarOverMACDBoundery)
                            {
                            MyEnterLong(string.Format("Long_{0}", CurrentBar));
                            MyPrint(string.Format("{0} | Long | {1} | {2}", Time[0].Format24Hour(), CurrentBar, MACDDiffValue));
                            }
                            else
                            {
                            ExitAllPositions();
                            MyPrint(string.Format("Long is ignored by MACD | {0} | {1}", MACDDiffValue, Time[0].Format24Hour()));
                            }
                            break;





                            Comment


                              #15
                              Hi,

                              By the way,
                              I set StopLoss and TakeProfit for each position by the following methods.
                              However as you can see in previous attachment the sell doesn't have any order to control it.

                              SetStrategyTakeProfit();
                              SetStrategyStopLoss();

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by WHICKED, Today, 09:05 PM
                              0 responses
                              10 views
                              0 likes
                              Last Post WHICKED
                              by WHICKED
                               
                              Started by luislag14, Today, 06:29 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post luislag14  
                              Started by Protech, Today, 11:08 AM
                              1 response
                              23 views
                              0 likes
                              Last Post NinjaTrader_ChrisL  
                              Started by guilhem, Today, 02:09 PM
                              1 response
                              24 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by Hyper, Today, 12:20 PM
                              1 response
                              23 views
                              0 likes
                              Last Post NinjaTrader_Jim  
                              Working...
                              X