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

Import Onnx model

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

    Import Onnx model

    I've googled with no avail.
    The search bar here does not return any results for ONNX.

    How might I import ONNX models from networks i've written in python into ninjascript ?

    I am not a C Sharp developer, I understand enough C Sharp to get by in ninjascript but not for adding any extensibility.

    Kine regards.


    #2
    Hello OllieFeraher,

    NinjaScript is C# language and does not natively support any kind of neural networks. If there is some C# library that can be used to load those models you may be able to reference that library using the NinjaScript editor and then use that. To be able to proceed with this type of task you would need to research this topic in external resources and see what C# items are available. If any you can learn about them and how to use them inside C# applications outside of NinjaTrader first, once you are comfortable coding using that library in C# you can try it in NinjaScript.

    JesseNinjaTrader Customer Service

    Comment


      #3
      Can I run anything in Ninjascript editor I would be able to in C Sharp?

      Thansk for you response. Do you know where I could start looking for the information I need?

      Comment


        #4
        Hello OllieFeraher,

        As long as the code is for C# .net framework 4.8 or less, yes.

        You would need to use a search engine line google, I am not aware of what ONNX models are to provide any context, I am not a python programmer. You can potentially search for something like "use onyx model in C#" or "execute onyx model from C# using python". You will have to do some research to see if any existing libraries exist or if you would need to develop some means to work with that.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Jesse View Post
          Hello OllieFeraher,

          NinjaScript is C# language and does not natively support any kind of neural networks. If there is some C# library that can be used to load those models you may be able to reference that library using the NinjaScript editor and then use that. To be able to proceed with this type of task you would need to research this topic in external resources and see what C# items are available. If any you can learn about them and how to use them inside C# applications outside of NinjaTrader first, once you are comfortable coding using that library in C# you can try it in NinjaScript.
          Like CNtK, Jesse? Make sense this code?


          using ninjatrader.ninjascript;
          using cntk;

          public class CNTKStrategy : NinjaScriptStrategy
          {
          private readonly LSTM _lstm;

          public override void OnInit()
          {
          // Configurar parâmetros
          var parameters = new LSTMParameters
          {
          // Intervalo de tempo dos dados de treinamento e teste
          Start = DateTime.Parse("2017-01-01"),
          End = DateTime.Parse("2022-12-31"),

          // Período de retorno
          ReturnPeriod = 60,

          // Função de ativação
          Activation = Activation.Tanh,

          // Taxa de aprendizado
          LearningRate = 0.01,
          };

          // Configurar rede neural
          _lstm = new CNTK.LSTM(parameters.Neurons);

          // Coletar dados históricos
          var historicalData = GetHistoricalData(parameters.Start, parameters.End);

          // Normalizar dados
          historicalData = Normalize(historicalData);

          // Dividir dados
          var trainingData = historicalData.Split(parameters.Start, parameters.End);
          var testData = historicalData.Split(parameters.End);

          // Treinar rede neural
          _lstm.Train(trainingData);

          // Fazer previsões
          var predictions = _lstm.Predict(testData);
          }

          public override void OnBarUpdate(Bar bar)
          {
          // Obter os 60 últimos candles de 1 dia
          var candles = GetHistoricalData(bar.Time - TimeSpan.FromDays(1), bar.Time);

          // Fazer previsão
          var prediction = _lstm.Predict(candles);

          // Tomar decisão de negociação
          if (prediction > 0)
          {
          // Comprar o ativo
          }
          else
          {
          // Vender o ativo
          }
          }

          private static DataFrame Normalize(DataFrame data)
          {
          var min = data.Close.Min();
          var max = data.Close.Max();

          for (int i = 0; i < data.Bars.Count; i++)
          {
          data.Bars[i].Close = (data.Bars[i].Close - min) / (max - min);
          }

          return data;
          }
          }

          Comment


            #6
            Originally posted by OllieFeraher View Post
            I've googled with no avail.
            The search bar here does not return any results for ONNX.

            How might I import ONNX models from networks i've written in python into ninjascript ?

            I am not a C Sharp developer, I understand enough C Sharp to get by in ninjascript but not for adding any extensibility.

            Kine regards.
            Try CNTK from .NET

            Comment


              #7
              Hello EvergreenGain,

              Thanks for your notes.

              Since we are not aware of how exactly the CNTK C# library functions and is intended to be used or know what the ONNX models are that OllieFeraher mentioned we cannot provide any context for if the CNTK library could be used to do the same things the ONNX model does. Further, we would not be able to assist with any code for using a C# library in NinjaScripts.

              You would need to research the library to understand exactly how it is intended to function and how to work with it. Once you understand how to work with it, you could utilize it within your NinjaScript.
              Brandon H.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Tirosovan, Today, 09:18 PM
              0 responses
              2 views
              0 likes
              Last Post Tirosovan  
              Started by jpkulkarni, 02-23-2024, 11:42 AM
              6 responses
              32 views
              0 likes
              Last Post jpkulkarni  
              Started by BrendoApex, Today, 12:22 AM
              2 responses
              14 views
              0 likes
              Last Post BrendoApex  
              Started by BrendoApex, Yesterday, 04:37 PM
              2 responses
              17 views
              0 likes
              Last Post BrendoApex  
              Started by wadams, Today, 08:47 PM
              0 responses
              3 views
              0 likes
              Last Post wadams
              by wadams
               
              Working...
              X