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

Multi time series

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

    Multi time series

    Hi there,
    I have following problem. This is my code(edited part):


    protected override void Initialize()
    {
    Add(PeriodType.Minute, 1); // Adds another TimeSeries 1min Array[1]
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Use this method for calculating your indicator values. Assign a value to each
    // plot below by replacing 'Close[0]' with your own formula.

    // Posouzeni Stoch 2min


    if (CCI(14)[0] <= 20
    && Rising(CCI(BarsArray[1],14)) == true)
    {
    DrawTextFixed("CCI status","CCI OK ", TextPosition.BottomLeft, Color.Black, new Font("Arial", 10), Color.Black, Color.Lime, 10);
    }
    else
    if (CCI(14)[0] >= 80
    && Falling(CCI(BarsArray[1],14)) == true)
    {
    DrawTextFixed("CCI status","CCI OK ", TextPosition.BottomLeft, Color.Black, new Font("Arial", 10), Color.Black, Color.Lime, 10);
    }
    else
    {
    DrawTextFixed("CCI status","CCI NOK ", TextPosition.BottomLeft, Color.Black, new Font("Arial", 10), Color.Black, Color.Red, 10);
    }

    }



    What I want it to do is:
    I have the primary Time series 2min.
    I want to build an indicator based on CCI.
    If CCI on 2min is below 20 and CCI on 1min is rising, print green box saying "CCI OK" . If CCI on 2min is above 80 and CCI on 1min is falling, print green box saying "CCI OK". If anything else print red box saying "CCI NOK"

    I used Add(PeriodType.Minute, 1) to add 1min time series and BarsArray[1] to execute it in a code
    But I cannot get it working

    Can you help please?
    Radek

    #2
    Radek, you want to include a check to BarsInProgress for your conditions / OnBarUpdate code as well - http://www.ninjatrader.com/support/h...BarsInProgress

    Right now both bars objects updates would be used, while you want to work off the primary (BarsInProgress 0 only, as this is your 2 min),
    BertrandNinjaTrader Customer Service

    Comment


      #3
      I changed the script like this, but still not working. When I activate the indicator on the chart, the bars stop moving, BarTimer stops working(like if I was not connected)


      {

      if (BarsInProgress == 0)
      {

      if (CCI(14)[0] < 80 && CCI(14)[0] > 20)
      {
      DrawTextFixed("status","CCI NOK ", TextPosition.BottomLeft, Color.Black, new Font("Arial", 10), Color.Black, Color.Red, 10);
      }


      else if (CCI(14)[0] <= 20)
      {
      if (BarsInProgress == 1)

      {
      if (Rising(CCI(14)[0] == true)
      {
      DrawTextFixed("status","CCI OK ", TextPosition.BottomLeft, Color.Black, new Font("Arial", 10), Color.Black, Color.Lime, 10);
      }
      else
      {
      DrawTextFixed("status","CCI NOK ", TextPosition.BottomLeft, Color.Black, new Font("Arial", 10), Color.Black, Color.Red, 10);
      }

      }
      }
      else if (BarsInProgress == 1)
      {
      if (Falling(CCI(14)[0] == true)
      {
      DrawTextFixed("status","CCI OK ", TextPosition.BottomLeft, Color.Black, new Font("Arial", 10), Color.Black, Color.Lime, 10);
      }
      else
      {
      DrawTextFixed("status","CCI NOK ", TextPosition.BottomLeft, Color.Black, new Font("Arial", 10), Color.Black, Color.Red, 10);
      }
      }

      }
      }

      Comment


        #4
        Now, chart data is updating, but indicator is not working
        if I use BarsInProgress do I have to use BarsArray[1] too?
        the problem is that I need to compare CCI on both time periods in one time and then do something
        Last edited by godiamond; 03-20-2014, 11:41 AM.

        Comment


          #5
          Radek, what do you mean exactly by the script is not working? It's not showing any return or not the one you would expect from your conditions?

          Here's a simple test you could run for example for the long side of your condition from a 2 min primary chart - that would identify bars where the 2 min CCI is <= 20 and the 1 min one rising at the same time (primary bar update / timestamp) :

          if (BarsInProgress != 0) return;

          if (CCI(14)[0] <= 20 && Rising(CCI(BarsArray[1],14)) == true)
          {
          BarColor = Color.Blue;
          DrawArrowUp(CurrentBar.ToString(), 0, Low[0] - TickSize, Color.DarkBlue);
          }
          BertrandNinjaTrader Customer Service

          Comment


            #6
            To NinjaTrader_Bertrand , your sample script works, but I want the action(That box saying OK or NOK) just for the actual tick, every new tick to be recalculated. I do not want it from the past

            Comment


              #7
              I did some changes and it seems to be working. But without your help I would not make it, thanks a lot

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by helpwanted, Today, 03:06 AM
              1 response
              11 views
              0 likes
              Last Post sarafuenonly123  
              Started by Brevo, Today, 01:45 AM
              0 responses
              9 views
              0 likes
              Last Post Brevo
              by Brevo
               
              Started by aussugardefender, Today, 01:07 AM
              0 responses
              5 views
              0 likes
              Last Post aussugardefender  
              Started by pvincent, 06-23-2022, 12:53 PM
              14 responses
              242 views
              0 likes
              Last Post Nyman
              by Nyman
               
              Started by TraderG23, 12-08-2023, 07:56 AM
              9 responses
              387 views
              1 like
              Last Post Gavini
              by Gavini
               
              Working...
              X