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

My strategy compiles but....

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

    My strategy compiles but....

    But when I execute a backtesting on it it says:

    **NT** Error on calling 'OnStartUp' method for strategy 'VARIACIONES/cd8b0830d54e49c0b9aea93bc2aced0d': Controlador no válido.

    Here is the code:

    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Indicator;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Strategy;
    #endregion

    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    /// <summary>
    /// Enter the description of your strategy here
    /// </summary>
    [Description("Enter the description of your strategy here")]
    public class VARIACIONES : Strategy
    {


    static int[] elem = new int[] { 0, 1 };
    static VARIACIONES p = new VARIACIONES();




    protected override void OnStartUp()
    {
    Console.Clear();
    int[,] hola = p.Creacion(2, 5);
    p.Inicializa(hola);

    p.Variaciones(hola);
    p.Dibuja(hola);
    }


    protected override void Initialize()
    {
    CalculateOnBarClose = true;
    }


    protected override void OnBarUpdate()
    {

    }
    //crea un array
    public int[,] Creacion(int Nelem, int Nposic)
    {
    int [,] hola = new int[(int)Math.Pow(Nelem,Nposic),Nposic];
    return hola;
    }
    //Inicializa todo el array a 0
    public int[,] Inicializa(int[,] Parray)
    {
    for (int i = Parray.GetLength(0) - 1; i >= 0; i--)
    {
    for (int j = Parray.GetLength(1)-1; j >= 0; j--)
    {
    Parray[i, j] = 0;
    }
    }
    return (Parray);
    }
    //Dibuja un todo el array
    public void Dibuja(int[,] Parray)
    {
    for (int i = Parray.GetLength(0) - 1; i >= 0; i--)
    {
    for (int j = Parray.GetLength(1)-1; j >= 0; j--)
    {
    Console.Write(Parray[i, j]);
    }
    Console.WriteLine();
    }
    Console.ReadKey();
    }
    //Genera las variaciones en el array/////////////////////////////////////
    public int[,] Variaciones(int[,] Parray)
    {
    //bool iguales=false;
    for(int i = Parray.GetLength(0)-1; i>=0; i--) //Desde la ultima fila hasta la primera
    {
    // iguales=false;
    if (i==Parray.GetLength(0)-1){} //EL INDICE PRINCIPAL Si es la ultima no hacer nada mantener la inicializacion
    else //Desde la posicion actual hasta la 31 buscar si se repite
    {
    for(int s = i+1;s<=Parray.GetLength(0)-1; s++)//Recorre todos las filas anteriores
    {
    int[] comod = new int[Parray.GetLength(1)]; //Array de ayuda donde guardaremos los datos de la fila t
    for (int t = Parray.GetLength(1) - 1; t >= 0; t--)//Consigo el array de la linea s el primer caso es el 31, lo guardo en comod
    {
    comod[t] = Parray[s, t];
    }
    //Comparamos la linea que estemos recorriendo con la linea i que es la que cambiaremos si es igual
    if (p.Iguales(comod, Parray, i)) //Si hemos encontrado una linea que es igual tenemos que crear otra random y volver a compararla
    {
    comod=p.GenerarRandom(elem, comod);
    Parray = p.Introducir(comod, Parray, i); //TENGO DUDAS QUE EL i Sea el correcto
    s = i; //Hemos cambiado la linea por otro aleatoria ahora debemos volver a comparar desde el principio
    }
    }

    }

    }
    return Parray;
    }
    // Introducir un array uniDimensional en un array Multidimensional
    public int[,] Introducir(int[] linea, int[,] multi, int fila)
    {
    for (int i = 0; i < linea.Length; i++)
    {
    multi[fila, i] = linea[i];
    }
    return multi;
    }
    //Generra un array de una dimension random()
    public int[] GenerarRandom(int[] elem, int[] nuevo)
    {
    Random rnd = new Random();
    for (int i = 0; i < nuevo.Length; i++)
    {
    int x = rnd.Next(0, elem.Length);
    nuevo[i] = elem[x];
    }
    return nuevo;
    }
    //Dibuja por pantalla un array unidimensional
    public void Dibuja(int[] Parray)
    {

    for (int j = Parray.Length - 1; j >= 0; j--)
    {
    Console.Write(Parray[j]);
    }
    Console.WriteLine();

    Console.ReadKey();
    }

    public int[] Devolver_Fila(int[] one, int[,] two, int n)
    {
    int j = one.Length;
    for (int i = 0; i < j; i++)
    { one[i] = two[n, i]; }
    return one;
    }

    public bool Iguales(int[] one, int[,] two, int n)
    {
    int j = one.Length;
    for (int i = 0; i < j; i++)
    {
    if (one[i] != two[n, i]) return (false);
    }
    return true;
    }




    }
    }


    Thank you

    Luis

    #2
    Hello! I have found that changing Console.Clear() for Console.Beep() It executes normally and the beep sounds.

    So It has to do with Console.Clear() I dont know why this methods worked for me yesterday..

    Comment


      #3
      Luis,

      Thank you for your post.

      You may want to use a Try-Catch statement for the Console.Clear()
      Cal H.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by love2code2trade, 04-17-2024, 01:45 PM
      4 responses
      31 views
      0 likes
      Last Post love2code2trade  
      Started by cls71, Today, 04:45 AM
      2 responses
      10 views
      0 likes
      Last Post eDanny
      by eDanny
       
      Started by proptrade13, Today, 11:06 AM
      0 responses
      5 views
      0 likes
      Last Post proptrade13  
      Started by kulwinder73, Today, 10:31 AM
      1 response
      10 views
      0 likes
      Last Post NinjaTrader_Erick  
      Started by RookieTrader, Today, 09:37 AM
      3 responses
      15 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X