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

i cant figure out timespan

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

    i cant figure out timespan

    zacharydw00

    Hi sorry i am out of blue, regarding your ict indicator, i am trying to setup a strategy but i cant figure out timespan and basically this line. Can you provide with an example that i can use in strategy? I am getting wrong arguments

    NinjaTrader_ChelseaB
    How do i reference TimeSpan in the strategy?

    fvgIndicator = FVGICT(Close, true, FVGPeriodTypes.Minute, 5, 50, true, 1, 10, 0.01, true, FVGFillType.CLOSE_THROUGH, true, false,
    true,TimeSpan(0, 03, 00, 0, 0),60,
    true,System.TimeSpan(0, 03, 00, 0, 0),60,
    true,System.TimeSpan(0, 03, 00, 0, 0),60,
    Brushes.Maroon, Brushes.Maroon, Brushes.DarkGreen, Brushes.DarkGreen, Brushes.Blue, Brushes.RoyalBlue, 13, 20, true,
    NinjaTrader.NinjaScript.DrawingTools.TextPosition. TopRight, new SimpleFont("Verdana", 12) { Bold = false, Italic = false },
    Brushes.WhiteSmoke, Brushes.DimGray, Brushes.Blue, 50);​

    Click image for larger version

Name:	image.png
Views:	302
Size:	560.8 KB
ID:	1268224
    Last edited by tkaboris; 09-10-2023, 12:26 PM.

    #2
    Hello tkaboris,

    I have moved your post to a new thread as this does not relate to referencing a ChartScale object outside of OnRender().

    Use the new keyword to generate a new instance of a class.

    new TimeSpan(2, 14, 18);

    Below is a link to the microsoft documentation.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you
      threre is this indicator in ecosystem

      It has FVG Class


      Code:
      #region Class FVG
              public class FVG
              {
                  public double upperPrice;
                  public double lowerPrice;
                  public double consequentEncroachmentPrice;
                  public string tag;
                  public FVGType type;
                  public bool filled;
                  public DateTime gapStartTime;
                  public DateTime fillTime;
      
      
                  public FVG(string tag, FVGType type, double lowerPrice, double uppperPrice, DateTime gapStartTime)
                  {
                      this.tag = tag;
                      this.type = type;
                      this.lowerPrice = lowerPrice;
                      this.upperPrice = uppperPrice;
                      this.consequentEncroachmentPrice = (this.lowerPrice + this.upperPrice) / 2.0;
                      this.filled = false;
                      this.gapStartTime = gapStartTime;
                  }
              }
              #endregion​
      in the onBarUpdate we add new fvg but it seems it doesnt store fvg in a collection. In my strrategy i need to find Last value and if I print
      Print(fvgList.FindLast); it returns error.
      Code:
      FVG fvg = new FVG(tag, FVGType.S, Highs[iDataSeriesIdx][2], Lows[iDataSeriesIdx][0], Times[iDataSeriesIdx][2]);
      Debug("Drawing Up FVG [" + fvg.gapStartTime + ", " + fvg.lowerPrice + ", " + fvg.upperPrice + "]");
      // Print(fvg);
      Draw.Rectangle(this, tag, false, fvg.gapStartTime, fvg.lowerPrice, future, fvg.upperPrice, UpBrush, UpAreaBrush, ActiveAreaOpacity, true);
      
      if (DisplayCE) Draw.Line(this, tag + "_CE", false, fvg.gapStartTime, fvg.consequentEncroachmentPrice, future, fvg.consequentEncroachmentPrice, UpBrush, DashStyleHelper.Dash, 1);
      fvgList.Add(fvg);​
      ​​

      I was wondering if someone can help to store fvg into a collection so later i can find Last occurence of fvg.upperPricec, or fvg.lowerPrice

      Comment


        #4
        Hello tkaboris,

        Where you have mentioned:
        "In my strrategy i need to find Last value"

        What Last value?

        Do you mean the market data Last update (as in Last, Ask, Bid) from OnMarketData()?


        Do you have a list and you are trying to find the last added element?

        myList[myList.Count - 1]

        Where you have mentioned:
        "Print(fvgList.FindLast); it returns error."

        If you would like assistance with an error message, please provide the full error message (Ctrl + c to copy the error from the errors area in the NinjaScript Editor, Ctrl + v to paste the error into your post) or a screenshot.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I am sorry
          For some reason now i have error that } must be there but it shouldnt
          It seems like issue in indicator definition. I was hoping to use strategy builder to deine indicator values but its not finding in strategy builder. can you please help?

          fvgIndicator = FVGICT(Close, true, FVGPeriodTypes.Minute, 5, 50, true, 1, 10, 0.01, true, FVGFillType.CLOSE_THROUGH, true, false,
          false,new TimeSpan(2, 14, 18),60,
          false,new TimeSpan(2, 14, 18),60,
          false,new TimeSpan(2, 14, 18),60,
          Brushes.Maroon, Brushes.Maroon, Brushes.DarkGreen, Brushes.DarkGreen, Brushes.Blue, Brushes.RoyalBlue, 13, 20, true,
          NinjaTrader.NinjaScript.DrawingTools.TextPosition. TopRight, new SimpleFont("Verdana", 12) { Bold = false, Italic = false },
          Brushes.WhiteSmoke, Brushes.DimGray, Brushes.Blue, 50);

          Click image for larger version

