Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Spread indicator

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

    Spread indicator

    hi

    i have a spread indicator that does:

    Closes[1][0] - Closes[2][0];

    The problem with the above is that if Closes[2] did not have a value for a paticular point in time, the indicator takes the previous value, which is in a different timeframe. in other words, the value for closes[1] can be at 9 am and closes[2] might be 8 am. Any suggestions on how I can create an index that only compares values when both closes had a value at a paticular time, and ignore other values? I know there is an indicator called 'index' in the indicator seciton, but that doesnt seem to do what I am trying to do.

    also just read this;



    seems super complicated to me. i'd appreciate a sample code here. pls!

    basically i need:

    if closes[1][0] & closes[2][0] both had a value at time[0], then do the calculation, if the time for the closes is not the same, ignore.
    Last edited by staycool3_a; 04-20-2015, 12:06 AM.

    #2
    Originally posted by calhawk01 View Post
    hi

    i have a spread indicator that does:

    Closes[1][0] - Closes[2][0];

    The problem with the above is that if Closes[2] did not have a value for a paticular point in time, the indicator takes the previous value, which is in a different timeframe. in other words, the value for closes[1] can be at 9 am and closes[2] might be 8 am. Any suggestions on how I can create an index that only compares values when both closes had a value at a paticular time, and ignore other values? I know there is an indicator called 'index' in the indicator seciton, but that doesnt seem to do what I am trying to do.

    also just read this;



    seems super complicated to me. i'd appreciate a sample code here. pls!

    basically i need:

    if closes[1][0] & closes[2][0] both had a value at time[0], then do the calculation, if the time for the closes is not the same, ignore.
    Code:
    if (Closes[2].IsValidPlot(CurrentBar))
    {
    //do stuff
    }
    ref: http://www.ninjatrader.com/support/h...ries_class.htm

    Comment


      #3
      Thanks;

      so i created a private data series:

      private DataSeries myDataSeries;
      then added it to initliaize:

      myDataSeries = new DataSeries(this, MaximumBarsLookBack.Infinite);
      and in OBU i defined the dataseries:

      myDataSeries.Set(Closes[2][0]);
      I can plot the above, and it essentially plots the close price of CLoses[2]. How can i ignore values where Closes[2] is not valid? I tried the snippet you gave me but i'm not sure how to use that properly.

      I tried:

      if (myDataSeries.IsValidPlot(CurrentBar))

      Plot.Set{Closes[2][0]}

      But that doesnt compile.

      Also tried bunch of other stuff but i'm too embarrassed to share lol. Again, i also tend to just throw darts at the board, hoping something sticks that gives me the correct results lol

      Comment


        #4
        Originally posted by calhawk01 View Post
        Thanks;

        so i created a private data series:


        then added it to initliaize:


        and in OBU i defined the dataseries:


        I can plot the above, and it essentially plots the close price of CLoses[2]. How can i ignore values where Closes[2] is not valid? I tried the snippet you gave me but i'm not sure how to use that properly.

        I tried:

        if (myDataSeries.IsValidPlot(CurrentBar))

        Plot.Set{Closes[2][0]}

        But that doesnt compile.

        Also tried bunch of other stuff but i'm too embarrassed to share lol. Again, i also tend to just throw darts at the board, hoping something sticks that gives me the correct results lol
        What is "Plot" ? You should be getting an error about it being undefined, as far as I can see, from the snippet that you have posted.

        And why do we need to place anything in another DataSeries, that is a duplicate of one that we already have? Why not just test the existing one directly, as that is what you would have to do anyway before setting the DataSeries, if you are to reflect invalid data from Closes[2] in the DataSeries?
        Last edited by koganam; 04-20-2015, 10:21 AM.

        Comment


          #5
          Originally posted by koganam View Post
          What is "Plot" ? You should be getting an error about it being undefined, as far as I can see, from the snippet that you have posted.

          And why do we need to place anything in another DataSeries, that is a duplicate of one that we already have? Why not just test the existing one directly, as that is what you would have to do anyway before setting the DataSeries, if you are to reflect invalid data from Closes[2] in the DataSeries?
          Exactly thats what i was thinking: RE: Why do we need to create another data series.

          So my current code in OBU that sort of works is: but this is essentially identical to Closes[2][0] - Closes[1][0]. Not sure why isvalidplot isnt working

          Code:
                          if ( (Closes[2].IsValidPlot(CurrentBar)) )
                          {
                              
                              Plot.Set(Closes[2][0] - Closes[1][0]);
                              
                          }
          I'm trying to plot the difference between two dataseries. But only plot it of closes[2] has a value. If it doesn't have a value, I don't want anything to be plotted.. or return a value of zero or something. But whats happening right now is that, the plot is still using old closes[2] and doing the plotting. Thanks and pls let me know if i'm not making any sense. I wonder if it would be better to store a timestamp each time closes[2] value changes, and then compare the close[1] for the same time stamp
          Last edited by staycool3_a; 04-20-2015, 10:49 AM.

          Comment


            #6
            Originally posted by calhawk01 View Post
            Exactly thats what i was thinking: RE: Why do we need to create another data series.

            So my current code in OBU that sort of works is: but this is essentially identical to Closes[2][0] - Closes[1][0]. Not sure why isvalidplot isnt working

            Code:
                            if ( (Closes[2].IsValidPlot(CurrentBar)) )
                            {
                                
                                Plot.Set(Closes[2][0] - Closes[1][0]);
                                
                            }
            I'm trying to plot the difference between two dataseries. But only plot it of closes[2] has a value. If it doesn't have a value, I don't want anything to be plotted.. or return a value of zero or something. But whats happening right now is that, the plot is still using old closes[2] and doing the plotting. Thanks and pls let me know if i'm not making any sense. I wonder if it would be better to store a timestamp each time closes[2] value changes, and then compare the close[1] for the same time stamp
            You might want to check if Closes[2].IsValidPlot(CurrentBar) is ever false. If it is not, then your filter just means that NT does not really check, or at any rate never returns false on Closes (maybe only on IDataSeries that are not part of the IndicatorBase?)
            Code:
                           if  (Closes[2].IsValidPlot(CurrentBar)) 
                            {
                                Print("Valid Closes[2]");
                            }
                           else
                            {
                                Print("Invalid Closes[2]");
                            }
            If you confirm that Closes[2].IsValidPlot(CurrentBar) is never false, we shall have to look at something else to validate bars. We might look at Volume for example. If there was no trade on the bar, the Volume will either by 0 or invalid, or a minimum enforced by NT. You could check for that.

            The real best thing to do of course would be to not try to trade instruments that are so illiquid that they show no trades on a bar.
            Last edited by koganam; 04-20-2015, 12:34 PM.

            Comment


              #7
              Originally posted by koganam View Post
              You might want to check if Closes[2].IsValidPlot(CurrentBar) is ever false. If it is not, then your filter just means that NT does not really check, or at any rate never returns false on Closes (maybe only on IDataSeries that are not part of the IndicatorBase?)
              Code:
                             if  (Closes[2].IsValidPlot(CurrentBar)) 
                              {
                                  Print("Valid Closes[2]");
                              }
                             else
                              {
                                  Print("Invalid Closes[2]");
                              }
              If you confirm that Closes[2].IsValidPlot(CurrentBar) is never false, we shall have to look at something else to validate bars. We might look at Volume for example. If there was no trade on the bar, the Volume will either by 0 or invalid, or a minimum enforced by NT. You could check for that.

              The real best thing to do of course would be to not try to trade instruments that are so illiquid that they show no trades on a bar.
              Lol i agree. The thing is i have some calender spread strategies. Trading spread between back month and current month. CL is the most liquid calender for this purpose, but still the back month.. when you go out multiple months end up being illiquid. But you can still execute your orders at a fair price as exchanges try their best to keep this instrument fairly liquid.




              So i did what you asked.

              Code:
                             if  (Closes[2].IsValidPlot(CurrentBar)) 
                              {
                                  Print("Valid Closes[2]");
                              }
                             else
                              {
                                  Print("Invalid Closes[2]");
                              }
              NT does indeed return valid and invalid values. Mostly only going back two days, prior to two days, all values are valid. This could be either NT issue or data is not downloaded? I am connected to continuum. And my historical data should be being downloaded automatically.

              then i converted the above to:

              Code:
                             if  (Closes[2].IsValidPlot(CurrentBar)) 
                              {
                                  Ratio.Set(Closes[2][0]);
                              }
                             else
                              {
                                  Ratio.Set(0);
                              }
              the above seems to return zero when closes[2] does not have value, and returns the close[2] when it does have a value. How can i make it so that when it does not have a value, it returns previously calculated value by the indicator?. And any idea why NT is only calculating this going back two days? Prior to two days, it's not ensuring if Closes[2].IsValid; it's just taking the most recent close instead
              Last edited by staycool3_a; 04-20-2015, 03:10 PM.

              Comment


                #8
                Originally posted by calhawk01 View Post
                Lol i agree. The thing is i have some calender spread strategies. Trading spread between back month and current month. CL is the most liquid calender for this purpose, but still the back month.. when you go out multiple months end up being illiquid. But you can still execute your orders at a fair price as exchanges try their best to keep this instrument fairly liquid.




                So i did what you asked.

                Code:
                               if  (Closes[2].IsValidPlot(CurrentBar)) 
                                {
                                    Print("Valid Closes[2]");
                                }
                               else
                                {
                                    Print("Invalid Closes[2]");
                                }
                NT does indeed return valid and invalid values. Mostly only going back two days, prior to two days, all values are valid. This could be either NT issue or data is not downloaded? I am connected to continuum. And my historical data should be being downloaded automatically.

                then i converted the above to:

                Code:
                               if  (Closes[2].IsValidPlot(CurrentBar)) 
                                {
                                    Ratio.Set(Closes[2][0]);
                                }
                               else
                                {
                                    Ratio.Set(0);
                                }
                the above seems to return zero when closes[2] does not have value, and returns the close[2] when it does have a value. How can i make it so that when it does not have a value, it returns previously calculated value by the indicator?. And any idea why NT is only calculating this going back two days? Prior to two days, it's not ensuring if Closes[2].IsValid; it's just taking the most recent close instead
                If you are setting Ratio, I must presume that it is what you want to return. The previous value will be Ratio[1]. Whatever DataSeries/Plot you want to return, the previous value is indexed as 1.

                Your results imply that the validation of Closes[2] is being done correctly, so it is rather fruitless to speculate as to whether or not the validation agrees with what you expect. At least, I cannot fathom why there would be a discrepancy. That having been said, I have seen some rather wonky things with /CL in particular, post-rollover, pre-expiry, including such arcana as RangeBars (or Renko) that are incomplete before new bars form, and that do not get completed even if I reload historical data. /CL was in the post-rollover state until today. I cannot say that is the issue: I cannot say either what the issue might be.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                558 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                324 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                101 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                545 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                547 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X