• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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.
    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 superg3, Today, 12:33 AM
        0 responses
        3 views
        0 likes
        Last Post superg3
        by superg3
         
        Started by vppzepuq, Yesterday, 11:28 PM
        0 responses
        1 view
        0 likes
        Last Post vppzepuq  
        Started by Steve L, 05-25-2019, 10:04 PM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by mestril, 05-25-2019, 10:22 AM
        1 response
        14 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by hir04068, 05-25-2019, 09:29 PM
        7 responses
        21 views
        0 likes
        Last Post hir04068  
        Working...
        X