Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem with target in strategy Analyzer

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

    #16
    Hello PatrickH.

    This code that you sent me didn't work.

    I've tested it.

    I did some change in code with my strategy.

    I need know, how I can fix this problem with StopSetLoss.

    Because, If I want see strategy work with data of 10 years ago, I need to check everything in chart? It's impossible.

    Did you understand my question?

    Thank you!

    Comment


      #17
      Yes, I understand your question. It would appear you do not understand the solution or have improperly implemented the correct code as provided.

      What part of the code I provided does not perform as you are attempting to have your strategy perform? Please detail the unexpected behavior in your response using my code.

      Comment


        #18
        Problem with target in strategy Analyzer Reply to Thread

        Hello PatrickH.

        See attachments. I did a backtesting with your code.

        File "Help NinjaTrader 3"

        Price of buy and stop aren't working.

        Have you any ideas, how we can fix it?

        I appreciate your help.

        Thank you!
        Attached Files

        Comment


          #19
          Hello marcyomatheus,

          Thank you for your response.

          That is the nature of the historical fills, they will fill one bar after the condition returns true. Please refer to the following link for more information: http://www.ninjatrader.com/support/h...ime_vs_bac.htm

          Comment


            #20
            Hello PatrickH.

            Until now unfortunately isn't solved.

            Could you send me a code that works?

            Because, I tried yours and didn't work.

            I my strategy, I need to fix SetStopLoss.

            Could you help me?

            Thank you!

            Comment


              #21
              Hello marcyomatheus,

              Thank you for your response.

              So are you trying to get intra-bar fills as historical data will see fills at the end of the bar?

              Comment


                #22
                Problem with target in strategy Analyzer Reply to Thread

                Hello PatrickH.

                I'm trying to do this:

                Close above SMA(20);

                If the next candle exceed the maximum = buy;

                StopLoss in candle that close above SMA(20);

                Just it.

                Some cases StopLoss didn't work.

                Please look my code and send me a solution for this problem.

                Thank You!
                Attached Files

                Comment


                  #23
                  Hello marcyomatheus,

                  Thank you for your patience.

                  As you suspected it was the resetting of the Stop Loss. Please use the corrected code below:
                  Code:
                          protected override void OnBarUpdate()
                          {			
                  			if(CrossAbove(Close, SMA(20), 1)
                  				&& Position.MarketPosition == MarketPosition.Flat)
                  			{
                  				lowAtCross = Low[0];
                  				highAtCross = High[0];
                  				barAtCross = CurrentBar;
                  			}
                  			if(CurrentBar == barAtCross+1
                  				&& High[0] > highAtCross
                  				&& Close[0] > lowAtCross
                  				&& Close[0] > SMA(20)[0])
                  			{
                  				EnterLong();
                  				SetProfitTarget(CalculationMode.Price, highAtCross + (highAtCross - lowAtCross));
                  				SetStopLoss(CalculationMode.Price, lowAtCross);
                  			}
                          }

                  Comment


                    #24
                    Problem with target in strategy Analyzer Reply to Thread

                    Hello PatrickH.

                    Thank you for your patience too!!!!!

                    Now this script is Ok. I did some change, but your code is everything OK.

                    See the new code

                    #if(CrossAbove(Close, SMA(20), 1)
                    && Position.MarketPosition == MarketPosition.Flat)
                    {
                    lowAtCross = Low[0];
                    highAtCross = High[0];
                    barAtCross = CurrentBar;
                    }
                    if((CrossAbove(Close,SMA(20), 1))
                    && High[0] <= High[-1])
                    {
                    EnterLongLimit(DefaultQuantity, High[0],"");
                    SetProfitTarget(CalculationMode.Price, highAtCross + (highAtCross - lowAtCross));
                    SetStopLoss(CalculationMode.Price, lowAtCross);
                    }#

                    Thank you a lot!!!!!!

                    Comment


                      #25
                      Keep in mind that High[0] <= High[-1] will not work on real-time bars as it is not possible to know the values of a non-existent value. Hence the use of CurrentBar == barAtCross+1.

                      Comment


                        #26
                        Hello PatrickH.

                        It's true.

                        You have reason. I hadn't thought about it before.

                        I will use your code in my strategy.

                        Thank you!!!

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Segwin, 05-07-2018, 02:15 PM
                        14 responses
                        1,788 views
                        0 likes
                        Last Post aligator  
                        Started by Jimmyk, 01-26-2018, 05:19 AM
                        6 responses
                        837 views
                        0 likes
                        Last Post emuns
                        by emuns
                         
                        Started by jxs_xrj, 01-12-2020, 09:49 AM
                        6 responses
                        3,293 views
                        1 like
                        Last Post jgualdronc  
                        Started by Touch-Ups, Today, 10:36 AM
                        0 responses
                        13 views
                        0 likes
                        Last Post Touch-Ups  
                        Started by geddyisodin, 04-25-2024, 05:20 AM
                        11 responses
                        63 views
                        0 likes
                        Last Post halgo_boulder  
                        Working...
                        X