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

    #46
    I added these two lines and its printing type of the current one and its upper price. Not sure if these are values you want. it seems we need another loop to find the last type = S or R
    Code:
    EnterShort(1, "Short");
                    Print("Entering Short");
                    Print("fvgIndicator.FVGList[index].type"+fvgIndicator.FVGList[index].type);
                    Print("fvgIndicator.FVGList[fvgIndicator.FVGList.Count() - 1].upperPrice"+fvgIndicator.FVGList[fvgIndicator.FVGList.Count() - 1].upperPrice);
                    if (fvgIndicator.FVGList[index].type == NinjaTrader.NinjaScript.Indicators.FVGICT.FVGType.S)
                        {
                            Print("Previous upper");
                            Print(fvgIndicator.FVGList[fvgIndicator.FVGList.Count() - 1].upperPrice);                
                        }​
    Output
    Entering Short
    fvgIndicator.FVGList[index].typeR
    fvgIndicator.FVGList[fvgIndicator.FVGList.Count() - 1].upperPrice15427.25
    Fair Value Gap v0.0.3.0 :: Checking for FVGs that are filled.
    Fair Value Gap v0.0.3.0 :: Home isInTimeRange = True
    Fair Value Gap v0.0.3.0 :: Forum isInTimeRange = True Time: 8/30/2023 1:57:00 AM
    Fair Value Gap v0.0.3.0 :: Checking time range and impluse move filters.​

    Comment


      #47
      @NinjaTrader_ChelseaB

      HI i have this nested code updated and it seems working but it only finds the type on the nested for loop and very first value of that type but i need the last type S and its value
      I need to find
      - last opposite Type (S or R)
      - upperprice of that type

      protected override void OnBarUpdate()
      {
      if(CurrentBar < 10)
      return;

      for (int index = 0; index < fvgIndicator.FVGList.Count(); index++)
      {
      for (int indexx = 0; indexx < fvgIndicator.FVGList.Count(); indexx++)
      {
      Print("================================");
      // Print(string.Format("index: {0}: fvg.start gap time previous[{0}]: {1}", index, fvgIndicator.FVGList[1].gapStartTime));

      if (fvgIndicator.FVGList[index].type == NinjaTrader.NinjaScript.Indicators.FVGICT.FVGType. R
      && High[0] > fvgIndicator.FVGList[index].lowerPrice && Close[0] < Open[0])

      {
      EnterShort(1, "Short");
      Print("Entering Short" + Time[0]);
      Print("fvgIndicator.FVGList[index].type"+fvgIndicator.FVGList[index].type);
      Print("fvgIndicator.FVGList[fvgIndicator.FVGList.Count() - 1].upperPrice"+fvgIndicator.FVGList[fvgIndicator.FVGList.Count() - 1].upperPrice);
      // find type for nested loop
      if(fvgIndicator.FVGList[indexx].type == NinjaTrader.NinjaScript.Indicators.FVGICT.FVGType. S)
      Print("Type: "+fvgIndicator.FVGList[index].type);
      Print("upper Price of S"+fvgIndicator.FVGList[indexx].upperPrice); // It does return price but some other price of very first one, not the upperPrice of Last Type S
      }
      }
      }
      Updated...​

      Prints Output -- Lots of logging going on
      Entering Short9/13/2023 12:36:00 AM
      fvgIndicator.FVGList[index].typeR
      fvgIndicator.FVGList[fvgIndicator.FVGList.Count() - 1].upperPrice15493.25
      upper Price of S15659
      ================================
      index: 5: fvg.start gap time[5]: 9/12/2023 10:07:00 PM
      index: 5: fvg.type[5]: R
      index: 5: fvg.lowerPrice[5]: 15490.75
      index: 5: fvg.upperPrice[5]: 15493.25
      index: 5: fvg.filled[5]: False
      index: 5: fvg.fill time[5]: 1/1/0001 12:00:00 AM
      index: 5: fvg.tag[5]: FVGDOWN_2517cb7a-b3a5-403b-8dd7-625b448d0550_4387
      ================================
      Entering Short9/13/2023 12:36:00 AM
      fvgIndicator.FVGList[index].typeR
      fvgIndicator.FVGList[fvgIndicator.FVGList.Count() - 1].upperPrice15493.25
      upper Price of S15635.75
      ================================
      index: 5: fvg.start gap time[5]: 9/12/2023 10:07:00 PM
      index: 5: fvg.type[5]: R
      index: 5: fvg.lowerPrice[5]: 15490.75
      index: 5: fvg.upperPrice[5]: 15493.25
      index: 5: fvg.filled[5]: False
      index: 5: fvg.fill time[5]: 1/1/0001 12:00:00 AM
      index: 5: fvg.tag[5]: FVGDOWN_2517cb7a-b3a5-403b-8dd7-625b448d0550_4387
      ================================
      Entering Short9/13/2023 12:36:00 AM
      fvgIndicator.FVGList[index].typeR
      fvgIndicator.FVGList[fvgIndicator.FVGList.Count() - 1].upperPrice15493.25
      upper Price of S15613.75
      ================================
      index: 5: fvg.start gap time[5]: 9/12/2023 10:07:00 PM
      index: 5: fvg.type[5]: R
      index: 5: fvg.lowerPrice[5]: 15490.75
      index: 5: fvg.upperPrice[5]: 15493.25
      index: 5: fvg.filled[5]: False
      index: 5: fvg.fill time[5]: 1/1/0001 12:00:00 AM
      index: 5: fvg.tag[5]: FVGDOWN_2517cb7a-b3a5-403b-8dd7-625b448d0550_4387
      ================================
      Entering Short9/13/2023 12:36:00 AM
      fvgIndicator.FVGList[index].typeR
      fvgIndicator.FVGList[fvgIndicator.FVGList.Count() - 1].upperPrice15493.25
      upper Price of S15578.5
      ================================
      index: 5: fvg.start gap time[5]: 9/12/2023 10:07:00 PM
      index: 5: fvg.type[5]: R
      index: 5: fvg.lowerPrice[5]: 15490.75
      index: 5: fvg.upperPrice[5]: 15493.25
      index: 5: fvg.filled[5]: False
      index: 5: fvg.fill time[5]: 1/1/0001 12:00:00 AM
      index: 5: fvg.tag[5]: FVGDOWN_2517cb7a-b3a5-403b-8dd7-625b448d0550_4387
      ================================
      Entering Short9/13/2023 12:36:00 AM
      fvgIndicator.FVGList[index].typeR
      fvgIndicator.FVGList[fvgIndicator.FVGList.Count() - 1].upperPrice15493.25
      upper Price of S15556.5
      ================================
      index: 5: fvg.start gap time[5]: 9/12/2023 10:07:00 PM
      index: 5: fvg.type[5]: R
      index: 5: fvg.lowerPrice[5]: 15490.75
      index: 5: fvg.upperPrice[5]: 15493.25
      index: 5: fvg.filled[5]: False
      index: 5: fvg.fill time[5]: 1/1/0001 12:00:00 AM
      index: 5: fvg.tag[5]: FVGDOWN_2517cb7a-b3a5-403b-8dd7-625b448d0550_4387​
      Last edited by tkaboris; 09-14-2023, 05:25 AM.

      Comment


        #48
        Can you please help to iterate a nexted loop trough a List to find last occurence of type S and its upperPrice value?

        Comment


          #49
          Maybe it would be easier to modify indicator and make it better and more suitable for strategy in this case?

          Comment


            #50

            Hello tkaboris,

            I recommend you only print for the one item you are investigating at a time to keep things simple.

            While I am not able to provide advice for custom logic, from your description it sounds like you want the code accessing FVGList[index].type in the outer loop and code accessing FVGList[indexx].type in the inner loop, instead of all of the logic being in the inner loop.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #51
              How can i get one before last one lowerPrice?

              for (int index = 0; index < fvgIndicator.FVGList.Count(); index++)
              {
              Print(fvgIndicator.FVGList[index].lowerPrice );
              Print(fvgIndicator.FVGList[index].lowerPrice );

              }​

              Comment


                #52
                Hello tkaboris,

                I'm not sure what you are asking. Are you asking how to subtract one from the index variable?

                if (index > 0)
                Print(fvgIndicator.FVGList[index - 1].lowerPrice );
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #53
                  Yes thats what I need.
                  I also have this problem with indicator. In my entry condition, i state resistance level not to be filled for short and Sometimes even though price gets fiiled and indicator plots it as filled, strategy still opens the short trade. So I was thinking I need to create additional filter to include .tag as additional condition. (Maybe there is another way?)
                  However tag prints out "FVGDOWN_494119b2-a368-44fc-80f2-313bccaeea80_1167" which is not a doulbe so i cant plot it .
                  I was thinking to create another List of tags, like list of Short Tags and Long Tags and make sure those tags are not filled too? Not sure of this approach though...

                  if (FVGList.Count > 0 )
                  {
                  for (int index = 0; index < FVGList.Count; index++)
                  {
                  if (index > 0)
                  Print("last lower price"+FVGList[index].lowerPrice );
                  Print("last tag"+FVGList[index].tag);
                  {
                  Print("down");
                  }
                  }
                  }

                  Indicator already has function for checkedfilled FVGs
                  Code:
                  private void CheckFilledFVGs()
                          {
                              List<FVG> filled = new List<FVG>();
                  
                              DateTime rdt = new DateTime();
                              DateTime sdt = new DateTime();
                  
                              foreach (FVG fvg in fvgList)
                              {
                                  if (fvg.filled) continue;
                  
                                  if (DrawObjects[fvg.tag] != null && DrawObjects[fvg.tag] is DrawingTools.Rectangle)
                                  {
                                      //Update EndAnchor of Gap to Expand into future.
                                      Rectangle gapRect = (Rectangle)DrawObjects[fvg.tag];
                                      gapRect.EndAnchor.Time = Times[iDataSeriesIdx][0].AddDays(ChartBars.Properties.DaysBack);
                  
                                      if (DisplayCE && DrawObjects[fvg.tag + "_CE"] != null && DrawObjects[fvg.tag + "_CE"] is DrawingTools.Line)
                                      {
                                          DrawingTools.Line gapLine = (DrawingTools.Line)DrawObjects[fvg.tag + "_CE"];
                                          gapLine.EndAnchor.Time = Times[iDataSeriesIdx][0].AddDays(ChartBars.Properties.DaysBack);
                                      }
                  
                                  }
                  
                                  if (fvg.type == FVGType.R && (FillType == FVGFillType.CLOSE_THROUGH ? (Closes[iDataSeriesIdx][0] >= fvg.upperPrice) : (Highs[iDataSeriesIdx][0] >= fvg.upperPrice)))
                                  {
                                      if (DrawObjects[fvg.tag] != null)
                                      {
                                          fvg.filled = true;
                                          fvg.fillTime = Times[iDataSeriesIdx][0];
                                          filled.Add(fvg);
                                          Values[24][0] = 2;
                  //                        Print("RFilled" + fvg.tag);
                                          if(lastR == null)
                                              lastR = fvg;
                                          else{
                                              if(fvg.gapStartTime > lastR.gapStartTime)
                                                  lastR = fvg;
                                          }
                  
                                      }
                                  }
                                  else if (fvg.type == FVGType.S && (FillType == FVGFillType.CLOSE_THROUGH ? (Closes[iDataSeriesIdx][0] <= fvg.lowerPrice) : (Lows[iDataSeriesIdx][0] <= fvg.lowerPrice)))
                                  {
                                      if (DrawObjects[fvg.tag] != null)
                                      {
                                          fvg.filled = true;
                                          fvg.fillTime = Times[iDataSeriesIdx][0];
                                          filled.Add(fvg);
                                          Values[25][0] = -2;
                  //                        Values[30][0] = 30;    
                  //                        Values[16][0] = 1;
                  //                        Print("SFilled" + fvg.tag);
                  //                        Print("FVG Up Filled Value"+Values[16][0]);
                  //                        Print("FVG Up Value From Start"+Values[4][0]);
                                          if(lastS == null)
                                              lastS = fvg;
                                          else{
                                              if(fvg.gapStartTime > lastS.gapStartTime)
                                                  lastS = fvg;
                                          }
                                      }
                                  }
                                  else{
                                      if (DrawObjects[fvg.tag] != null)
                                      {
                                          if(fvg.type == FVGType.S)
                                              currentS = fvg;
                                          else if(fvg.type == FVGType.R)
                                              currentR = fvg;
                                      }
                                  }
                              }
                  
                              foreach (FVG fvg in filled)
                              {
                                  if (DrawObjects[fvg.tag] != null)
                                  {
                                      var drawObject = DrawObjects[fvg.tag];
                                      Rectangle rect = (Rectangle)drawObject;
                  
                                      RemoveDrawObject(fvg.tag);
                                      RemoveDrawObject(fvg.tag + "_CE");
                  
                                      if (!HideFilledGaps)
                                      {
                                          Brush FilledBrush    = fvg.type == FVGType.R ? DownGapFilledBrush : UpGapFilledBrush;
                  
                                          rect = Draw.Rectangle(this, "FILLEDFVG" + fvg.tag, false, fvg.gapStartTime, fvg.lowerPrice, Times[iDataSeriesIdx][0], fvg.upperPrice, FilledBrush, FilledBrush, FilledAreaOpacity, true);
                                          //rect.OutlineStroke.Opacity = Math.Min(100, FilledAreaOpacity * 4);
                                      }
                                  }
                                  if (HideFilledGaps)
                                  {
                                      fvgList.Remove(fvg);
                                  }
                              }
                          }​
                  ​​Click image for larger version  Name:	image.png Views:	0 Size:	730.7 KB ID:	1270376
                  Last edited by tkaboris; 09-26-2023, 05:46 AM.

                  Comment


                    #54
                    Hello tkaboris,

                    You can use Draw.Text() to draw text such as the tag on the chart. (or you can custom render text in OnRender()).

                    If the order is being submitted at an unexpected time, the condition that submits the order evaluated as true.

                    Find the line that submits the order, the one line above the condition set print the time of the bar and all values used in the condition along with labels for each value and comparison operator.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #55
                      ok, a side question, do i need to initilize indicator in each barsinprogress? or just once in data loaded. its the same indicator

                      in dataloaded
                      indicator1 = (..........);


                      else if (BarsInProgress == 2)
                      indicator2 = (..........);

                      Comment


                        #56
                        Hello tkaboris,

                        Happy to assist.

                        Indicators can be assigned to variables and initialized from State.DataLoaded with the BarsArray[barsInProgressIndex], Closes[barsInProgressIndex], etc.

                        private SMA mySMA1, mySMA2;
                        private EMA myEMA;

                        In OnStateChange():
                        Code:
                        else if (State == State.Configure)
                        {
                        AddDataSeries(null, BarsPeriodType.Minute, 5); // BarsInProgress 1, BarsArray[1]
                        AddDataSeries(null, BarsPeriodType.Minute, 10); // BarsInProgress 2, BarsArray[2]
                        }
                        else if (State == State.DataLoaded)
                        {
                        mySMA1 = SMA(BarsArray[0], 14); // the entire bars object of the primary series BarsInProgress 0 (the chart bars), is supplied to indicator, by default the Input will be the Close series.
                        mySMA2 = SMA(Highs[1], 14); // specifically the high series of BarsInProgress 1, the 5 minute series, is supplied to the SMA as the input series.
                        myEMA; = EMA(SMA(Closes[2], 7), 14); // the close of BarsInProgress 2, the 10 minute series, is supplied to the SMA, then the plot series from the SMA is supplied to the EMA
                        }
                        In OnBarUpdate():
                        Code:
                        if (CurrentBars[0] < 1 || CurrentBars[1] < 1 || CurrentBars[2] < 1)
                        return;
                        
                        Print(string.Format("{0} | BIP: {1}, CurrentBar: {2}, {0} {1} {2}", Time[0], BarsInProgress, CurrentBar, Instrument.FullName, BarsArray[BarsInProgress].BarsPeriod.Value, BarsArray[BarsInProgress].BarsPeriod.BarsPeriodType));
                        
                        if (BarsInProgress == 0)
                        {
                        Print(string.Format("{0} | mySMA1: {1}", Time[0], mySMA1[0]));
                        }
                        else if (BarsInProgress == 1)
                        {
                        Print(string.Format("{0} | mySMA2: {1}", Time[0], mySMA2[0]));
                        ​}
                        else if (BarsInProgress == 2)
                        {
                        Print(string.Format("{0} | myEMA: {1}", Time[0], myEMA[0]));
                        }
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #57
                          thank you.
                          Can you please provide me with an idea of how to find a breaker pattern? a breaker pattern would be when i have "down fvg" previously and "up fvg" formed on or around down fvg levels instead?


                          Code:
                          if ((!AllBarsSameDirection || Closes[iDataSeriesIdx][2] < Opens[iDataSeriesIdx][2]
                                              && Closes[iDataSeriesIdx][1] < Opens[iDataSeriesIdx][1] && Closes[iDataSeriesIdx][0] < Opens[iDataSeriesIdx][0]) &&
                                              Highs[iDataSeriesIdx][0] < Lows[iDataSeriesIdx][2] && (Math.Abs(Highs[iDataSeriesIdx][0] - Lows[iDataSeriesIdx][2]) >= MinimumFVGSize))
                                          {
                                              Debug("Down FVG Found.");
                                              string tag = "FVGDOWN_" + InstanceId + "_" + CurrentBars[iDataSeriesIdx];
                                              FVG fvg = new FVG(tag, FVGType.R, Highs[iDataSeriesIdx][0], Lows[iDataSeriesIdx][2], Times[iDataSeriesIdx][2]);
                                              Debug("fvg down Tag."+ tag);​
                          }

                          Comment


                            #58
                            @NinjaTrader_ChelseaB

                            HI can you please help me to store fvg.tag name in series so i can reference it later?
                            I was hoping to to have evaluation whether Close[1] > upperprice , but i need to make sure upperprice belongs to the same tag, so i was thinking to loop through count and tag, and if they match then i will use it.

                            private Series<String> sameTag;

                            sameTag= new Series<String>(this);


                            if (fvgIndicator.FVGList.Count > 0 )
                            {

                            for (int index = 0; index < fvgIndicator.FVGList.Count; index++)
                            {

                            if (index > 0)

                            Print("Time :"+Time[0]);
                            Print("-last tag:"+fvgIndicator.FVGList[index].tag);
                            Print("-last upper price:"+fvgIndicator.FVGList[index].upperPrice );
                            Print("-last lower price:"+fvgIndicator.FVGList[index].lowerPrice );
                            Print("_____________");

                            if(Low[1] < fvgIndicator.FVGList[index].lowerPrice && fvgIndicator.FVGList[index].tag ==1)
                            {

                            Print("++++++++++++");
                            Print("Time :"+Time[0]);
                            Print("low1"+Low[1]);
                            Print("fvgIndicator.FVGList[index].lowerPrice"+fvgIndicator.FVGList[index].lowerPrice);
                            Print("-last tag of lowerPrice:"+fvgIndicator.FVGList[index].tag);
                            }
                            }
                            }​

                            Prints:
                            -last tag of lowerPrice:FVGUP_0321a0b6-5721-4a78-9885-51c6f54fb0b3_6699
                            Last edited by tkaboris; 09-29-2023, 11:59 AM.

                            Comment


                              #59
                              Hello tkaboris,

                              Please note, our Engineering Support staff is not supposed to be creating custom logic for clients. There are vendors that do provide these services.
                              (And the community is welcome to provide you with custom logic or trading advice)


                              In the support department at NinjaTrader it is against our policy to create, debug, or modify, code or logic for our clients. Further, we do not provide C# programming education services or one on one educational support in our NinjaScript Support department. This is so that we can maintain a high level of service for all of our clients as well as our associates.

                              You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.​


                              That said, FVGList is a List<> of added elements and is not a data series. I'm not understanding how you are relating a Series with this list.

                              That said are you trying to do this?

                              sameTag[0] = fvgIndicator.FVGList[index].tag;
                              Chelsea B.NinjaTrader Customer Service

                              Comment


                                #60
                                yes thats what i am tying to accomplish

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by synthhokie, Today, 08:53 AM
                                1 response
                                8 views
                                0 likes
                                Last Post NinjaTrader_Jesse  
                                Started by lunardiplomacy, Today, 09:00 AM
                                0 responses
                                7 views
                                0 likes
                                Last Post lunardiplomacy  
                                Started by ccerecermxl, Today, 08:44 AM
                                1 response
                                9 views
                                0 likes
                                Last Post NinjaTrader_Erick  
                                Started by successful_trader, Today, 08:33 AM
                                1 response
                                5 views
                                0 likes
                                Last Post NinjaTrader_Erick  
                                Started by xepher101, 05-10-2024, 12:19 PM
                                8 responses
                                105 views
                                0 likes
                                Last Post xepher101  
                                Working...
                                X