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

ATR(int period)[int barsAgo]

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

    ATR(int period)[int barsAgo]

    Why it caused error, when I put "1 period ago" to plot in Initialize()?

    Click image for larger version

Name:	[1].PNG
Views:	1
Size:	11.6 KB
ID:	898415

    Code:
     
    protected override void Initialize()
            {
    	(ATR(my_per)[B][1][/B]).Plots[0].Pen.Color = Color.Blue;
    
                Add((ATR(my_per)[B][1][/B]));
    			
    	CalculateOnBarClose = true;
            }

    #2
    Hi Alex, unfortunately that way of adding would not be supported, you could only add the complete indicator study as designed and not an individual custom, indexed value. If you wish to add delayed version of the ATR, then just create a custom verison of the ATR that would set a delayed by one bar plot for example.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Well, without [1] script works fine. All errors disappeared.
      I just need ATR returns value from "one bar before enter"
      Please help me how could I do this.

      Comment


        #4
        Correct. Yes, you would need to custom code an indicator that would return simply the plot one bar ago of the ATR, you can then add this custom indicator instead of the default ATR you're using now.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          I did like this
          Code:
          protected override void Initialize()
                  {
          	ATR(my_per).Plots[0].Pen.Color = Color.Blue;
          
                      Add(ATR(my_per));
          			
          	CalculateOnBarClose = true;
                  }
          
                  /// <summary>
                  /// Called on each bar update event (incoming tick)
                  /// </summary>
                  protected override void OnBarUpdate()
                  {
                      
          	// Condition for long
                      if (C[1] < C[2] + 1 * TickSize)
                      {
                          EnterLongStop(DefaultQuantity, C[0] + ATR(my_per)[B][1][/B], "Long Entry 1");
          So, I add "1 period ago" just in position rule. Can you advice, how could I do to set "1 bar before enter".

          Comment


            #6
            Originally posted by alexstox View Post
            Why it caused error, when I put "1 period ago" to plot in Initialize()?

            [ATTACH]21698[/ATTACH]

            Code:
             
            protected override void Initialize()
                    {
            	(ATR(my_per)[B][1][/B]).Plots[0].Pen.Color = Color.Blue;
            
                        Add((ATR(my_per)[B][1][/B]));
            			
            	CalculateOnBarClose = true;
                    }
            If you just need to access the ATR one bar ago, why are you adding it at all? Just access it directly where you need it.

            Regardless, you cannot index anything in the Initialize() method, as nothing indexable yet exists.

            Comment


              #7
              Hi Alex, there's no generic way for this unfortunately - you would need to store the ATR value on the bar of entry as needed (for example ATR[1]) and then you can use this value later in your Stop loss as double variable to place the stop level at.
              BertrandNinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_Bertrand View Post
                you would need to store the ATR value on the bar of entry as needed (for example ATR[1])
                But how to define Entry point?

                Comment


                  #9
                  Alex, simply store the value as your entry conditions trigger :

                  if (myEntryCondition)
                  {
                  EnterLong();
                  entryATR = ATR(14)[0];
                  }

                  Then you could use the entryATR value in your stop loss level calculation later.
                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    I want to clarify. If I use entryATR in EnterLong() condition, I just put entryATR before EnterLong() condition. Will entryATR be first in calculation by script, than EnterLong()? Am I right?

                    Code:
                    if (myEntryCondition)
                     {
                    entryATR = ATR(14)[0]; 
                    EnterLong();
                      }

                    Comment


                      #11
                      That's correct Alex, it would first store your ATR value and then call EnterLong() to enter the position.
                      BertrandNinjaTrader Customer Service

                      Comment


                        #12
                        Whenever i do an order entry for 20,000 contracts for example, it will say on the screen "Entry 19,000 @1.3144 and Entry 1,000 @1.3144" and then another 2 on the stop orders? does that mean that each order was a separate order and if so how do i make them each one order?

                        Comment


                          #13
                          Camron, for the future please post your issues in a new, separate thread. You're getting partial fills here for your FX spot simulated trading, go to Tools > Options > Simulator and check 'Enforce immediate fills' >> then you should not see this splitup happen.
                          BertrandNinjaTrader Customer Service

                          Comment


                            #14
                            Bertrand, Im getting "partial fills" as you call it for live trading not in the simulator.. how do i rectify that?

                            Comment


                              #15
                              Thanks for the clarification - could be the case, this is solely determined by market dynamics and not governed by any NT setting.
                              BertrandNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by timmbbo, 07-05-2023, 10:21 PM
                              4 responses
                              158 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by tkaboris, Today, 08:01 AM
                              1 response
                              7 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by Lumbeezl, 01-11-2022, 06:50 PM
                              31 responses
                              817 views
                              1 like
                              Last Post NinjaTrader_Adrian  
                              Started by xiinteractive, 04-09-2024, 08:08 AM
                              5 responses
                              15 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Started by swestendorf, Today, 11:14 AM
                              2 responses
                              6 views
                              0 likes
                              Last Post NinjaTrader_Kimberly  
                              Working...
                              X