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

Funtion type in NinjaScript

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

    Funtion type in NinjaScript

    Hi, please, I would appreciate to Know how I can make a call to a function like in C to do the code more efficient. I mean that if I have the same code that repeat in various if, for example, I remember that in C you can describe a funtion where declare said code that could be use repeated times by the rest of the code.
    Below I show an example code where the if code is repeated and I would need to put it in a function that each if would call it.

    if (Tendencia == true)
    {
    if (Close[i] > Open[i])
    {
    alcista = true;
    Print("Datos de la vela " + i );
    Print("Apertura: " + Opens[0][i]);
    Print("Cierre: " + Closes[0][i]);
    Print("Máximo: " + Highs[0][i]);
    Print("Mínimo: " + Lows[0][i]);
    double high = Highs[0][i];
    if (high > maxHigh)
    {
    maxHigh = high;
    }
    double min = Lows[0][i];
    if (min < minLow)
    {
    minLow = min;
    }
    }
    }

    if (Tendencia == false)
    {
    if(Close[i] < Open[i])
    {
    bajista = true;
    Print("Datos de la vela " + i );
    Print("Apertura: " + Opens[0][i]);
    Print("Cierre: " + Closes[0][i]);
    Print("Máximo: " + Highs[0][i]);
    Print("Mínimo: " + Lows[0][i]);
    double high = Highs[0][i]; // Obtener el máximo de la vela actual
    if (high > maxHigh)
    {
    maxHigh = high; // Actualizar el máximo si encontramos un alto mayor
    }
    double min = Lows[0][i]; // Obtener el mínimo de la vela actual
    if (min < minLow)
    {
    minLow = min; // Actualizar el mínimo si encontramos un minimo menor
    }
    }
    }

    #2
    Yes, you can easily create additional methods in your Indicator or Strategy object. Read up on https://learn.microsoft.com/en-us/do...tructs/methods for many examples of how this works.
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      Hello BIOK.NT,

      Thanks for your post.

      QuantKey_Bruce has provided some great information on this topic.

      Please view the publicly available link they shared for information and examples on this topic.

      Below is a link to a forum thread which you also might find helpful.

      MySharedMethods: https://ninjatrader.com/support/forum/forum/ninjatrader-8/add-on-development/1051472-mysharedmethods-pass-highs-lows-instrument#post1051574
      Brandon H.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by poplagelu, Today, 05:00 AM
      0 responses
      3 views
      0 likes
      Last Post poplagelu  
      Started by fx.practic, 10-15-2013, 12:53 AM
      5 responses
      5,407 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Started by Shai Samuel, 07-02-2022, 02:46 PM
      4 responses
      98 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Started by DJ888, Yesterday, 10:57 PM
      0 responses
      8 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by MacDad, 02-25-2024, 11:48 PM
      7 responses
      160 views
      0 likes
      Last Post loganjarosz123  
      Working...
      X