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 Mestor, 03-10-2023, 01:50 AM
        16 responses
        388 views
        0 likes
        Last Post z.franck  
        Started by rtwave, 04-12-2024, 09:30 AM
        4 responses
        31 views
        0 likes
        Last Post rtwave
        by rtwave
         
        Started by yertle, Yesterday, 08:38 AM
        7 responses
        29 views
        0 likes
        Last Post yertle
        by yertle
         
        Started by bmartz, 03-12-2024, 06:12 AM
        2 responses
        22 views
        0 likes
        Last Post bmartz
        by bmartz
         
        Started by funk10101, Today, 12:02 AM
        0 responses
        7 views
        0 likes
        Last Post funk10101  
        Working...
        X