Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    JimNinjaTrader Customer Service

    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 GussJ, 03-04-2020, 03:11 PM
        11 responses
        3,228 views
        0 likes
        Last Post xiinteractive  
        Started by andrewtrades, Today, 04:57 PM
        1 response
        13 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by chbruno, Today, 04:10 PM
        0 responses
        7 views
        0 likes
        Last Post chbruno
        by chbruno
         
        Started by josh18955, 03-25-2023, 11:16 AM
        6 responses
        440 views
        0 likes
        Last Post Delerium  
        Started by FAQtrader, Today, 03:35 PM
        0 responses
        12 views
        0 likes
        Last Post FAQtrader  
        Working...
        X