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

where to close to cover my previous losses

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

    where to close to cover my previous losses

    Hello,

    I would like to create an indicator which would show me where would it be possible to close my actual position to cover my previous losses (realized PnL < 0). So let´s say that it would draw a line above my entry when in a long position. The line would be placed on "daily breakeven" (entry price + realized PnL defined in tics). Could you advise me how to start?

    Thank you
    emuns

    #2
    Hello emuns,

    Thanks for your post.

    You could do this through your strategy using the Draw.Line() method, or by using a plot via AddPlot().
    References:



    Using Position.MarketPosition to detect when you are in a position you can then pull the Position.AveragePrice for the entry price and from there add (or subtract) the difference of the Realized PNL in ticks (if the realized PNL is less than 0). You can convert the price to ticks using TickSize.
    References:



    Here is a link to an example strategy that works with cumulative profit: https://ninjatrader.com/support/help...nce_statis.htm
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hello PaulH,

      thank you for your answer. I´m trying to create an indicator not strategy. But I think that it should be similar…?

      Now I struggle with problem, how to say:
      if (the current open position is long)
      do something;

      Comment


        #4
        Hello emuns,

        Thanks for your reply.

        An indicator would not typically have access to account/strategy information that your strategy would have.

        The links I previously provide all list various methods and properties that you can click on to see further along with examples.

        In the case of "the current open position is long", this would be known as the market position, please see MarketPosition: https://ninjatrader.com/support/help...etposition.htm

        Alternatively if you would like this created for you, we can provide references to 3rd party programmers skilled in Ninjascript.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Hello Paul,

          because you wrote that strategy would be easier, i tried to create one (see below). I compiled it successfully, but it doesn´t work as expected.

          I created some trades manually, these trades were losing trades, so my CumProfit is now in a loss. Than I take another trade manually on one chart (with chart trader) and I expect that the strategy will show me (on another chart) where to close this trade to cover my prior losses.

          Is my strategy incorrect or is my expectation incorrect?

          Thank you
          Attached Files

          Comment


            #6
            Hello emuns,

            Thanks for your reply.

            A strategy would in general only be aware of trades that the strategy itself initiated. Strategies are unaware of manual trades or trades of other strategies. The suggestions I provided would only be for a strategy to meet your initial query (on my incorrect assumption that the strategy was the only trading being performed).

            We should probably start over in understanding what you wish to do. Can you confirm that you are looking to create indication, on a specific chart, of where your entire accounts daily PNL (regardless of instrument) is relative to the current trades entry price? Would this be irrespective or inclusive of any current strategy trades?


            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Hello Paul,

              thank you for clarification.

              Yes, i can confirm that. I make only manual trades, so there are no strategy trades.

              I thought that it could be easy, but it was probably incorrect assumption… I went through the Help guide and I wonder what is the difference between "Position" and "PositionAccount"?
              I was also thinking what about to use this indicator as an inspiration: https://ninjatraderecosystem.com/use...lay-indicator/

              Thank you
              emuns
              Last edited by emuns; 08-01-2019, 08:57 AM.

              Comment


                #8
                Hello emuns,

                Thanks for your post.

                The help guide advises that Position.Account "Represents position related information that pertains to real-world account (live or simulation)."
                The help guide advises that Position "Represents position related information that pertains to an instance of a strategy. "

                I agree, the indicator your referenced contain many of the methods I was going to point to as a way to get account information into an indicator and work from there, so indeed yes.
                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  Hello Paul,

                  so, if I understand it correctly, it means that Position.Account is for indicators and Position is for strategies?

                  Comment


                    #10
                    Hello emuns,

                    Position as previously advised would only pull data relevant to the strategy code it is running in.

                    PositionAccount provides what the actual account position is. For example if one strategy on an instrument was long and another strategy on the same instrument and same account was Short, the PositionAccount for that account would be reporting that the account position is flat.

                    Paul H.NinjaTrader Customer Service

                    Comment


                      #11
                      Hello PaulH,

                      thank you for clarification… My indicator now works as expected. I just would have one note to the link of the Help Guide you provided. I mean TickSize: https://ninjatrader.com/support/help.../?ticksize.htm

                      There is a misleading example:

                      protected override void OnBarUpdate()

                      {

                      // Displays the master instrument's tick size at the bottom right of the chart

                      Draw.TextFixed(this, "tag1", Bars.Instrument.MasterInstrument.TickSize, TextPosition.BottomRight);

                      }

                      I suppose that correct should be:

                      protected override void OnBarUpdate()

                      {

                      // Displays the master instrument's tick size at the bottom right of the chart

                      Draw.TextFixed(this, "tag1", Bars.Instrument.MasterInstrument.TickSize.ToString(), TextPosition.BottomRight);

                      }


                      Comment


                        #12
                        Hello emuns,

                        Thanks for your reply.

                        If that is an example from the help guide, please provide a link to the page so we can get that example corrected. The link you provide is to TickSize which not does show the examples you are showing.
                        Paul H.NinjaTrader Customer Service

                        Comment


                          #13
                          Hello PaulH,

                          yes, I always wonder, how to get the correct address of the Help Guide? Wherever I go, I always get the same address in an address line:
                          https://ninjatrader.com/support/helpGuides/nt8/en-us/ ?!

                          So there are two TickSize´s pages:

                          The first one is:

                          NinjaScript > Language Reference > Common > Analytical >TickSize

                          The second one is:

                          NinjaScript > Language Reference > Common > Instruments > Instrument > MasterInstrument >
                          TickSize

                          I was trying to refer to the second reference.

                          The same problem is with PointValue (.ToString() is missing in the example). The same address as in the second reference, only with PointValue at the end.

                          How can I get correct address which refer to the desired page???



                          Comment


                            #14
                            Hello emuns,

                            Thanks for the direction, this is the link to the page: https://ninjatrader.com/support/help...t_ticksize.htm

                            I use google chome and in the search section once I find the section I right mouse click on it and select "open in new tab" which gives me the link/address of that help guide page.
                            Anyway, thanks for pointing that out and we will get it updated!


                            Paul H.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by yertle, Yesterday, 08:38 AM
                            7 responses
                            28 views
                            0 likes
                            Last Post yertle
                            by yertle
                             
                            Started by bmartz, 03-12-2024, 06:12 AM
                            2 responses
                            21 views
                            0 likes
                            Last Post bmartz
                            by bmartz
                             
                            Started by funk10101, Today, 12:02 AM
                            0 responses
                            5 views
                            0 likes
                            Last Post funk10101  
                            Started by gravdigaz6, Yesterday, 11:40 PM
                            1 response
                            9 views
                            0 likes
                            Last Post NinjaTrader_Manfred  
                            Started by MarianApalaghiei, Yesterday, 10:49 PM
                            3 responses
                            11 views
                            0 likes
                            Last Post NinjaTrader_Manfred  
                            Working...
                            X