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

Modifying syntax logic for NT

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

    Modifying syntax logic for NT

    HI I am trying to write a logic to go long when last consecutive bars are bullish and about the same size.

    ChatGPT throws sample code but its not good for NT. Can someone help to convert the logic?




    double[] barSizes = new double[5];
    bool[] bullishBars = new bool[5];

    // Loop through the last 5 bars
    for (int i = 0; i < 5; i++)
    {
    // Calculate the size of each bar
    barSizes[i] = Math.Abs(Opens[i] - Closes[i]);

    // Determine if the bar is bullish
    bullishBars[i] = Closes[i] > Opens[i];
    }

    // Calculate the average size of the bars
    double averageSize = (barSizes[0] + barSizes[1] + barSizes[2] + barSizes[3] + barSizes[4]) / 5;

    // Define a tolerance for variation in bar sizes
    double tolerance = 0.01; // Adjust this value as needed

    // Check if all bar sizes are within the tolerance of the average size
    bool similarSizes = true;
    foreach (double size in barSizes)
    {
    if (Math.Abs(size - averageSize) > tolerance)
    {
    similarSizes = false;
    break;
    }
    }

    // Check if all bars are bullish
    bool allBullish = true;
    foreach (bool isBullish in bullishBars)
    {
    if (!isBullish)
    {
    allBullish = false;
    break;
    }
    }

    // If the last 5 bars were all bullish and of similar size, go long
    if (allBullish && similarSizes)
    {
    EnterLong();
    }
    }
    }
    }

    #2
    Hello tkaboris,

    Thanks for your post.

    From our experience at this time, ChatGPT is not quite adequate to generate valid compilable NinjaScripts that function as the user has intentioned. We often find that the generated code will call non-existent properties and methods, use improper classes or inheritance, and may have incorrect logic. We highly encourage that you create a new NinjaScript yourself using the NinjaScript Editor, and use the code generated by ChatGPT as more as suggestions and guide when coding the script yourself, than using the actual code generated.

    While It would not be within our support model to correct these scripts at user request, we would be happy to provide insight for any direct specific inquiries you may have if you would like to create this script yourself. Our support is able to assist with finding resources in our help guide as well as simple examples, and we are happy to assist with guiding you through the debugging process to assist you with understanding unexpected behavior.\

    To detect if the last 3 bars are up bars (green) you could create a condition that checks if Close[0] > Open[0] and checks if Close[1] > Open[1] and checks if Close[2] > Open[2].

    To detect uf the last 3 bars are down bars (red) you could create similar conditions using the less than comparison operator (<).

    For information about getting the number of ticks in a bar, see this forum thread: https://forum.ninjatrader.com/forum/...98#post1132098

    You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.
    Brandon H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by xepher101, 05-10-2024, 12:19 PM
    4 responses
    51 views
    0 likes
    Last Post xepher101  
    Started by DawnTreader, 05-08-2024, 05:58 PM
    22 responses
    82 views
    0 likes
    Last Post DawnTreader  
    Started by Mathias79, Today, 03:44 PM
    0 responses
    17 views
    0 likes
    Last Post Mathias79  
    Started by Austiner87, Today, 03:42 PM
    0 responses
    11 views
    0 likes
    Last Post Austiner87  
    Started by lorem, 04-25-2024, 09:18 AM
    19 responses
    84 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Working...
    X