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

how to find new 52-wk High on close

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

    how to find new 52-wk High on close

    I'm working on gathering some historical performance measures. Not really a trading strategy per se. What I want to calculate is this: When a stock closes at a new 52-week high, go long.

    Here is what I have so far:

    int value = HighestBar(Close, 256);

    If (CrossAbove(Close, Close[value], 1))
    {EnterLong(DefaultQuantity, "");}
    ....

    But it never enters any trades. I've tried both Highest Bar and MAX but with the same undesired output.

    Hints?

    thanks!
    dwayne

    #2
    Hello paschall,

    Thanks for your post.

    The issue is that your checking the a period that includes the current bar. The current bar will never cross above itself even if it is the highest bar. Instead, why don't you check to see if the current bar is the highest and the previous bar is not. This would be the same as a crossabove.

    For example:

    Code:
    int value = HighestBar(Close, 256);
    
    if (Close[1] != Close[value] && Close[0] == Close[value])
    {
    EnterLong(DefaultQuantity, "");
    }
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      re: how to find new 52-wk High on close

      Many thanks Chelsea. Your suggestions worked just fine.

      One thing I noticed in testing were a few errors in the Strategy Analyzer. I'll include the screen captures here. As you can see, the ordering of best cumulative return to worst doesn't always make sense. I.e., it lists a stock with NEGATIVE return (i.e., you lost money) as among the best (see the one stock with a PF less than one). I included the specific stocks in questions as screen captures as well.

      Not sure what the calculation problem was with S.A., but wanted to pass along the info as FYI.

      Thanks again for the help!

      cheers,
      D
      Attached Files

      Comment


        #4
        Hi paschall,

        The cumulative profit amount uses the gross profit to make its calculation and ignores any losses.

        http://www.ninjatrader.com/support/h...efinitions.htm

        For the amount of trades, this trade did have a high gross profit.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          So you're saying that "profit" = "gross winnings"? Doesn't "profit" mean wins - losses? And therefore "cumulative profit" would be the aggregate of that?

          Comment


            #6
            Hi paschall,

            I agree with you, I think my previous post (#4) is incorrect.

            While I know the calculation is "PRODUCT(1 + profit / entry price) of all trades - 1", I am not sure how this applies to the data you have.

            What I am going to do is work this out with a sample strategy and very few trades so that I can demonstrate how this works.

            I appreciate your patience as I whip something together.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              No problem. And I appreciate you looking into it. I think it may have something to do with the fact that it MAY (and I reserve the right to be wrong here) have to do with the initial price of the first trade in the backtest history. i.e., if price goes down, but rebounds and I make several profitable trades on the way back up, which entry price does SA use to calculate this? I could be way off though. Just guessing.

              It just seems, rather intuitively, that if PF is less than 1, then Cum. Profit can't be positive. Because they both share the same aspect of "profit".

              Comment


                #8
                Also note that the Cum. Profit number listed is in red which usually denotes a negative number in NT. If that's also true, then a Cum. Profit of -110% is NOT larger than a Cum. Profit of +96% (the next ones below in the high-low ranking of Cum. Profit!

                Comment


                  #9
                  Look at the SA grids. In the list of all the instruments in the portfolio, the Cum. Profit is listed in black (signifying a positive number). But click on the individual stock performance and the Cum. Profit is listed in red (signifying a negative number). SO how can it be positive and negative at the same time? Hahah. Sorta like "jumbo shrimp" ;-)

                  Comment


                    #10
                    Hi paschall,

                    So I made a video of how to calculate the cumulative profit. I'd like to you run your backtest over a single instrument with very few days so you have very little trades.

                    Try and get the backtest results to have a negative net profit and positive cumulative profit.

                    Then use the method in the video to manually calculate the values.

                    If you find the cumulative profit is wrong, please let me know, I will collect everything I need to test your strategy and will try calculating these values as well.

                    Below is a link to the video showing how to calculate the cumulative profit.
                    http://screencast.com/t/iz69NlQcXG6
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Many thanks. I have a couple of deadlines to handle today but I'll try to knock that out in the next day or two. Many thanks again for all your efforts.

                      Comment


                        #12
                        paschall,

                        I appreciate your question.

                        I wasn't very familiar with this and now have more experience with cumulative profit. This has been a learning experience for me as well.

                        Let me know if I can be of further assistance.
                        Chelsea B.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by PhillT, 04-19-2024, 02:16 PM
                        4 responses
                        31 views
                        0 likes
                        Last Post PhillT
                        by PhillT
                         
                        Started by ageeholdings, 05-01-2024, 05:22 AM
                        5 responses
                        36 views
                        0 likes
                        Last Post ageeholdings  
                        Started by reynoldsn, Today, 02:34 PM
                        0 responses
                        10 views
                        0 likes
                        Last Post reynoldsn  
                        Started by nightstalker, Today, 02:05 PM
                        0 responses
                        17 views
                        0 likes
                        Last Post nightstalker  
                        Started by llanqui, Yesterday, 09:59 AM
                        8 responses
                        30 views
                        0 likes
                        Last Post llanqui
                        by llanqui
                         
                        Working...
                        X