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

Last iteration of multi stock strategy

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

    Last iteration of multi stock strategy

    I am running a 50 stock strategy, my questions are this

    What is the last iteration of BarsInProgress?

    Would the code be complete at BarsInProgress[49]?

    My problem is sometimes the value is the plot0 statement is null

    I want my code to pick that null reference up and loop back to the last not null data

    then break

    But I am doing something run and getting odd results

    Code:
                if (Plot0[0]==0)
                {
                    for (int index = 0; index < 50; index++) 
                    {
                        if (Plot0[index]!=0)
                        {
                        Plot0.Set(Plot0[index]);            
                        Print((Plot0[index])+"//"+index);
                        break;
                        }
                    }
                }

    #2
    Hello tinkerz,
    Thanks for your post and I am happy to assist you.

    BarsInProgress is the integer value that represents the BarsArray[] object that calls the OnBarUpdate event.

    There is no last iteration of BarsInProgress. It gets updated as and when the tick of the said BarsArray gets updated in the OnBarUpdate event.

    To know more about BarsInProgress please refer here http://www.ninjatrader.com/support/h...inprogress.htm

    You might also get some concept on the OnBarUpdate event http://www.ninjatrader.com/support/h...nbarupdate.htm

    To demonstrate the concept:
    Code:
    protected override void OnBarUpdate()	//OnBarUpdate event process quotes for all instruments
    {
    //Bars in progress helps us determine which data series the quotes belong too
    	if (BarsInProgress == 0)
    	{
    		//process data for primary series
    	}
    else if (BarsInProgress == 1)
    {
    		//precess data for secondary series
    }
    }
    Let us assume the no trade takes place for the secondary series. thus BarsInProgress == 1 will never trigger and BarsArray[1] will be a null value. So you got to check stuffs with if CurrentBar(s) > 0

    Please let me know if I can assist you any further.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      I understand that and the current bars concept.

      If I have a valid number of stocks the code

      if (validstocks!=0)
      {
      Plot0.Set(RCsum/validstocks);
      }

      will plot as there must be data in there, and as It will have to compute as many times as there is an unknown quatity of input data.

      but it does not explain if the plot statement is null this bar look back untill you find the first not null field and set at current plot.

      As I dont know the when last BarsInProgress will appear I can code it in, but its not working

      Any ideas

      Code:
              if (validstocks!=0) 
              {            
              Plot0.Set(RCsum/validstocks);
              }
      
                  if (Plot0[0]==null)
                  {
                      for (int index = 0; index < 50; index++) 
                      {
                          if (Plot0[index]!=null)
                          {
                          Plot0.Set(Plot0[index]);            
                          Print((Plot0[index])+"//"+index);
                          break;
                          }
                      }
                  }

      Comment


        #4
        Hello tinkerz,
        To know when BarsInProgress will appear, you got to filter the OnBarUpdate like:

        Code:
        protected override void OnBarUpdate()	
        {
        	if (BarsInProgress == 0)
        	{
        		//process data for primary series
        	}
        else if (BarsInProgress == 1)
        {
        		//precess data for secondary series
        }
        }
        There is no way to know otherwise.

        If you let me know what exactly you are trying to achieve then it will be easy for me to help you. Looks like you're trying to set plots but you also mentioned that this is a strategy. What is it you're looking to accomplish in the particular NinjaScript?

        I look forward to assist you further.
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          Hi,

          Its an indicator, I set my conditions earlier in the code

          Code:
              if (CurrentBar <= Length)
              return;
          
                  if (BarsInProgress==0)
                  {
                      RCsum=0;    
                      validstocks=0;
                      for (int index1 = 0; index1 < Length-1; index1++) 
                      {                    
                      Output1[index1]=Closes[0][index1];
          //            Print("A//"+Closes[0][index1]);
                      }                                        
                  }                        
                  
                              
                      
                  
                      
              for (int index = 1; index < 50; index++) 
              {    
                  if (BarsInProgress==index)
                  {            
                      for (int index1 = 0; index1 < Length-1; index1++) 
                      {                    
                      Output2[index1]=Closes[index][index1];    
          //            Print("B -  "+Closes[index][index1]);    
                      }
          
                  RCresult[index]=ComputeRankCorrelation(Output1,Output2,0,Length-1);
          //        Print("----------------"+RCresult[index]+"//"+BarsInProgress);    
                  RCsum=RCresult[index]+RCsum;
                      if(RCresult[index]!=0 || !double.IsNaN(RCresult[index])) 
                      {
                      validstocks+=1;
                      }
                  }                        
              }

          Therefore I want to print the total, i have a condition check if its not zero, then if there is missing data I want to fo got back to the last non-null plot and pull that data into the current bar

          and have a ema on the plot0

          So I need to have all the data in, I am just using historical data by the way, before I can plot and fill in the missing gaps

          thanks for your help on this

          Code:
                  if (validstocks!=0) 
                  {            
                  Plot0.Set(RCsum/validstocks);
                      
                                  
                  }
          
                      if (validstocks==0)
                      {
                          for (int index = 1; index < 50; index++) 
                          {
                              if (Plot0.Get(index)!=null)
                              {
                              Plot0.Set(Plot0.Get(index));            
                              Print((Plot0[index])+"//"+index);
                              break;
                              }
                          }
                      }
          
                  Plot1.Set((double)EMA(Plot0,Fast)[0]);        
                  Plot2.Set((double)EMA(Plot0,Slow)[0]);

          Comment


            #6
            Hello tinkerz,
            Can you upload the complete code or send the indicator to support[AT]ninjatrader[DOT]com
            If you send it via email do not forget to give a reference of this thread.

            I look forward to assist you further.
            JoydeepNinjaTrader Customer Service

            Comment


              #7
              Hello Neil,
              Thanks for the code.
              Unfortunately we do not do debugging for such complex code.


              Thanks for you reply, please can you comment on the structure of the code, I know the code is working to gather the data, the total plot 0 line is correct.


              its the EMA code and and lookback that I cant understand, it looks like having 50 stocks in the code is causing the loops that are not guarded by BarsInProgress to be run 50 times, is that correct?

              Comment


                #8
                Hello,

                For us to comment on the code we would need to analyze it.

                The first step here is reducing the complexity of the code. You need to get it down to something that is less then 20 lines of code that reproduces the issue. This si your first step to simplify it down to something that is the area that is causing the problem.

                Once we have this then we can help you isolate further however we could not isolate large code files unfortunately we do not have the resources to do that.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by DJ888, 04-16-2024, 06:09 PM
                4 responses
                12 views
                0 likes
                Last Post DJ888
                by DJ888
                 
                Started by terofs, Today, 04:18 PM
                0 responses
                9 views
                0 likes
                Last Post terofs
                by terofs
                 
                Started by nandhumca, Today, 03:41 PM
                0 responses
                6 views
                0 likes
                Last Post nandhumca  
                Started by The_Sec, Today, 03:37 PM
                0 responses
                3 views
                0 likes
                Last Post The_Sec
                by The_Sec
                 
                Started by GwFutures1988, Today, 02:48 PM
                1 response
                9 views
                0 likes
                Last Post NinjaTrader_Clayton  
                Working...
                X