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

From MT to NT

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

    From MT to NT

    Hello,

    I'm parsing my strategies and indicators to NinjaTrader from MetaTrader4. I'm doing fine, but there are some functions that I can't find, so I ask for your help.

    I need to access all the old operations from NT, but I don't know how to get them. I need to count all the operations of a symbol in a day.

    Also, how I can know if an speciffic symbol has an operation already open?

    Greetings,
    Barrenas

    PS: After being coding in MT4 since before it had object programming, coding in NinjaTrader is extra funny. A really great job of the NT developers
    Last edited by Barrenas; 08-04-2015, 05:32 AM.

    #2
    Hello Barrenas,

    Thanks for your post and welcome to the Ninjatrader forums.

    For a list of methods in Ninjatrader you may want to use the alphabetically listed reference here: http://ninjatrader.com/support/helpG..._reference.htm

    You can find information about the number of trades or current position in the these links:
    http://ninjatrader.com/support/helpG...erformance.htm http://ninjatrader.com/support/helpG...etposition.htm
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Paul View Post
      Hello Barrenas,

      Thanks for your post and welcome to the Ninjatrader forums.

      For a list of methods in Ninjatrader you may want to use the alphabetically listed reference here: http://ninjatrader.com/support/helpG..._reference.htm

      You can find information about the number of trades or current position in the these links:
      http://ninjatrader.com/support/helpG...erformance.htm http://ninjatrader.com/support/helpG...etposition.htm
      Thnak you for your response and welcome.
      I have three new doubts.

      In the method "GetTrades" of TradeCollection class, what's the third parameter "instace" exacly for?

      The MarketPosition.Flat in Position.MarketPosition stands for no operation in the symbol at the moment?

      The third one, is in te NT graphic section a place where I can put text? Not an object, something like the comment section in MT4. (http://docs.mql4.com/common/comment)

      Also, if I call SetStopLoss when the trade is working, it will modify the SL?

      Thank you so much for your help.
      Greetings!
      Last edited by Barrenas; 08-04-2015, 06:43 AM.

      Comment


        #4
        Hello Barrenas,

        Thanks for your reply.

        The method GetTrades(), gets a TradeCollection object representing a specified position. The 3rd parameter is an integer number representing the occurrence of trades which would allow you to step back through your trades.

        Correct, MarketPosition.Flat means that you are not in a position. It is not uncommon to use this as a test for an entry condition, to make sure you are flat before entering a new position. For example
        if (Position.MarketPosition == MarketPosition.Flat && your other entry conditions)
        {
        // enter order here
        }


        For the chart comment, the equivalent would be either DrawTextFixed() or DrawText() methods. Using the Fixed version sets the text in any corner or center of chart while the unfixed version the text would move with the bars of the chart.

        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Paul View Post
          Hello Barrenas,

          Thanks for your reply.

          The method GetTrades(), gets a TradeCollection object representing a specified position. The 3rd parameter is an integer number representing the occurrence of trades which would allow you to step back through your trades.

          Correct, MarketPosition.Flat means that you are not in a position. It is not uncommon to use this as a test for an entry condition, to make sure you are flat before entering a new position. For example
          if (Position.MarketPosition == MarketPosition.Flat && your other entry conditions)
          {
          // enter order here
          }


          For the chart comment, the equivalent would be either DrawTextFixed() or DrawText() methods. Using the Fixed version sets the text in any corner or center of chart while the unfixed version the text would move with the bars of the chart.

          http://ninjatrader.com/support/helpG...wtextfixed.htm
          Thank you!

          (SOLVED)The indicators are driving me crazy, how can I put an arrow/triangle where I want? I get a separate graphic, but I want it to work with the price.(/SOLVED)

          Also, if I call SetStopLoss when the trade is working, it will modify the SL?

          Greetings!
          Last edited by Barrenas; 08-04-2015, 11:28 AM.

          Comment


            #6
            Hello,

            Thanks for your post.

            If I understand correctly, to have the indicator place a draw object you would need to modify the Ninjascript of the indicator.

            For SetStopLoss, yes you can dynamically change it. Here is the text from the helpguide:

            You may call this method from within the strategy OnBarUpdate() method should you wish to dynamically change the stop loss price while in an open position. Should you call this method to dynamically change the stop loss price in the strategy OnBarUpdate() method, you should always reset the stop loss price/offset value when your strategy is flat otherwise, the last price/offset value set will be used to generate your stop loss order on your next open position Here is the full reference: http://ninjatrader.com/support/helpG...etstoploss.htm
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Paul View Post
              Hello,

              Thanks for your post.

              If I understand correctly, to have the indicator place a draw object you would need to modify the Ninjascript of the indicator.

              For SetStopLoss, yes you can dynamically change it. Here is the text from the helpguide:

              You may call this method from within the strategy OnBarUpdate() method should you wish to dynamically change the stop loss price while in an open position. Should you call this method to dynamically change the stop loss price in the strategy OnBarUpdate() method, you should always reset the stop loss price/offset value when your strategy is flat otherwise, the last price/offset value set will be used to generate your stop loss order on your next open position Here is the full reference: http://ninjatrader.com/support/helpG...etstoploss.htm
              Ok, I have it. Thank you so much. I can compile now, but I have a runtime error. It seems to happen in the following line:
              pivot = ((Bars.GetDayBar(Upivot).High + Bars.GetDayBar(Upivot).Low + Bars.GetDayBar(Upivot).Close)/3);

              The error is "Reference to an object not established as an instance of an object" (traduction from spanish). Upivot is 1, so the problem should be in the Bars.GetDayBar() I guess. Is the method correctly used in my code?

              Regards,

              Comment


                #8
                Hello Barrenas,

                Thanks for your post.

                Your code is correct but incomplete. The issue is that you likely do not have enough bars loaded at the moment when your code executes. For reference when you add the indicator to the chart, it will process starting at the very first bar of data in the dataseries. So if you have 5 days of data loaded (in your chart/dataseries) the indicator will begin processing at the 1st bar 5 days ago. So the issue here is that when the indicator loads, on the 1st bar it cannot find a prior days data which then generates the error message you've seen.

                To fix the issue you need to check for a null bar and only execute when you do have a bar:

                if (Bars.GetDayBar(1) !=null) // if not null then we have data
                {
                pivot = ((Bars.GetDayBar(Upivot).High + Bars.GetDayBar(Upivot).Low + Bars.GetDayBar(Upivot).Close)/3);
                }


                Please note the example shown in the help guide here: http://ninjatrader.com/support/helpG...?getdaybar.htm
                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  Hello,

                  With your help, I have my strategies compiling, but I have one mayor issue: when the strategy takes one trade, it gets frozen.

                  Thats because I have two modes, one for managing the operation and other for opening trades. It switch beetween the two of them with if(Position.MarketPosition!=MarketPosition.Flat), that obiously isn't working.

                  I can't also get the count of lost trades of a day, my code is:

                  Code:
                  protected int countOps(string instrument, string tName){
                                    TradeCollection historic = Performance.AllTrades.LosingTrades.GetTrades(instrument,tName,1);
                  
                                         int i, rtrn=0;
                                         for(i=0;i<historic.Count-1;i++){
                                                 if(Time[0].DayOfYear==historic[i].Exit.Time.DayOfYear)
                                                           rtrn++;
                                  }
                              return(rtrn);
                          }
                  About the parameters, instrument is Instrument.Fullname, the second parameter is the trade name.

                  Can you help me to get where the errors are?

                  Thank you,
                  Kind Regards!

                  Comment


                    #10
                    Hello Barrenas,

                    Thanks for your post.

                    You will need to debug your strategy. We have assembled a good reference to the process in Ninjatrader here: http://ninjatrader.com/support/forum...ead.php?t=3418 In particular you will want to review TraceOrders to get more information.

                    In your code, you are retrieving only the first instance of a losing trade and i am not sure this is your intent. http://ninjatrader.com/support/helpG...?gettrades.htm note the parameter of 1 refers to the latest instance.
                    Paul H.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_Paul View Post
                      Hello Barrenas,

                      Thanks for your post.

                      You will need to debug your strategy. We have assembled a good reference to the process in Ninjatrader here: http://ninjatrader.com/support/forum...ead.php?t=3418 In particular you will want to review TraceOrders to get more information.

                      In your code, you are retrieving only the first instance of a losing trade and i am not sure this is your intent. http://ninjatrader.com/support/helpG...?gettrades.htm note the parameter of 1 refers to the latest instance.
                      I'm with the debbuging, seems that Position.MarketPosition isn't the current open trade, because sometimes is MarketPosition.Short when I have no operation in the market. I don't know how can get the current open position of an instrument.

                      About the second one, its driving me crazy. I'm tryng to get the number of losing trades that a given instrument has done in the present day. I though that Performance.AllTrades.LosingTrades.GetTrades(instr ument,tName,i).Count returned the total of lossing trades of an instrument, but It seems not. I'm totally lost with this.

                      Greetings!

                      Comment


                        #12
                        Hello Barrenas,

                        Thanks for your reply.

                        The Position.MarketPosition should reflect the condition of the strategy position. Are you thinking more of the account position verses the strategy position? http://ninjatrader.com/support/helpG..._account_p.htm

                        For your check of losing trades, here is a way (using either the entry time or exit time):
                        Code:
                               		
                        foreach (Trade myTrade in Performance.AllTrades.LosingTrades)       	
                        {
                          if (myTrade.Entry.Time.DayOfYear == Time[0].DayOfYear)
                                 Print ("mytrade: "+myTrade.Exit.Time.DayOfYear);  // replace with count accumulator.
                         }
                        Paul H.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_Paul View Post
                          Hello Barrenas,

                          Thanks for your reply.

                          The Position.MarketPosition should reflect the condition of the strategy position. Are you thinking more of the account position verses the strategy position? http://ninjatrader.com/support/helpG..._account_p.htm

                          For your check of losing trades, here is a way (using either the entry time or exit time):
                          Code:
                                         
                          foreach (Trade myTrade in Performance.AllTrades.LosingTrades)           
                          {
                            if (myTrade.Entry.Time.DayOfYear == Time[0].DayOfYear)
                                   Print ("mytrade: "+myTrade.Exit.Time.DayOfYear);  // replace with count accumulator.
                           }
                          Hello,

                          Thats exactly my problem, I don't know how to get straight to the account position! Please, can you help me with this?
                          About the code, it works perfect (except it takes strategy and no account positions), shame on me for not remembering the foreach (too much Mt4, I suppose).

                          I really appreciate your help,
                          Cheers!

                          Comment


                            #14
                            Hello Barrenas,

                            Thanks for your reply.

                            You can use GetAccount() to obtain your account value: http://ninjatrader.com/support/helpG...countvalue.htm

                            Here is a short video on the various sync options, I had meant to post this previously: https://www.youtube.com/watch?v=US9c...A14C398CA140D7
                            Paul H.NinjaTrader Customer Service

                            Comment


                              #15
                              Originally posted by NinjaTrader_Paul View Post
                              Hello Barrenas,

                              Thanks for your reply.

                              You can use GetAccount() to obtain your account value: http://ninjatrader.com/support/helpG...countvalue.htm

                              Here is a short video on the various sync options, I had meant to post this previously: https://www.youtube.com/watch?v=US9c...A14C398CA140D7
                              Hello,

                              I don't know If I fixed my problem, I'll keep you informed.

                              I have other problem, when I try to manage my order. I have a code that is like:
                              Code:
                              if(order.StopPrice > order.AvgFillPrice && things) SetStopLoss(tradeName,CalculationMode.Price,orden.AvgFillPrice-something,false);
                              The problem is (I think) that order is an IOrder instance that sometimes is null, there is a global variable where I can get the strategy order that is open now and get the SL and average price of it?

                              Greetings and thanks!

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by AaronKoRn, Today, 09:49 PM
                              0 responses
                              11 views
                              0 likes
                              Last Post AaronKoRn  
                              Started by carnitron, Today, 08:42 PM
                              0 responses
                              10 views
                              0 likes
                              Last Post carnitron  
                              Started by strategist007, Today, 07:51 PM
                              0 responses
                              11 views
                              0 likes
                              Last Post strategist007  
                              Started by StockTrader88, 03-06-2021, 08:58 AM
                              44 responses
                              3,980 views
                              3 likes
                              Last Post jhudas88  
                              Started by rbeckmann05, Today, 06:48 PM
                              0 responses
                              9 views
                              0 likes
                              Last Post rbeckmann05  
                              Working...
                              X