Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Three Data Series Code Help

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

    Three Data Series Code Help

    I have downloaded and sort of understand the coding example for adding a second data series, but adding a third series has proved difficult. Before I get too deep into this I made a test strategy (but it is not working)...

    My main chart is RANGE, upon which I have loaded the strategy. I added 5 MIN and 1200 TICK. I only want to execute the trade on the close of the RANGE bar.

    I would like the last completed MIN bar and the last completed TICK bar to be green (higher close than open) before the RANGE bar closes--and when the RANGE bar closes higher than open (green), execute the trade.

    What is happening in the code below is the trade is executing on the close of the RANGE bar regardless of the MIN and TICK bars. When I compile I have no errors but obviously something is wrong. Below is the complete code, void of any // remarks.

    Can someone please point me in the right direction.

    Code:
    public class SampleDataSeriesC : Strategy
        {
            #region Variables
    		private DataSeries primarySeries;
    		private DataSeries secondarySeries;
    		private DataSeries thirdSeries;
    		private bool second = false;
    		private bool third = false;
            #endregion
    
            
            protected override void Initialize()
            {
    			Add(PeriodType.Minute, 5);
    			Add(PeriodType.Tick, 1200);
    			primarySeries = new DataSeries(this);
                            secondarySeries = new DataSeries(this);
    			thirdSeries = new DataSeries (this);
    			SetStopLoss(CalculationMode.Ticks, 5);
    			SetProfitTarget(CalculationMode.Ticks, 10);
    			CalculateOnBarClose = true;
            }
    
            protected override void OnBarUpdate()
            {
    			
    			if (secondarySeries == null)
    				{secondarySeries = new DataSeries(this);}
    			if (thirdSeries == null)
    			{thirdSeries = new DataSeries (this);}
    			
    			if (BarsInProgress == 1)
    			{
    				secondarySeries.Set(Close[1] - Open[1]);
    					if (secondarySeries[1] > 0)
    					 second = true;
    			}
    				
    			if (BarsInProgress ==1)
    			{
    				thirdSeries.Set(Close[1]- Open[1]);
    			
    					if (thirdSeries[1] >0)
    					third = true;	
    			}
    			
    			if (Close[0] > Open[0] && second == true && third == true)
    				EnterLong();
            }
    
            #region Properties
            #endregion
        }
    }

    #2
    Hello sarasotavince,

    Thank you for your post.

    Please try the following:
    Code:
    			if (BarsInProgress == 1)
    			{
    				secondarySeries.Set(Closes[1][1] - Opens[1][1]);
    					if (secondarySeries[1] > 0)
    					 second = true;
    			}
    				
    			if (BarsInProgress ==2)
    			{
    				thirdSeries.Set(Closes[2][1]- Opens[2][1]);
    			
    					if (thirdSeries[1] >0)
    					third = true;	
    			}
    			
    			if(BarsInProgress == 0)
    			{
    			if (Closes[0][0] > Opens[0][0] && second == true && third == true)
    				EnterLong();
    			}

    Comment


      #3
      Looks reasonable. Will experiment and report back asap. Thanks much...fingers crossed.

      Comment


        #4
        Close but no cigar. Please see the attached screen grab... here is what appears to be happening...

        If the current bar on the MIN chart is green and the current bar on the TICK chart is green, and the RANGE bar closes green...the trade fires. Clearly the last completed bar on the MIN chart was Close = Open (flat) and the last completed bar on the TICK chart was Close < Open.

        Your thoughts?

        Do you think the [1] is reading the second bar back from the current bar since the current bar still has 1:24 seconds for MIN and 1063 ticks for TICKS?

        Thanks for taking a look...
        Attached Files

        Comment


          #5
          You don't turn off any flags that have been "de-set"?

          So if 2 happens then 3 happens but 2 turns off, then 1 turns on - then that's a go.

          Comment


            #6
            Hello sarasotavince,

            Sledge makes a good point, the bools are never set to false. Please try the following:

            Code:
            			if (BarsInProgress == 1)
            			{
            				secondarySeries.Set(Closes[1][1] - Opens[1][1]);
            					if (secondarySeries[1] > 0)
            					 second = true;
            					else second = false;
            			}
            				
            			if (BarsInProgress ==2)
            			{
            				thirdSeries.Set(Closes[2][1]- Opens[2][1]);
            			
            					if (thirdSeries[1] >0)
            					third = true;	
            					else third = false;
            			}
            			
            			if(BarsInProgress == 0)
            			{
            			if (Closes[0][0] > Opens[0][0] && second == true && third == true)
            				EnterLong();
            			}

            Comment


              #7
              I'm embarrassed by that "rookie" mistake...but I can see you are absolutely correct. I think I have what I am looking for: a base upon which to build. Thanks All.

              Comment


                #8
                Hello sarasotavince,

                No worries, I made the same mistake in not noticing it when reviewing your code. Thanks to sledge for pointing it out to us.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by pechtri, 06-22-2023, 02:31 AM
                9 responses
                122 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by frankthearm, 04-18-2024, 09:08 AM
                16 responses
                66 views
                0 likes
                Last Post NinjaTrader_Clayton  
                Started by habeebft, Today, 01:18 PM
                1 response
                5 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by benmarkal, Today, 12:52 PM
                2 responses
                15 views
                0 likes
                Last Post benmarkal  
                Started by f.saeidi, Today, 01:38 PM
                1 response
                9 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Working...
                X