Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

High Since Entry

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

    High Since Entry

    Hello All-

    How would I code the highest price since my entry?

    I want something along the lines of:

    // if highest price since entry is above PriceTarget 1


    {
    Put StopLimit @ Average Position Price
    }


    Thank you,

    Nick

    #2
    Hello njmeyer713,

    Thank you for your post.

    Excuse the edit but I thought of a different and better way to do this as soon as I hit post.

    You can use BarsSinceEntryExecution:

    if (BarsSinceEntryExecution() > 0)
    {
    if (MAX(High, BarsSinceEntryExecution())[0] > PriceTarget1)
    {
    //do something
    }
    }



    Please let us know if we may be of further assistance to you.
    Last edited by NinjaTrader_Kate; 07-15-2022, 01:49 PM.

    Comment


      #3
      Kate,

      Thank you for your response, I am running in to the Error message, "Value of property 'Period' of NInjaScript 'Max' is 0 and not in the valid range between 1 and 2147483647."

      I'm thinking that BarsSinceEntryExecution is returning a 0 on the first bar which is erroring it out.

      How do I fix this?

      Thank you,

      Nick

      Comment


        #4
        Kate,

        I have tried a few different things. Please see the attached screenshots.

        I have no longer getting the error message. I created an int called BarsSinceEntry and added 1 to put in the place of period in the MAX logic.

        My issue now is that the trade GreenHammer, is taken correctly but it immediately submits the ExitLongStopMarket called @"1GreenHammerExit"

        What I want it to do is submit the StopMarket @"1GreenHammer" only if the High since entry has reached GreenHammerTarget, which is a double variable set equal to the Highs[0][2] of the entry bar. I set this double when the buy order is submitted.

        I have added prints to try and see what the values are of the two variables and see why the ExitLongStopMarket logic is evaluating as true. I am attaching a screenshot of the Output window to show that the MAX high and GreenHammerTarget are both returning the expected values but that the ExitLongStopMarket is still being submitted.

        In summary, the MAX high since entry is returning a value below the GreenHammerTarget but exit order @"1GreenHammerExit" is still being submitted when it should only be submitted if the MAX high is greater than or equal to GreenHammerExit.

        Any ideas as to why this happening. Do you see any errors in my coding?

        Hopefully this makes sense.

        Thank you,

        Nick

        Attached Files

        Comment


          #5
          Hello njmeyer713,

          Thank you for your reply.

          I'm not seeing the same on my end with this test script - the exit order is only being submitted if the High since entry has reached the GreenHammerTarget level. Do you see the same testing with the attached code?

          Thanks in advance; I look forward to assisting you further.
          Attached Files
          Last edited by NinjaTrader_Kate; 07-18-2022, 09:07 AM. Reason: Didn't upload attachment the first time

          Comment


            #6
            Kate-

            Thank you for the reply. When I use your script the code performs how I would expect and want it to.

            However, when I copy that same exit logic over and use it following my entry order and fill in the names for the entries and exits, it sends a sell stop limit before the candle reaches the highs[0][2].

            I can't for the life of me figure out why the same exit logic works on yours but not in my strategy.

            Any thoughts? I know this a question with a lot of possible answers.

            Thank you,

            Nick

            Comment


              #7
              Hello njmeyer713,

              Thank you for your reply.

              I'd need to look at your strategy, as there's likely something amiss with your implementation. You can export the strategy from Tools > Export > NinjaScript Addon. Do not check the box to export as a compiled assembly or I will not be able to review your logic. Please attach the resulting .Zip file to your reply.

              Thanks in advance; I look forward to assisting you further.

              Comment


                #8
                Kate-

                I am having issues exporting the script. Here are screenshots of the code. I really stripped it down just to try and isolate the issue.

                Entries are good. For the exit I started with if Long, ExitLong("GreenHammer") and made sure every additional bit of code I added wouldn't cause the issue.

                Everything worked fine until I put in Line 95 of the code, the MAX coding. As I was added code bit by bit I had line 95 read as follows:

                Code:
                if(Closes[0][0] >= Highs[0][2]
                Everything else you see in the screenshot was the same. With that coding it worked as it should.

                When I replaced that with the following code


                Code:
                      if((MAX(High, BarsSinceEntry)[0] >= Highs[0][2]))
                the sell order would happen as soon as I entered the trade long instead of when the price reach the High of 2 bars ago.

                I then did a print statement to see and as you can see it shows the MAX high since entry is lower than the High of 2 bars ago but there is still an order submitted.


                One thing I did notice, when I would import your test script you sent in the above comments, a widow would pop up showing an error related to the MAX indicator. I have attached a screenshot of that. Could this have anything to do with it?

                Thank you,

                Nick

                Attached Files

                Comment


                  #9
                  Hey Kate-

                  I am just double checking that you saw my last post.

                  Thank you,

                  Nick

                  Comment


                    #10
                    Hello njmeyer713,

                    Thank you for your patience.

                    I've reworked your logic into an example script that may make more sense. This submits one of two exit orders, one if the bars since entry execution is 0 and we're only looking at the high of the current candle to place the exit and one that exits based on your conditions if the highest high since entry is greater than the high of 2 bars ago and bars since entry execution is greater than 0. If you open a NinjaScript Output window you'll see prints when the orders have been placed along with the bars since entry at which they were placed.

                    Please let us know if we may be of further assistance to you.
                    Attached Files

                    Comment


                      #11
                      Kate-

                      Thank you very much. I have run your script on my end at its working as it should. I am going to use this as a solid base to keep adding more parameters to. I'll let you know if I run into any further issues.

                      Thank you again,

                      Nick

                      Comment


                        #12
                        Kate-

                        I am having some issues with MIN. I will do my best to summarize.

                        A entry based on the previous shooter bar was taken, see the attached screenshot Chart, at 120.50. When the next bar opened up it immediately bought to cover at 120.65

                        However, the exit was ShooterMarketExit1, which has a condition that the MIN low since entry has to be below the double variable called Low2.

                        Low2 is defined on line 219 as Low2 = BarsSinceEntryExecution(0,"Shooter", 0) +2. This allows me to find the bar 2 prior to the entry bar.

                        You can see from line 240-259 that ShooterMarketExit1 is under the condition that the MIN Low since entry has to be less than the low of the Low2, which is 2 bars before the entry bar.

                        I have also included the output window from line 258.

                        From it you can see the data from when the bar open and the order to close the position is executed. Bars since entry is 1, correct. Value of Low2 is 3, correct. But is says that the statement (MIN(Low, BarsSinceEntry)[0] <= Lows[0][Low2] evaluates as true. Which I believe is false.

                        I don't know what I am missing or getting wrong here. In summary I don't know why that last statement evaluates as true when the price doesn't reach the Low of Low2.

                        Let me know if I need to clarify anything, I know I am throwing a lot at you.

                        Thank you,

                        Nick
                        Attached Files

                        Comment


                          #13
                          Hello Nick,

                          Thank you for your note.

                          What I would suggest here is to also print the values of MIN(Low, BarsSinceEntry)[0] and Lows[0][Low2]. That way you can assess what these values actually are more easily than trying to just look at the chart itself. What do you get for output when you also print those values?

                          Thanks in advance; I look forward to assisting you further.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by NullPointStrategies, Yesterday, 05:17 AM
                          0 responses
                          71 views
                          0 likes
                          Last Post NullPointStrategies  
                          Started by argusthome, 03-08-2026, 10:06 AM
                          0 responses
                          143 views
                          0 likes
                          Last Post argusthome  
                          Started by NabilKhattabi, 03-06-2026, 11:18 AM
                          0 responses
                          76 views
                          0 likes
                          Last Post NabilKhattabi  
                          Started by Deep42, 03-06-2026, 12:28 AM
                          0 responses
                          47 views
                          0 likes
                          Last Post Deep42
                          by Deep42
                           
                          Started by TheRealMorford, 03-05-2026, 06:15 PM
                          0 responses
                          51 views
                          0 likes
                          Last Post TheRealMorford  
                          Working...
                          X