Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Sample RealizedPnLwithATM Strategy

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

    Sample RealizedPnLwithATM Strategy

    Here's a sample Ninjascript strategy that calls an ATM strategy and includes the ability to set a daily Realized PnL profit and loss. If you have a daily goal of $300, the strategy will stop trading when realized PnL is $300 or greater. If you have a daily loss limit of -$300 the strategy will stop trading when PnL is -$300 or more. I tested it on various days and it worked perfectly.

    Thanks to Josh for guiding me every step of the way. Hopefully it will help someone who is having trouble making their strategy do this and the Ninja Support folks won't have to go through it all again. (You guys are all terrific).
    Joe
    Attached Files

    #2
    Trade1963,

    Thanks for sharing. I am sure someone will find this extremely helpful.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Trade1953, TY for sharing !

      helped me a lot

      Comment


        #4
        how to import.

        thanks for this, can someone please tell me how to import this in Ninja 7?

        Comment


          #5
          Welcome to our forums, for NT 7 you would need to modify the code to make it workable there, as Action.Buy changed to OrderAction.Buy (same for the sell side).

          BertrandNinjaTrader Customer Service

          Comment


            #6
            Thanks, i was able to compile in NT7, now i have a question, how to activate this Stratergy? using Superdom or Conrol center,,

            Comment


              #7
              Great, as this is a NinjaScript strategy, please either start it from the chart or strategies tab -



              Please also ensure to have an ATM strategy template on the SuperDOM setup that would be saved under the 2Tic name used in the NinjaScript strategy calling it.
              BertrandNinjaTrader Customer Service

              Comment


                #8
                Firstly I wished to thank Trader1953 for this piece of code....excellent work.
                It has cleanup almost all of my problems i had when tallying total profit for trades when using my strategy.

                I have however found an instance where there is still a problem in the totaling.
                Iit occurs in a very specific case described below.

                If you are in a trade with a working strategy and
                reverse your entry on the same bar (first use AtmStrategyClose(atmStrategy)
                the GetAtmStrategyRealizedProfitLoss will not return the correct profit for the trade.
                It will be returned on the next bar.

                It may be too late for me because i would like to check if on this last trade the daily target or max loss has been reached. If so i do not want to enter the reverse order.

                The GetAtmStrategyunRealizedProfitLoss is close but not accurate.
                If i use the GetAtmStrategyunRealizedProfitLoss my daily tally will be off by this amount
                going forward.

                Is there a way to get the total RealProfitLoss on running strategy without having to create an array of all orders entered and reading through it?

                Thank you for your patience and especially your help

                Regards
                Sammy

                PS I am using NinjaTrader 65

                Comment


                  #9
                  Sammy, can you please post the full code you are using and a reproducible scenario so we can test this out here? Thank you.
                  AustinNinjaTrader Customer Service

                  Comment


                    #10
                    Hi

                    I have been trying to keep a DailyTotal for the days activity in an ATM strategy and have found that occasionally, for whatever reason, my total does not always agree with the DOM.
                    (I am only trading one instrument at a time and the total should agree, and yes i start at Zero on the DOM and ATM)

                    I would like to create a string array and collect all the strategyIds used. Then read them to get the actual PNL for the day from the getatmstrategyrealizedprofitloss function
                    I have added the lines in the attached code with an <--------- added
                    to denote what i have added to the original working script.

                    When I uncomment the lines to insert into the string array ( where the orders are placed ) the strategy stops working. I am following a sample from a c# book but i must be doing something wrong.

                    Could someone kindly point me in the correct direction or show me a sample of a working string array.

                    This is what i am trying to accomplish:
                    I would like to load the array with the atmstrategyId when the orders are placed and then show them at the top of onbarupdate ( eventually I would like to do a tally for the PNL to ensure it matches up with all the orders taken).


                    Thank you kindly for your patience.

                    Sammy
                    Attached Files

                    Comment


                      #11
                      Sammy, what errors do you see when running this code? Are you perhaps accessing a non available index in your array (index out of bounds error)?

                      You probably have an easier time working with ArrayList's - http://msdn.microsoft.com/en-us/libr...(v=VS.80).aspx
                      BertrandNinjaTrader Customer Service

                      Comment


                        #12
                        Bertrand,

                        Thank you for your input.
                        The script stops working with no message.
                        If you were to uncomment out the lines in the where the orders are place and run the script you could see the atm stops running after the first order.

                        I have added the logic you suggested and am getting the message when compiling:
                        "The name 'myAL' does not exist in the current context."
                        its on this line:

                        myAL.Add(atmStrategyID);


                        What did i miss?
                        So sorry for the newbie question.

                        Thank you kindly

                        Sammy
                        Attached Files
                        Last edited by SammyC; 09-13-2010, 01:43 PM.

                        Comment


                          #13
                          Hello Sammyc,

                          Likely you are seeing this error because there is nothing called myAl. It may help to move that line to the variables region where it will be available anywhere within the indicator.

                          private ArrayList myAl = new ArrayList();
                          Ryan M.NinjaTrader Customer Service

                          Comment


                            #14
                            Thank you Ryan and Bertrand.
                            Your suggestions and direction are greatly appreciated.
                            I have attached the code which will solve the problem of not having the DOM's total equal the daily total I am maintaining in the Strategy.
                            It may not be the most eloquent but it solves the problem.
                            Best Regards,
                            Sammy
                            Attached Files

                            Comment


                              #15
                              Great to hear you got it working, thanks for sharing it here.
                              BertrandNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by AdamDJ8, Today, 09:18 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post AdamDJ8
                              by AdamDJ8
                               
                              Started by knowmad, Today, 03:52 AM
                              2 responses
                              26 views
                              0 likes
                              Last Post knowmad
                              by knowmad
                               
                              Started by ETFVoyageur, Today, 07:05 PM
                              0 responses
                              9 views
                              0 likes
                              Last Post ETFVoyageur  
                              Started by Orion815, 05-02-2024, 08:39 AM
                              2 responses
                              18 views
                              0 likes
                              Last Post Orion815  
                              Started by suroot, 02-25-2017, 04:43 AM
                              11 responses
                              2,554 views
                              0 likes
                              Last Post Zilvercat  
                              Working...
                              X