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

multiple AddDataSeries

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

    multiple AddDataSeries

    I want to have multiple data series

    with the same indicator in each temporality​ (EZKnube) That indicator has some plots, but the one that interests me is one called Trend. value 1 (buy) and -1 (sell) (attached image)​. I am activating the strategy in 30 seconds​

    error:I cannot access the values ​​of the EZKNUBE indicator in the time frame 60 min and 15 min​

    Click image for larger version

Name:	Captura de pantalla 2024-04-30 165313.png
Views:	47
Size:	69.7 KB
ID:	1301609



    else if (State == State.Configure)
    {
    // Agregar la serie de datos de 60 minutos
    AddDataSeries(Data.BarsPeriodType.Minute, 60);
    AddDataSeries(Data.BarsPeriodType.Minute, 15);

    }
    else if (State == State.DataLoaded)
    {
    // Inicializar EZKnube1_60Min solo una vez con la serie de datos de 60 minutos
    if (BarsInProgress == 1)
    {
    EZKnube1_60Min = EZKnube(Close, EZKTriggerLine.EMA, 18, EZKSmothTrendLine.EMA, 18, "", true, true, 10, Brushes.Aqua, Brushes.Orange);
    EZKnube1_15Min = EZKnube(Close, EZKTriggerLine.EMA, 18, EZKSmothTrendLine.EMA, 18, "", true, true, 10, Brushes.Aqua, Brushes.Orange);
    }
    }​

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 0)
    return;

    double trendValue60Min = EZKnube1_60Min.Trend[0];
    double trendValue15Min = EZKnube1_15Min.Trend[0];

    // Imprimir los valores de tendencia en la consola de NinjaTrader
    Print("Trend 60 Min Value: " + trendValue60Min);
    Print("Trend 15 Min Value: " + trendValue15Min);

    // Si la tendencia es -1 en todas las temporalidades, pintar en rojo
    if (trendValue60Min == -1 && trendValue15Min == -1)
    {
    BackBrushAll = Brushes.Red;
    }
    // Si la tendencia es 1 en todas las temporalidades, pintar en verde
    else if (trendValue60Min == 1 && trendValue15Min == 1)
    {
    BackBrushAll = Brushes.Green;
    }
    }​


    Click image for larger version

Name:	Captura de pantalla 2024-04-30 165228.png
Views:	45
Size:	43.7 KB
ID:	1301610Click image for larger version

Name:	Captura de pantalla 2024-04-30 165102.png
Views:	48
Size:	36.2 KB
ID:	1301611

    #2
    Hello leojimenezp,

    For this type of use case I would suggest to initially use the straetgy builder so that your indicator instances get set up correctly and have the correct data series specified. This also heavily depends on how your indicator was created and if it was intentionally made to support using an Input.

    The following code is not valid in OnStateChange:
    Code:
    // Inicializar EZKnube1_60Min solo una vez con la serie de datos de 60 minutos
    if (BarsInProgress == 1)
    {​
    
    }
    To configure indicators in OnStateChange you need to remove that condition so it looks like this:

    Code:
    else if (State == State.DataLoaded)
    {
    EZKnube1_60Min = EZKnube(Close, EZKTriggerLine.EMA, 18, EZKSmothTrendLine.EMA, 18, "", true, true, 10, Brushes.Aqua, Brushes.Orange);
    EZKnube1_15Min = EZKnube(Close, EZKTriggerLine.EMA, 18, EZKSmothTrendLine.EMA, 18, "", true, true, 10, Brushes.Aqua, Brushes.Orange);
    }​
    To create an instance that uses a secondary series you need to supply the correct Close series:

    Code:
    This would be for the primary
    EZKnube1_60Min = EZKnube(Close, EZKTriggerLine.EMA, 18, EZKSmothTrendLine.EMA, 18, "", true, true, 10, Brushes.Aqua, Brushes.Orange);
    ​
    This would be for the secondary
    EZKnube1_60Min = EZKnube(Closes[1], EZKTriggerLine.EMA, 18, EZKSmothTrendLine.EMA, 18, "", true, true, 10, Brushes.Aqua, Brushes.Orange);
    ​
    ​
    If you instead use the builder to add the series and then form conditions using the indicators you can select the series to be used with the indicator instance and that will make sure you have all the variables needed to support your conditions and that they point to the correct secondary series.
    JesseNinjaTrader Customer Service

    Comment


      #3

      I'm sorry I had put that as a test​.

      if (BarsInProgress == 1)
      {​ }​


      1. I have not found how in strategy builder I can add several data series​. you have an example


      2. The error is that I cannot access the PLOTS called TREND of the indicator in the 60min and 15 min time frame. I execute the strategy in 30 seconds.
      In the attached image you can see that the graph indicator only takes 30sec. and changes color when the PLOTS of the 30s change, but the condition is that it validates the PLOTS: TREND
      in 60 and 15 minutes​


      Click image for larger version

Name:	Captura de pantalla 2024-05-01 100804.png
Views:	28
Size:	24.2 KB
ID:	1301705


      Code:
      [B]if (trendValue60Min == -1 && trendValue15Min == -1)[/B]
      {
      BackBrushAll = Brushes.Red; //     I should paint in the 30 sec, validating the 60 and 15 min
      
      }
      
      [B]else if (trendValue60Min == 1 && trendValue15Min == 1)[/B]
      {
      BackBrushAll = Brushes.Green; //      I should paint in the 30 sec, validating the 60 and 15 min
      }​​

      Click image for larger version

Name:	Captura de pantalla 2024-05-01 095401.png
Views:	23
Size:	156.9 KB
ID:	1301704
      Attached Files

      Comment


        #4
        Hello leojimenezp,

        In the builder you can use the additional data tab to add secondary series, those are then selectable when you configure the indicator in a condition as its series.

        https://ninjatrader.com/support/help...standingTheAdd itrionalDataScreen

        In the code that you already provided you are accessing the Trend plot:

        Code:
        double trendValue60Min = EZKnube1_60Min.Trend[0];
        double trendValue15Min = EZKnube1_15Min.Trend[0];


        The indicators you have added are both for the primary series though so you would have to supply the correct Close series to the indicator for which it should be using. The builder is the easiest way to do that so the correct syntax is generated. You would first add the secondary series and then in the condition builder screen make a condition using the indicators you wanted. Then click View Code, that will show the generated code including the additional series.

        The condition that you had in OnStateChange will prevent the indicators from being created because BarsInProgress is a property that is only updated in OnBarUpdate, it will not be 1 in OnStateChange. After removing that you can set up the indicators you want in State.DataLoaded and then use them in OnBarUpdate.

        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by AlphaOptions, 06-18-2013, 08:24 AM
        5 responses
        2,168 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by JTizz, 04-08-2020, 08:59 AM
        2 responses
        211 views
        0 likes
        Last Post betsuni_123  
        Started by bortz, 11-06-2023, 08:04 AM
        53 responses
        2,023 views
        0 likes
        Last Post muchacha  
        Started by NickyD, 10-26-2023, 04:41 PM
        5 responses
        192 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by janio973, Yesterday, 07:24 PM
        4 responses
        26 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X