Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

What is efficient?

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

    What is efficient?

    hello,

    What is relatively more efficient?

    Code:
    if(XYZ)
    {ABC = true}
    
    if(BarsInProgress = 24)
    (if ABC = true & Close>0) {EnterLong}
    
    if(BarsInProgress = 10)
    (if ABC = true & Close>0) {EnterLong}
    vs

    Code:
    If(XYZ)
    {ABC= true}
    
    If(ABC = true && Closes[24][0] > 0) {EnterLong(24,true,Quantity.........}
    
    If(ABC = true && Closes[10][0] > 0) {EnterLong(10,true,Quantity.........}
    Last edited by staycool3_a; 09-13-2018, 01:22 PM.

    #2
    Hello staycool3_a,

    Thanks for your question.

    Using a BarsInProgress check will limit operations to occur only when that Data Series is iterating. If you do not use BarsInProgress checks, those operations will take place on every BarsInProgress iteration.

    Limiting your operations so they only occur when necessary would be the most efficient way to design your code.

    More information on setting up BarsInProgress checks along with a complete guide for working with Multi Time Frame NinjaScripts can be found below.

    Event Driven OnBarUpdate (Multi Time Frame and Instruments) - https://ninjatrader.com/support/help...arupdateMethod

    Also as a tip, I may suggest formatting your code so your curly braces are on separate lines. This can help with readability and can help us to better follow what you are programming. Online tools like Code Beautify can be used to quickly format code.

    CodeBeautify - https://codebeautify.org/

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

    Comment


      #3
      Originally posted by NinjaTrader_Jim View Post
      Hello staycool3_a,

      Thanks for your question.

      Using a BarsInProgress check will limit operations to occur only when that Data Series is iterating. If you do not use BarsInProgress checks, those operations will take place on every BarsInProgress iteration.

      Limiting your operations so they only occur when necessary would be the most efficient way to design your code.

      More information on setting up BarsInProgress checks along with a complete guide for working with Multi Time Frame NinjaScripts can be found below.

      Event Driven OnBarUpdate (Multi Time Frame and Instruments) - https://ninjatrader.com/support/help...arupdateMethod

      Also as a tip, I may suggest formatting your code so your curly braces are on separate lines. This can help with readability and can help us to better follow what you are programming. Online tools like Code Beautify can be used to quickly format code.

      CodeBeautify - https://codebeautify.org/

      Please let us know if we can be of further assistance.
      Thank you Jim. I will try to beautify my code in the future.

      I don't really understand iteration concept. So i'm just going to stick to the option without doing the barsinprogress check and directly indexing
      Last edited by staycool3_a; 09-13-2018, 11:05 PM.

      Comment


        #4
        Originally posted by staycool3_a View Post
        hello,

        What is relatively more efficient?

        Code:
        if(XYZ)
        {ABC = true}
        
        if(BarsInProgress = 24)
        (if ABC = true & Close>0) {EnterLong}
        
        if(BarsInProgress = 10)
        (if ABC = true & Close>0) {EnterLong}
        vs

        Code:
        If(XYZ)
        {ABC= true}
        
        If(ABC = true && Closes[24][0] > 0) {EnterLong(24,true,Quantity.........}
        
        If(ABC = true && Closes[10][0] > 0) {EnterLong(10,true,Quantity.........}
        Avoid redundancy
        Code:
        if (XYZ) {
          ABC = true;
        }
        
        if (ABC) {
          if ((BarsInProgress == 24 || BarsInProgress == 10) && Close[0] > 0) EnterLong();
        }

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        44 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        124 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        65 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