Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multiple data series for a strategy

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

    Multiple data series for a strategy

    I have a strategy that runs on 5min chart
    But I want one of my Exist conditions to be checking every 1 minute or every 30 seconds.
    How can I make only that one condition to run on 1 minute, while keeping the rest of the strategy running on 5 minutes ?
    I would very much appreciate if you can add a sample code. thanks

    #2
    Hello onlinebusiness,

    You can do that in a manually coded strategy. You would add a secondary series using AddDataSeries and then make a BarsInProgress condition:

    Code:
    if(BarsInProgress == 1)
    {
        //your conditions to be checked on 1 minute or 30 second secondary series here. 
    }




    Comment


      #3
      Hi Jesse, thank you for the assistance

      So here is a part of the strategy code where I want the condition to check every 1 minute

      Code:
                  if (State == State.Configure)
                  {
                      AddChartIndicator(PriceBreakoutShort(upwardBreakout,volumeMultiple));
                      AddDataSeries(BarsPeriodType.Minute, 1);
                  }
              }
      
              protected override void OnBarUpdate()
              {
                  // entering a short trade on the normal 5 minutes chart
                  if ( (Times[0][0].TimeOfDay >= new TimeSpan(17, 10, 0))
                      || (Times[0][0].TimeOfDay < new TimeSpan(14, 0, 0)))
                  {
                      EnterShort(10, "Short");
                      justEntered = true;
                  }
      
                  // checking the value of uPnL every 1minute
                  if (BarsInProgress == 0 && Account.Get(AccountItem.UnrealizedProfitLoss, Currency.UsDollar) > 500)
                  {
                      uPnLS500 = true;
                  }
      
                  // checking the exit condition every 1 minute
                  if (BarsInProgress == 0 && (uPnLS500 == true) && (Account.Get(AccountItem.UnrealizedProfitLoss, Currency.UsDollar) < 500))
      
                  {
                      ExitShort(100,"TakeProfit S" ,"Short");
                      // setting uPnL back to false so it is ready to be checked for the next position
                      uPnLS500 = false;
      
                  }​
      I only want that Exit condition to operate every 1 minute while leaving the rest of the strategy operating on my default chart time.
      That's what I did above but it's not working

      Maybe I did something wrong, could you please check

      Comment


        #4
        Hello onlinebusiness,

        It looks like you just used the wrong index, BarsInProgress == 0 would be your primary timeframe. BarsInProgress == 1 would be the secondary series that you added. I would suggest surrorunding your entry code as well if you want that to only work based on the default chart time:


        Code:
        protected override void OnBarUpdate()
        {
           ​​​​​​​   if (BarsInProgress == 0)
        ​​​​​​​   ​​​​​​​   {
               ​​​​​​​   // entering a short trade on the normal 5 minutes chart
            ​​​​​​​    if ( (Times[0][0].TimeOfDay >= new TimeSpan(17, 10, 0))
           ​​​​​​​      || (Times[0][0].TimeOfDay < new TimeSpan(14, 0, 0)))
            ​​​​​​​     {
              ​​​​​​​      EnterShort(10, "Short");
              ​​​​​​​      justEntered = true;
        ​​​​​​​   ​​​​​​​ ​​​​​​​     }
          ​​​​​​​     }
        
              // checking the value of uPnL every 1minute
              if (BarsInProgress == 1 && Account.Get(AccountItem.UnrealizedProfitLoss, Currency.UsDollar) > 500)
              {
        ​​​​​​​   ​​​​​​​   ​​​​​​​   uPnLS500 = true;
        ​​​​​​​   ​​​​​​​   }
        
        ​​​​​​​   ​​​​​​​   // checking the exit condition every 1 minute
        ​​​​​​​   ​​​​​​​   if (BarsInProgress == 1 && (uPnLS500 == true) && (Account.Get(AccountItem.UnrealizedProfitLoss, Currency.UsDollar) < 500))
        
        ​​​​​​​   ​​​​​​​   {
        ​​​​​​​   ​​​​​​​   ​​​​​​​   ExitShort(100,"TakeProfit S" ,"Short");
        ​​​​​​​   ​​​​​​​   ​​​​​​​   // setting uPnL back to false so it is ready to be checked for the next position
        ​​​​​​​   ​​​​​​​   ​​​​​​​   uPnLS500 = false;
        
        ​​​​​​​   ​​​​​​​   }​​

        Comment


          #5
          Hi Jesse

          I tried doing the same thing on this RSI simple strategy I'm practicing on, but it did not work

          Code:
                      if (State == State.Configure)
                      {
                          AddDataSeries(BarsPeriodType.Minute, 5);
                          AddDataSeries(BarsPeriodType.Minute, 3);
                          AddDataSeries(BarsPeriodType.Minute, 2);
                          AddDataSeries(BarsPeriodType.Minute, 1);
          
                      }
                      if (State == State.DataLoaded)
                      {                
                          RSI1                = RSI(Close, 7, 3);
                      }
                  }
          
                  protected override void OnBarUpdate()
                  {
                  if (CurrentBar < 5)
                  return;
                  if (BarsInProgress == 3)
                  {
          
                      /// SHORT Trades    
                      if (CrossBelow(RSI1.Default, 70, 1))
                      {
                          EnterShort(6, "Short");
                          justEntered = true;
                      }​
          For example when I change if (BarsInProgress == 0) to if (BarsInProgress == 3) nothing really changes in my trades, they are still executed at bar close​ and not every minute my entry condition is true.

          How can I make it execute every minute the RSI crossbelow 70 while still using the 5 chart. I don't want to wait for the bar to close then execute.

          Thank you

          Comment


            #6
            Hello onlinebusiness,

            To make the condition true every minute you need to change from using CrossBelow to a Less than condition.

            Code:
             if (RSI1.Default[0] < 70)

            The code you have in if (BarsInProgress == 3) will be executed for each 1 minute but the crossing of the primary series based RSI won't happen on every bar, a less than condition would happen on every bar. The order will still be submitted OnBarClose but that would be the bar close for the 1 minute series.

            For backtesting purposes you can specify the BarsInProgress with the entry as well to make sure the fill is placed on the more granular series:

            EnterShort(int barsInProgressIndex, int quantity, string signalName)


            Code:
            EnterShort(3, 6, "Short");

            Comment


              #7
              But I need the condition to excute on CrossBelow not on less than.
              is there anyway to make it possible?

              Comment


                #8
                Hello onlinebusiness,
                For example when I change if (BarsInProgress == 0) to if (BarsInProgress == 3) nothing really changes in my trades
                You are still referencing the same indicator so the same result will be true, you are just checking it more rapidly. If your BarsInProgress == 0 was a 10 minute chart and BarsInProgress == 1 is 1 minute the indicator value doesn't change, you just check its value 10 times instead of once because you moved it from BarsInProgress 0 to BarsInProgress 3.

                For the condition to be true for multiple 1 minute bars you need a condition that can remain true for multiple bars. CrossBelow is checking that the previous value was above the target and the current value is below the target. That only happens one time when the price crosses, once it has crossed it wont be true again.

                To be able to use a cross condition but then keep a condition true on the 1 minute series you would need to use a variable, once your cross condition becomes true set a variable to true. In the 1 minute BarsInProgress you can check if that variable is true to keep doing an action for each 1 minute bar. Once you no longer want to do the action you can set the variable to false.


                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Yesterday, 05:17 AM
                0 responses
                54 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                130 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                72 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                44 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                49 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X