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

How to make purchases and sales at the close of the bar and update the stop in ticks

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

    #31
    Thanks ChelseaB, I would like to try to add the prints all at once.
    Could you explain to me with a brief example how to create it?

    Comment


      #32
      Hello jmarcano,

      The same way you have been doing it.

      Make a print for:
      Code:
      && (Position.MarketPosition == MarketPosition.Flat)
      Then make a print for:
      Code:
      && (VolumeUpDown1.UpVolume[0] > 1300)
      Then make a print for:
      Code:
      && (CrossAbove(Close, Swing1.SwingHigh, 1))
      Then make a print for:
      [CODE]&& (Close[0] > EMA1[0])
      Then make a print for:
      Code:
      && (Operaciones < TradeDay)
      Then make a print for:
      Code:
      && (Long == true))

      You've made one print correctly so far.
      Code:
      Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " < Cierre.TimeOfDay: " + Cierre.TimeOfDay.ToString());
      Keep doing this for the rest of the conditions in the condition set.
      If you get stuck, let me know.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #33
        Good afternoon Chelsea, sending the file with the print output
        Attached Files
        Last edited by jmarcano; 10-12-2020, 04:59 PM.

        Comment


          #34
          Thanks ChelseaB, would it be something like this? I'm not very clear on how to declare this condition?

          && (CrossAbove (Close, Swing1.SwingHigh, 1))

          This is how I keep the code

          // Long
          if (IsFirstTickOfBar
          && (Times[0][0].TimeOfDay >= Apertura.TimeOfDay)
          && (Times[0][0].TimeOfDay < Cierre.TimeOfDay)
          && (Position.MarketPosition == MarketPosition.Flat)
          && (VolumeUpDown1.UpVolume[0] > 1300)
          && (CrossAbove(Close, Swing1.SwingHigh, 1))
          && (Close[0] > EMA1[0])
          && (Operaciones < TradeDay)
          && (Long == true))
          {
          Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " => Apertura.TimeOfDay: " + Apertura.TimeOfDay.ToString());
          Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " < Cierre.TimeOfDay: " + Cierre.TimeOfDay.ToString());
          Print("\r\n" + Time[0].ToString() + " Position.MarketPosition: " + Position.MarketPosition.ToString() + " == MarketPosition.Flat: " + MarketPosition.Flat.ToString());
          Print("\r\n" + Time[0].ToString() + " VolumeUpDown1.UpVolume: " + VolumeUpDown1.UpVolume.ToString() + " > 1300: " + 1300.ToString());
          // Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " < Cierre.TimeOfDay: " + Cierre.TimeOfDay.ToString());
          Print("\r\n" + Time[0].ToString() + " Close: " + Close.ToString() + " > EMA1: " + EMA1.ToString());
          Print("\r\n" + Time[0].ToString() + " Operaciones: " + Operaciones.ToString() + " < TradeDay: " + TradeDay.ToString());
          Print("\r\n" + Time[0].ToString() + " Long: " + Long.ToString() + " == true: " + true.ToString());
          }

          Comment


            #35
            Hello jmarcano,

            It is important that we see the print (on the first tick of a bar) for every bar and not just when the condition is true.

            This is the reason we are using the print above and out side of the condition that triggers the action.

            We are choosing to only print on the first tick of a new bar, to cut down on the amount of prints.

            This means, you want to print the values outside of the condition set triggering the action.

            Do not also add the conditions to the print condition, because then we won't see prints for every bar. We will only see prints when the condition is true, which means we cannot get information when the conditon is not true.

            We are only adding prints, we are not changing the condition.

            Set the print the condition back to:
            if (IsFirstTickOfBar)


            Here is an example with the first three prints added:
            Code:
            if (IsFirstTickOfBar)
            {
            Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " => Apertura.TimeOfDay: " + Apertura.TimeOfDay.ToString());
            Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " < Cierre.TimeOfDay: " + Cierre.TimeOfDay.ToString());
            Print("\r\n" + Time[0].ToString() + " Position.MarketPosition: " + Position.MarketPosition.ToString() + " == MarketPosition.Flat: " + MarketPosition.Flat.ToString());
            }
            If this is the first tick the bar, print the time, print the values being used in the condition. On every bar, not just when the condition is true.

            Try printing this and let me know if this is not clarifying why we are using prints to see what values are being compared in the condition.

            We are trying to see if your condition values are all evaluating as true.

            If the condition set evaluates as true the action is triggered.

            If the condition set evaluates as false, the action is not triggered.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #36
              Good morning Chelsea, thanks for your answer, I send you the exit print
              Attached Files

              Comment


                #37
                I send the code with the impressions added.


                protected override void OnBarUpdate()
                {



                // Reset stop
                //if ((Position.MarketPosition == MarketPosition.Flat))
                //{
                //SetStopLoss(CalculationMode.Ticks, Stop);
                //}

                // Long
                if (IsFirstTickOfBar
                && (Times[0][0].TimeOfDay >= Apertura.TimeOfDay)
                && (Times[0][0].TimeOfDay < Cierre.TimeOfDay)
                && (Position.MarketPosition == MarketPosition.Flat)
                && (VolumeUpDown1.UpVolume[0] > 1300)
                && (CrossAbove(Close, Swing1.SwingHigh, 1))
                && (Close[0] > EMA1[0])
                && (Operaciones < TradeDay)
                && (Long == true))

                {
                Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " => Apertura.TimeOfDay: " + Apertura.TimeOfDay.ToString());
                Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " < Cierre.TimeOfDay: " + Cierre.TimeOfDay.ToString());
                Print("\r\n" + Time[0].ToString() + " Position.MarketPosition: " + Position.MarketPosition.ToString() + " == MarketPosition.Flat: " + MarketPosition.Flat.ToString());
                Print("\r\n" + Time[0].ToString() + " VolumeUpDown1.UpVolume: " + VolumeUpDown1.UpVolume.ToString() + " > 1300: " + 1300.ToString());
                // Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " < Cierre.TimeOfDay: " + Cierre.TimeOfDay.ToString());
                Print("\r\n" + Time[0].ToString() + " Close: " + Close.ToString() + " > EMA1: " + EMA1.ToString());
                Print("\r\n" + Time[0].ToString() + " Operaciones: " + Operaciones.ToString() + " < TradeDay: " + TradeDay.ToString());
                Print("\r\n" + Time[0].ToString() + " Long: " + Long.ToString() + " == true: " + true.ToString());
                }
                Last edited by jmarcano; 10-13-2020, 09:17 AM.

                Comment


                  #38
                  Hello jmarcano:

                  Hmm, I don't think I am communicating well that print should not be in the condition we are investigating, or what we are trying to accomplish here.

                  We need to know the values used in the condition, when the condition is not true.

                  If you put the print in the condition set, we won't get any prints when the condition is not true.

                  Would you like to schedule a phone call to discuss why are using prints?

                  Change:
                  Code:
                  // Reset stop
                  //if ((Position.MarketPosition == MarketPosition.Flat))
                  //{
                  //SetStopLoss(CalculationMode.Ticks, Stop);
                  //}
                  
                  // Long
                  if (IsFirstTickOfBar
                  && (Times[0][0].TimeOfDay >= Apertura.TimeOfDay)
                  && (Times[0][0].TimeOfDay < Cierre.TimeOfDay)
                  && (Position.MarketPosition == MarketPosition.Flat)
                  && (VolumeUpDown1.UpVolume[0] > 1300)
                  && (CrossAbove(Close, Swing1.SwingHigh, 1))
                  && (Close[0] > EMA1[0])
                  && (Operaciones < TradeDay)
                  && (Long == true))
                  
                  {
                  Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " => Apertura.TimeOfDay: " + Apertura.TimeOfDay.ToString());
                  Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " < Cierre.TimeOfDay: " + Cierre.TimeOfDay.ToString());
                  Print("\r\n" + Time[0].ToString() + " Position.MarketPosition: " + Position.MarketPosition.ToString() + " == MarketPosition.Flat: " + MarketPosition.Flat.ToString());
                  Print("\r\n" + Time[0].ToString() + " VolumeUpDown1.UpVolume: " + VolumeUpDown1.UpVolume.ToString() + " > 1300: " + 1300.ToString());
                  // Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " < Cierre.TimeOfDay: " + Cierre.TimeOfDay.ToString());
                  Print("\r\n" + Time[0].ToString() + " Close: " + Close.ToString() + " > EMA1: " + EMA1.ToString());
                  Print("\r\n" + Time[0].ToString() + " Operaciones: " + Operaciones.ToString() + " < TradeDay: " + TradeDay.ToString());
                  Print("\r\n" + Time[0].ToString() + " Long: " + Long.ToString() + " == true: " + true.ToString());
                  }
                  To:
                  Code:
                  if (IsFirstTickOfBar)
                  {
                  Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " => Apertura.TimeOfDay: " + Apertura.TimeOfDay.ToString());
                  Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " < Cierre.TimeOfDay: " + Cierre.TimeOfDay.ToString());
                  Print("\r\n" + Time[0].ToString() + " Position.MarketPosition: " + Position.MarketPosition.ToString() + " == MarketPosition.Flat: " + MarketPosition.Flat.ToString());
                  Print("\r\n" + Time[0].ToString() + " VolumeUpDown1.UpVolume: " + VolumeUpDown1.UpVolume.ToString() + " > 1300: " + 1300.ToString());
                  // Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " < Cierre.TimeOfDay: " + Cierre.TimeOfDay.ToString());
                  Print("\r\n" + Time[0].ToString() + " Close: " + Close.ToString() + " > EMA1: " + EMA1.ToString());
                  Print("\r\n" + Time[0].ToString() + " Operaciones: " + Operaciones.ToString() + " < TradeDay: " + TradeDay.ToString());
                  Print("\r\n" + Time[0].ToString() + " Long: " + Long.ToString() + " == true: " + true.ToString());
                  }
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #39
                    Sorry, I understood you, I send you updated output
                    Attached Files

                    Comment


                      #40
                      I send the code

                      protected override void OnBarUpdate()
                      {


                      if (IsFirstTickOfBar)
                      {
                      Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " => Apertura.TimeOfDay: " + Apertura.TimeOfDay.ToString());
                      Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " < Cierre.TimeOfDay: " + Cierre.TimeOfDay.ToString());
                      Print("\r\n" + Time[0].ToString() + " Position.MarketPosition: " + Position.MarketPosition.ToString() + " == MarketPosition.Flat: " + MarketPosition.Flat.ToString());
                      Print("\r\n" + Time[0].ToString() + " VolumeUpDown1.UpVolume: " + VolumeUpDown1.UpVolume.ToString() + " > 1300: " + 1300.ToString());
                      // Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " < Cierre.TimeOfDay: " + Cierre.TimeOfDay.ToString());
                      Print("\r\n" + Time[0].ToString() + " Close: " + Close.ToString() + " > EMA1: " + EMA1.ToString());
                      Print("\r\n" + Time[0].ToString() + " Operaciones: " + Operaciones.ToString() + " < TradeDay: " + TradeDay.ToString());
                      Print("\r\n" + Time[0].ToString() + " Long: " + Long.ToString() + " == true: " + true.ToString());
                      }

                      Comment


                        #41
                        Hello jmarcano,

                        Great job removing that.

                        We also have a few prints that need to be corrected so that they match what you have written into the condition.

                        -For the condition: "&& (VolumeUpDown1.UpVolume[0] > 1300)"
                        Change:
                        Code:
                        Print("\r\n" + Time[0].ToString() + " VolumeUpDown1.UpVolume: " + VolumeUpDown1.[U]UpVolume[/U].ToString() + " > 1300: " + 1300.ToString());
                        To:
                        Code:
                        Print("\r\n" + Time[0].ToString() + " VolumeUpDown1.UpVolume[0]: " + VolumeUpDown1.UpVolume[B][0][/B].ToString() + " > 1300");

                        -For the condition: "&& (CrossAbove(Close, Swing1.SwingHigh, 1))"
                        Change:
                        Code:
                        // Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " < Cierre.TimeOfDay: " + Cierre.TimeOfDay.ToString());
                        See the example in the forum post on how to use prints to look for a cross above:
                        https://ninjatrader.com/support/foru...121#post791121
                        To:
                        Code:
                        Print("\r\n" + Time[0].ToString() + " Close[1]: " + Close[1].ToString() + " <  Swing1.SwingHigh[1]: " + Swing1.SwingHigh[1].ToString() + " && " + " Close[0]: " + Close[0].ToString() + " >  Swing1.SwingHigh[0]: " + Swing1.SwingHigh[0].ToString());

                        -For the condition: "&& (Close[0] > EMA1[0])"
                        Change:
                        Code:
                        Print("\r\n" + Time[0].ToString() + " Close: " + Close.ToString() + " > EMA1: " + EMA1.ToString());
                        To:
                        Code:
                        Print("\r\n" + Time[0].ToString() + " Close[B][0][/B]: " + Close[B][0][/B].ToString() + " > EMA1[B][0][/B]: " + EMA1[B][0][/B].ToString());

                        With this information we have so far, we can see we are looking for bar between 9:35 and 11:30.

                        Here is the first print after 9:35.

                        10/8/2020 9:36:00 AM Times[0][0].TimeOfDay: 09:36:00 => Apertura.TimeOfDay: 09:35:00

                        10/8/2020 9:36:00 AM Times[0][0].TimeOfDay: 09:36:00 < Cierre.TimeOfDay: 11:30:00

                        10/8/2020 9:36:00 AM Position.MarketPosition: Flat == MarketPosition.Flat: Flat

                        10/8/2020 9:36:00 AM VolumeUpDown1.UpVolume: NinjaTrader.NinjaScript.Series`1[System.Double] > 1300: 1300

                        10/8/2020 9:36:00 AM Close: NinjaTrader.NinjaScript.PriceSeries > EMA1: EMA(NQ 12-20 (2 Minute),20)

                        10/8/2020 9:36:00 AM Operaciones: 0 < TradeDay: 1

                        10/8/2020 9:36:00 AM Long: True == true: True
                        We can see the position is flat, that the Operaciones is less than 1, and Long is true.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #42
                          I send you updated output
                          Attached Files
                          Last edited by jmarcano; 10-13-2020, 10:28 AM.

                          Comment


                            #43
                            I send the updated code, I am really very grateful for all the explanations that ChelseaB is giving me

                            protected override void OnBarUpdate()
                            {


                            if (IsFirstTickOfBar)
                            {
                            Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " => Apertura.TimeOfDay: " + Apertura.TimeOfDay.ToString());
                            Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " < Cierre.TimeOfDay: " + Cierre.TimeOfDay.ToString());
                            Print("\r\n" + Time[0].ToString() + " Position.MarketPosition: " + Position.MarketPosition.ToString() + " == MarketPosition.Flat: " + MarketPosition.Flat.ToString());
                            Print("\r\n" + Time[0].ToString() + " VolumeUpDown1.UpVolume[0]: " + VolumeUpDown1.UpVolume[0].ToString() + " > 1300");
                            Print("\r\n" + Time[0].ToString() + " Close[1]: " + Close[1].ToString() + " < Swing1.SwingHigh[1]: " + Swing1.SwingHigh[1].ToString() + " && " + " Close[0]: " + Close[0].ToString() + " > Swing1.SwingHigh[0]: " + Swing1.SwingHigh[0].ToString());
                            Print("\r\n" + Time[0].ToString() + " Close[0]: " + Close[0].ToString() + " > EMA1[0]: " + EMA1[0].ToString());
                            Print("\r\n" + Time[0].ToString() + " Operaciones: " + Operaciones.ToString() + " < TradeDay: " + TradeDay.ToString());
                            Print("\r\n" + Time[0].ToString() + " Long: " + Long.ToString() + " == true: " + true.ToString());
                            }

                            Comment


                              #44
                              Hello jmarcano,

                              Fantastic, you made it!

                              But your output file is a little short.

                              We don't have the output from after 9:35 and before 11:30.

                              I am only seeing in the file provided:
                              10/13/2020 12:22:00 PM Times[0][0].TimeOfDay: 12:22:00 => Apertura.TimeOfDay: 09:35:00

                              10/13/2020 12:22:00 PM Times[0][0].TimeOfDay: 12:22:00 < Cierre.TimeOfDay: 11:30:00

                              10/13/2020 12:22:00 PM Position.MarketPosition: Flat == MarketPosition.Flat: Flat

                              10/13/2020 12:22:00 PM VolumeUpDown1.UpVolume[0]: 1 > 1300

                              10/13/2020 12:22:00 PM Close[1]: 12080.25 < Swing1.SwingHigh[1]: 12181.75 && Close[0]: 12079.75 > Swing1.SwingHigh[0]: 12181.75

                              10/13/2020 12:22:00 PM Close[0]: 12079.75 > EMA1[0]: 12114.8475789235

                              10/13/2020 12:22:00 PM Operaciones: 0 < TradeDay: 1

                              10/13/2020 12:22:00 PM Long: True == true: True
                              Chelsea B.NinjaTrader Customer Service

                              Comment


                                #45
                                If chelseaB, I had to cut it because of the size, it would not let me send them, I send another reduced one to verify

                                Attached Files

                                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