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 Salahinho99, Today, 04:13 AM
                0 responses
                12 views
                0 likes
                Last Post Salahinho99  
                Started by junkone, 04-28-2024, 02:19 PM
                8 responses
                93 views
                1 like
                Last Post brucerobinson  
                Started by mkouitra, 10-23-2021, 04:40 PM
                17 responses
                1,970 views
                0 likes
                Last Post NinjaTrader_Jason  
                Started by Vietanhnguyen2hotmailcom, 05-03-2024, 10:29 AM
                4 responses
                32 views
                0 likes
                Last Post Vietanhnguyen2hotmailcom  
                Started by PhillT, 04-19-2024, 02:16 PM
                4 responses
                40 views
                0 likes
                Last Post PhillT
                by PhillT
                 
                Working...
                X