Name:	image.png
Views:	218
Size:	248.5 KB
ID:	1268351

          ​​​

          Comment


            #6
            Hello tkaboris,

            If you compile are there error messages?

            Check every opening and closing curly brace has a matching opposing curly brace. (Place the cursor on the outside of the curly brace and the opposing curly brace will be highlighted)

            Indicators cannot be opened in the Strategy Builder. Only strategies created with the Strategy Builder can be opened in the Strategy Builder.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              it compiles ok but still producing that error and because of it I cant properly access indicator values. if i comment out fvgIndicator in dataloaded it is fine after that.

              Code:
              #region Using declarations
              using System;
              using System.Collections.Generic;
              using System.ComponentModel;
              using System.ComponentModel.DataAnnotations;
              using System.Linq;
              using System.Text;
              using System.Threading.Tasks;
              using System.Windows;
              using System.Windows.Input;
              using System.Windows.Media;
              using System.Xml.Serialization;
              using NinjaTrader.Cbi;
              using NinjaTrader.Gui;
              using NinjaTrader.Gui.Chart;
              using NinjaTrader.Gui.SuperDom;
              using NinjaTrader.Gui.Tools;
              using NinjaTrader.Data;
              using NinjaTrader.NinjaScript;
              using NinjaTrader.Core.FloatingPoint;
              using NinjaTrader.NinjaScript.Indicators;
              using NinjaTrader.NinjaScript.DrawingTools;
              #endregion
              
              //This namespace holds Strategies in this folder and is required. Do not change it.
              namespace NinjaTrader.NinjaScript.Strategies
              {
                  public class FairValueGapStrategy : Strategy
                  {
                      private FVGICT fvgIndicator;
                      protected override void OnStateChange()
                      {
                          if (State == State.SetDefaults)
                          {
                              Description                                    = @"Enter the description for your new custom Strategy here.";
                              Name                                        = "FairValueGapStrategy";
                              Calculate                                    = Calculate.OnBarClose;
                              EntriesPerDirection                            = 1;
                              EntryHandling                                = EntryHandling.AllEntries;
                              IsExitOnSessionCloseStrategy                = true;
                              ExitOnSessionCloseSeconds                    = 30;
                              IsFillLimitOnTouch                            = false;
                              MaximumBarsLookBack                            = MaximumBarsLookBack.TwoHundredFiftySix;
                              OrderFillResolution                            = OrderFillResolution.Standard;
                              Slippage                                    = 0;
                              StartBehavior                                = StartBehavior.WaitUntilFlat;
                              TimeInForce                                    = TimeInForce.Gtc;
                              TraceOrders                                    = false;
                              RealtimeErrorHandling                        = RealtimeErrorHandling.StopCancelClose;
                              StopTargetHandling                            = StopTargetHandling.PerEntryExecution;
                              BarsRequiredToTrade                            = 20;
                              // Disable this property for performance gains in Strategy Analyzer optimizations
                              // See the Help Guide for additional information
                              IsInstantiatedOnEachOptimizationIteration    = true;
                          }
                          else if (State == State.Configure)
                          {
              //                AddDataSeries("ES 09-23", Data.BarsPeriodType.Minute, 5, Data.MarketDataType.Last);
                          }
                           else if (State == State.DataLoaded)
                          {  
                              fvgIndicator = FVGICT(Close, true, FVGPeriodTypes.Minute, 5, 50, true, 1, 10, 0.01, true,
                                              FVGFillType.CLOSE_THROUGH, true, false,
                                              false,new TimeSpan(2, 14, 18),60,
                                              false,new TimeSpan(2, 14, 18),60,
                                              false,new TimeSpan(2, 14, 18),60,
                                              Brushes.Maroon, Brushes.Maroon, Brushes.DarkGreen, Brushes.DarkGreen, Brushes.Blue, Brushes.RoyalBlue, 13, 20, true,
                                              NinjaTrader.NinjaScript.DrawingTools.TextPosition.TopRight, new SimpleFont("Verdana", 12) { Bold = false, Italic = false },
                                              Brushes.WhiteSmoke, Brushes.DimGray, Brushes.Blue, 50);​
                          }
                      }
              
                      protected override void OnBarUpdate()
                      {
                          if(CurrentBar < 10)
                              return;
              //            Print(FVGList.f);
              //            if (fvgIndicator != null && fvgIndicator.FVGList.Count > 0)
              //            {
              
              //            }
                      }
                  }
              }
              
              ​

              Comment


                #8
                Hello tkaboris,

                If the script compiles and there are no error messages, the syntax highlighting may be stale. Restart NinjaTrader.

                Regarding the indicator values, this would not be related if the script is compiled.

                Are you certain the indicator has a public property you are accessing? In the getter for this collection is Update() called?


                Are you certain the object is not null?
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  HI, there was a mistake in declaration int instead of double. I changed to double and error goes away.
                  I have made List public in indicator
                  public List<FVG> fvgList = new List<FVG>();

                  when i try to print this line i get error. I am trying to access last or before last lowerPrice and upperPrice

                  Print(fvgIndicator.FVGList.FindLast.lowerPrice);

                  Click image for larger version

