Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

3 bar up / down trend

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

    3 bar up / down trend

    can anyone help me build a strategy for a 3 bar uptrend or downtrend ? do i have to make a indicator first ?

    thanks

    #2
    Hello benrock,
    Thanks for your post and I am happy to assist you.

    You can code a 3 bar uptrend/downtrend within the strategy itself. A basic code would look like
    Code:
    if (CurrentBar < 3) return;
    if (Close[0] > Close[1] && Close[1] > Close[2] && Close[2] > Close[3])
    {
    	//do something
    }
    You can easily create the basic framework using the Strategy Wizard.

    Also please see this YouTube video tutorial on the Strategy Wizard.

    You can also consult our NinjaScript consultants to create it for you. You can get the list of our NinjaScript consultants from here http://www.ninjatrader.com/partners#...pt-Consultants

    Please let me know if I can assist you any further.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      well thats why im asking if someone can help me , i know it can be done in the wizard , i just need help on how to do it

      Comment


        #4
        Hello benrock,
        The basic configuration via the strategy will be like as shown in the attached picture.

        Please note after you have coded the strategy you have to unlock the strategy and add the below code just below OnBarUpdate.

        Code:
        protected override void OnBarUpdate()
        {
        	if (CurrentBar < 3) return;
                //rest of the codes
        Please let me know if I can assist you any further.
        Attached Files
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          wow the customer service is unreal with u guys , i never got answers so quick , good job guys ,

          Comment


            #6
            what do u mean i have to unlock code and add that ? i have no clue how to write code sorry , also what do i use for the user defined inputs . i just want to learn the basics of this wizard.

            Comment


              #7
              Hello benrock,
              Thanks for your kind words.
              Please let me know if I can assist you any further.
              JoydeepNinjaTrader Customer Service

              Comment


                #8
                what do u mean i have to unlock code and add that ? i have no clue how to write code sorry , also what do i use for the user defined inputs . i just want to learn the basics of this wizard.

                Comment


                  #9
                  Hello benrock,
                  Since you are referencing to 3 bars back, you have to make sure there are enough bars in the data series you are accessing. Please read this post for further describes it http://ninjatrader.com/support/forum...ead.php?t=3170

                  Unfortunately you cannot check the bars back via the Strategy Wizard. You have to unlock the Wizard (click the Unlock button in the wizard as shown in the attached picture) and append the below code via the NinjaScript editor manually in order to do so.

                  Code:
                  protected override void OnBarUpdate()
                  {
                  	[B]if (CurrentBar < 3) return;[/B][COLOR="Green"] // add this line to your code manually[/COLOR]
                          //rest of the codes
                  Please let me know if I can assist you any further.
                  Attached Files
                  JoydeepNinjaTrader Customer Service

                  Comment


                    #10
                    what do i put for user defined inputs ?

                    Comment


                      #11
                      Hello benrock,
                      Since in this case you do not have any user defined input please leave it blank.
                      Please let me know if I can assist you any further.
                      JoydeepNinjaTrader Customer Service

                      Comment


                        #12
                        ok i made the strategy but when i go to backtest it is not on the list of stratergies , but it is on the list to the left .

                        whats wrong here ?
                        \


                        #region Using declarations
                        using System;
                        using System.ComponentModel;
                        using System.Diagnostics;
                        using System.Drawing;
                        using System.Drawing.Drawing2D;
                        using System.Xml.Serialization;
                        using NinjaTrader.Cbi;
                        using NinjaTrader.Data;
                        using NinjaTrader.Indicator;
                        using NinjaTrader.Gui.Chart;
                        using NinjaTrader.Strategy;
                        #endregion

                        // This namespace holds all strategies and is required. Do not change it.
                        namespace NinjaTrader.Strategy
                        {
                        /// <summary>
                        /// Enter the description of your strategy here
                        /// </summary>
                        [Description3bartrend]
                        public class MyCustomStrategy : Strategy
                        {
                        #region Variables
                        // Wizard generated variables
                        // User defined variables (add any user defined variables below)
                        #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()
                        {
                        SetProfitTarget("", CalculationMode.Ticks, 2);
                        SetStopLoss("", CalculationMode.Ticks, 3, true);

                        CalculateOnBarClose = true;
                        }

                        /// <summary>
                        /// Called on each bar update event (incoming tick)
                        /// </summary>
                        protected override void OnBarUpdate()
                        {
                        if (CurrentBar < 3) return;
                        //rest of the codes

                        // Condition set 1
                        if (Close[0] > Close[1]
                        && Close[1] > Close[2]
                        && Close[2] > Close[3])
                        {
                        }
                        }

                        #region Properties
                        #endregion
                        }
                        }

                        Comment


                          #13
                          Hello benrock,
                          Once you have unlocked the code please make sure you have compiled it.
                          • In Control Center menu bar goto Tools>Edit NinjaScript>Strategies
                          • In the Strategies dialog select MyCustomStrategy and click on the Ok button.
                          • In the NinjaScript Editor press F5 to compile it.


                          Also to understand the issue better, can you share a screenshot showing the issue?

                          To send a screenshot press Alt + PRINT SCREEN to take a screen shot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save as a jpeg file and send the file as an attachment.

                          For detailed instructions please visit the following link

                          How to take a screenshot on your smartphone, tablet, notebook or desktop computer


                          I look forward to assisting you further.
                          JoydeepNinjaTrader Customer Service

                          Comment


                            #14
                            ok all done but i cant get any results from it , are you sure that attachment u gave me will work

                            Comment


                              #15
                              Hello benrock,
                              The code I presented only filters the conditions. You need to further code it (via the wizard or the NinjaScript editor) as per your requirement. Please let me know if you have any specific query.

                              If you are new to creating strategies then please go through this YouTube video which demonstrates how to create strategies via the Strategy Wizard.

                              Also please go through the educational resources from our help files http://www.ninjatrader.com/support/h...strategies.htm
                              JoydeepNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              649 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              370 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              109 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              574 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              576 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X