Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

how to use AddDataSeries(BarsPeriodType.Tick, 1)?

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

    how to use AddDataSeries(BarsPeriodType.Tick, 1)?

    Hello, I need your assistance.

    I'm currently using the following line of code in my strategy:
    csharp

    Code:
    Calculate = Calculate.OnEachTick;
    AddDataSeries(BarsPeriodType.Tick, 1);

    Within my strategy, I require the use of both "OnEachTick" and "OnBarClose" calculations. Is there a way to achieve this combination?

    Furthermore, when I'm inside the "OnBarClose" method, how can I leverage the prior use of AddDataSeries(BarsPeriodType.Tick, 1) to perform calculations as if I were in the "OnEachTick" context?

    I genuinely appreciate the time you dedicate to helping us.

    #2
    Hello aekzof,

    Thank you for your post.

    We have a helpful reference sample that demonstrates how you could separate logic to calculate either on bar close or on each tick. That sample may be found here:
    Essentially, if you want an action to only occur on bar close, you would need to check in the condition if IsFirstTickOfBar is true:
    Otherwise, OnBarUpdate() will be called on each tick whether you add a 1 tick data series or not; you do not need to add a 1 tick series if you are using Calculate.OnEachTick. For more information about the Calculate property:If you do plan to call AddDataSeries() and work with multiple different series, I suggest reviewing the information on the following page about multi time frame & instrument scripts:Please let us know if we may be of further assistance.

    Comment


      #3
      Hello
      Thank you for your response.

      Indeed, my question is based on a script for which I'm unable to find a solution when using Calculate.OnBarClose; this function works without any issues.

      However, unfortunately, this script isn't functioning correctly. It appears that there are too many orders being executed. This is normal since it counts every tick as a new bar.

      I've tried using IsFirstTickOfBar and MarketPosition to perform a test, but it didn't work. Perhaps I used them incorrectly?

      My objective is to work with Calculate.OnEachTick to perform other calculations and count the bars using this calculation mode.

      Attached, you'll find my script CounterBullishBearish. I would greatly appreciate any solution you could provide. Thank you very much for your assistance.



      Attached Files

      Comment


        #4
        Hello aekzof,

        Thank you for your reply.

        I suggest enabling TraceOrders to get output information related to orders being submitted, canceled, rejected, filled, etc. This is a property that may be set in OnStateChange() when State == State.SetDefaults. For more information:
        Additionally, you can add print statements to your script to understand what values are being used in your conditions and how frequently your variables are being updated or orders are being submitted. For more information on using Prints to debug a script:You may need to consider that when calculating on each tick, a condition such as Close[0] > Open[0] or Close[0] < Open[0] could be true for several ticks in a row; I suspect your counters are being updated multiple times in the same bar and reaching the value of 4 to trigger a long or short order. Prints will confirm this behavior from your script and can help you identify what might need to be changed as well as help you to test out how the behavior changes with each update you make to your conditions and actions in the logic.

        Please let us know if we may be of further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        50 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        126 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        69 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        42 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X