Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem with target in strategy Analyzer

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

    Problem with target in strategy Analyzer

    Hi Dear.

    I can't put target in my strategy.

    For example.

    When prices close above the SMA20, and the next day occur exceed the maximum of the previous day, you should buy.

    The entry in the high price, stop in low price, Target = (high price - low price) + high price.

    How I can do this in ninja trader ?

    See attachments for undestand better.

    Thank you
    Attached Files
    Last edited by marcyomatheus; 01-17-2015, 05:02 AM. Reason: Insert other attachments

    #2
    Hello marcyomatheus,

    Thank you for your post.

    What level are you determining as the Low price here?

    Comment


      #3
      Hi PatrickH.

      I am determining as the Low price in candle 1.

      Do you understanding my doubt?

      Note1: See attachments "help ninja trader 2"

      Thank you
      Last edited by marcyomatheus; 01-13-2015, 05:57 PM. Reason: Change the text

      Comment


        #4
        Hello,

        The code is listed below, let me know if you have any questions.
        Code:
                #region Variables
                private double lowAtCross = 0;
        		private double highAtCross = 0;
        		private int barAtCross = 0;
                #endregion
        
                /// <summary>
                /// This method is used to configure the strategy and is called once before any strategy method is called.
                /// </summary>
                protected override void Initialize()
                {
                    
                }
        
                /// <summary>
                /// Called on each bar update event (incoming tick)
                /// </summary>
                protected override void OnBarUpdate()
                {
        			if(CrossAbove(Close, SMA(20), 1))
        			{
        				lowAtCross = Low[0];
        				highAtCross = High[0];
        				barAtCross = CurrentBar;
        			}
        			if(CurrentBar == barAtCross+1
        				&& High[0] > highAtCross)
        			{
        				EnterLong();
        			}
        			if(Position.MarketPosition == MarketPosition.Flat) // Reset stop and target when flat.
        			{
        				SetProfitTarget(CalculationMode.Ticks, 5);
        				SetStopLoss(CalculationMode.Ticks, 5);
        			}
        			if(Position.MarketPosition == MarketPosition.Long)
        			{
        				SetProfitTarget(CalculationMode.Price, highAtCross + (highAtCross - lowAtCross));
        				SetStopLoss(CalculationMode.Price, lowAtCross);
        			}
                }

        Comment


          #5
          Hi PatrickH.

          When I put this code in strategy, show some errors.

          I'm so sorry, but I don't know "lowAtcross" - Where I can find it in Ninja Trader ?

          Could you send me in other way, see attachment 3.

          thank you.

          Comment


            #6
            Hello marcyomatheus,

            Thank you for your response.

            Due to storing the CurrentBar and using SetStopLoss and SetProfitTarget in OnBarUpdate() we could not build this in the Strategy Wizard. Please view the attachment to this post for the full .cs file.
            Attached Files

            Comment


              #7
              Hi PratrickH.

              I tried import this script to NinjaTrader. But isn't work.

              The next step, I did a copy and pase in edit script, and showed some errors, like ( { --- expected);

              So, would you send me a library comands from edit script. I have learn to do this.

              Thank you.

              Comment


                #8
                marcyomatheus, the error you unfortunately have seen would likely come from another script then, could you perhaps post a screenshot of the compile error you have witnessed here so we could review?

                Here's also a great tip generally how to approach this issues at compile time to isolate out - http://www.ninjatrader.com/support/f...ead.php?t=4678
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  Ok. This script that you send me is working.


                  Thank you

                  Comment


                    #10
                    Hi PatrickH,

                    Could you explain me this part of script.

                    if(Position.MarketPosition == MarketPosition.Flat) // Reset stop and target when flat.
                    {
                    SetProfitTarget(CalculationMode.Ticks, 5);
                    SetStopLoss(CalculationMode.Ticks, 5);
                    }

                    I noted that I had change number "5" to "100", but some stops aren't working.

                    See attachements.

                    Thank you.

                    Comment


                      #11
                      Hello marcyomatheus,

                      Thank you for your response.

                      That code resets the values of the Stop and Target to avoid use of the previous values of the previous position when entering into a new position. 100 is likely too large. However, if you would like us to take a look please add the attachments as they are not present in your post.

                      Comment


                        #12
                        Problem with target in strategy Analyzer Reply to Thread

                        Hello PatrickH.

                        Ok. See attachments (Scipt of strategy and print of chart);

                        1 - SetProfitTarget - OK;
                        2 - SetStopLoss - isn't working;
                        3 - I tried to use - (SetprofitTarget(CalculationMode.Ticks = 5), but didn't work.


                        Have a nice day!

                        Thank you!
                        Attached Files
                        Last edited by marcyomatheus; 01-19-2015, 02:54 AM. Reason: Edit the text.

                        Comment


                          #13
                          Hello marcyomatheus,

                          Thank you for your response.

                          Do you receive an error on screen? Are there errors on the Log tab of the Control Center? If so, what do these errors report?

                          Comment


                            #14
                            Hello PatrickH.

                            I didn't notice any error on screen, Log Tab of the Control Center.

                            See attachments 4.

                            SetProfitTarget is OK. But SetStopLoss isn't.

                            On attachments 4.1 you can see, what I want explain.

                            SetProfitTarget isn't reseting.

                            Did you see my script ?
                            Attached Files
                            Last edited by marcyomatheus; 01-19-2015, 10:09 AM.

                            Comment


                              #15
                              Yes, I did see your script. Please use the code below.
                              Originally posted by NinjaTrader_PatrickH View Post
                              Hello,

                              The code is listed below, let me know if you have any questions.
                              Code:
                                      #region Variables
                                      private double lowAtCross = 0;
                              		private double highAtCross = 0;
                              		private int barAtCross = 0;
                                      #endregion
                              
                                      /// <summary>
                                      /// This method is used to configure the strategy and is called once before any strategy method is called.
                                      /// </summary>
                                      protected override void Initialize()
                                      {
                                          
                                      }
                              
                                      /// <summary>
                                      /// Called on each bar update event (incoming tick)
                                      /// </summary>
                                      protected override void OnBarUpdate()
                                      {
                              			if(CrossAbove(Close, SMA(20), 1))
                              			{
                              				lowAtCross = Low[0];
                              				highAtCross = High[0];
                              				barAtCross = CurrentBar;
                              			}
                              			if(CurrentBar == barAtCross+1
                              				&& High[0] > highAtCross)
                              			{
                              				EnterLong();
                              			}
                              			if(Position.MarketPosition == MarketPosition.Flat) // Reset stop and target when flat.
                              			{
                              				SetProfitTarget(CalculationMode.Ticks, 5);
                              				SetStopLoss(CalculationMode.Ticks, 5);
                              			}
                              			if(Position.MarketPosition == MarketPosition.Long)
                              			{
                              				SetProfitTarget(CalculationMode.Price, highAtCross + (highAtCross - lowAtCross));
                              				SetStopLoss(CalculationMode.Price, lowAtCross);
                              			}
                                      }

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by cre8able, Yesterday, 01:16 PM
                              3 responses
                              11 views
                              0 likes
                              Last Post cre8able  
                              Started by ChartTourist, Today, 08:22 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post ChartTourist  
                              Started by LiamTwine, Today, 08:10 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post LiamTwine  
                              Started by Balage0922, Today, 07:38 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post Balage0922  
                              Started by JoMoon2024, Today, 06:56 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post JoMoon2024  
                              Working...
                              X