Name:	image.png
Views:	206
Size:	214.1 KB
ID:	1268368

                  Comment


                    #10
                    Hello tkaboris,

                    The error is stating that FindLast() is a method. Used with parenthesis. If this is <List>.FindLast() there will not be a lowerPrice property.
                    List.FindLast() uses a delegate to find the last element that matches a condition.

                    Below is a link to the microsoft documentation.
                    Searches for an element that matches the conditions defined by the specified predicate, and returns the last occurrence within the entire List.


                    What is last?

                    Do you mean marketDataUpdate.Last?

                    What is lowerPrice? Is this double? This wouldn't be returned by FindLast().
                    Do you want fvgIndicator.lowerPrice?
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      In inidicator we have this logic. I want to access
                      fvg.lowerPrice
                      fvg.upperPrice from the strategy and i dont know how to

                      FVG fvg = new FVG(tag, FVGType.S, Highs[iDataSeriesIdx][2], Lows[iDataSeriesIdx][0], Times[iDataSeriesIdx][2]);
                      Debug("Drawing Up FVG [" + fvg.gapStartTime + ", " + fvg.lowerPrice + ", " + fvg.upperPrice + "]");

                      Draw.Rectangle(this, tag, false, fvg.gapStartTime, fvg.lowerPrice, future, fvg.upperPrice, UpBrush, UpAreaBrush, ActiveAreaOpacity, true);

                      if (DisplayCE) Draw.Line(this, tag + "_CE", false, fvg.gapStartTime, fvg.consequentEncroachmentPrice, future, fvg.consequentEncroachmentPrice, UpBrush, DashStyleHelper.Dash, 1);
                      fvgList.Add(fvg);​
                      Click image for larger version

Name:	image.png
Views:	212
Size:	1.08 MB
ID:	1268377

                      Comment


                        #12
                        Hello tkaboris,

                        What is lowerPrice?

                        Is this a plot series added with AddPlot()?
                        Is this an integer or double?
                        Is this a method?

                        Further, you have not confirmed, is .Update() being called in the getter of non-series properties?

                        To confirm, is this an indicator you created your self that you are calling?

                        If not, have you asked the developer or vendor that distributes this software for instructions on how to use their script?
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          I am lost..
                          I dont think that indicator has AddPlots series for that..
                          I didnt develop this indicator it was someone else, i tried reaching to developer of that indicator no response yet.

                          Comment


                            #14
                            Hello tkaboris,

                            How do you know there is a lowerPrice property?

                            Are you looking at the definition for it in the code of that indicator?

                            How is this property declared?
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              yes the lowerPrice i can see inside indicator code, as noted in post3.
                              Code to link also provided there

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by tradingnasdaqprueba, 04-09-2024, 09:52 AM
                              6 responses
                              26 views
                              0 likes
                              Last Post tradingnasdaqprueba  
                              Started by PaulMohn, Today, 02:06 AM
                              1 response
                              2 views
                              0 likes
                              Last Post PaulMohn  
                              Started by Mindset, Today, 01:27 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by EB Worx, 03-07-2023, 05:05 AM
                              4 responses
                              98 views
                              1 like
                              Last Post cls71
                              by cls71
                               
                              Started by patricia70, 11-23-2020, 10:17 AM
                              17 responses
                              548 views
                              1 like
                              Last Post PaulMohn  
                              Working...
                              X