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 timmbbo, Today, 08:59 AM
        1 response
        2 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by KennyK, 05-29-2017, 02:02 AM
        2 responses
        1,280 views
        0 likes
        Last Post marcus2300  
        Started by fernandobr, Today, 09:11 AM
        0 responses
        2 views
        0 likes
        Last Post fernandobr  
        Started by itrader46, Today, 09:04 AM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by bmartz, 03-12-2024, 06:12 AM
        5 responses
        33 views
        0 likes
        Last Post NinjaTrader_Zachary  
        Working...
        X