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

    #46
    Hello jmarcano,

    The extra spaces came because my example had the extra spaces. You could condense lines by removing the extra spaces.

    Also, as you saw in the demonstration of using prints video you have watched, be sure to clear the output window before reloading the script.

    Code:
    if (IsFirstTickOfBar)
    {
    Print("\r\n" + Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " => Apertura.TimeOfDay: " + Apertura.TimeOfDay.ToString());
    Print(Time[0].ToString() + " Times[0][0].TimeOfDay: " + Times[0][0].TimeOfDay.ToString() + " < Cierre.TimeOfDay: " + Cierre.TimeOfDay.ToString());
    Print(Time[0].ToString() + " Position.MarketPosition: " + Position.MarketPosition.ToString() + " == MarketPosition.Flat: " + MarketPosition.Flat.ToString());
    Print(Time[0].ToString() + " VolumeUpDown1.UpVolume[0]: " + VolumeUpDown1.UpVolume[0].ToString() + " > 1300");
    Print(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(Time[0].ToString() + " Close[0]: " + Close[0].ToString() + " > EMA1[0]: " + EMA1[0].ToString());
    Print(Time[0].ToString() + " Operaciones: " + Operaciones.ToString() + " < TradeDay: " + TradeDay.ToString());
    Print(Time[0].ToString() + " Long: " + Long.ToString() + " == true: " + true.ToString());
    }
    The last step is to enable TraceOrders so that we can see if an order may have been submitted but ignored or cancelled instead of filled.

    In OnStateChange in the action block for State.Configure set
    Code:
    TraceOrders = true;

    Taking a look at the output you have after 9:35
    Code:
    10/9/2020 9:36:00 AM Times[0][0].TimeOfDay: 09:36:00 => Apertura.TimeOfDay: 09:35:00
    10/9/2020 9:36:00 AM Times[0][0].TimeOfDay: 09:36:00 < Cierre.TimeOfDay: 11:30:00
    10/9/2020 9:36:00 AM Position.MarketPosition: Flat == MarketPosition.Flat: Flat
    10/9/2020 9:36:00 AM VolumeUpDown1.UpVolume[0]: 4890 > 1300
    10/9/2020 9:36:00 AM Close[1]: 11607 < Swing1.SwingHigh[1]: 11616 && Close[0]: [B]11610.75 >[/B] Swing1.SwingHigh[0]: [B]11616[/B]
    10/9/2020 9:36:00 AM Close[0]: 11610.75 > EMA1[0]: 11606.932402745
    10/9/2020 9:36:00 AM Operaciones: 0 < TradeDay: 1
    10/9/2020 9:36:00 AM Long: True == true: True
    The one that stands out is the cross above.
    11610.75 is not greater than11616.

    Are you seeing any specific bars where all of the conditions are true?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #47
      Thanks Chelsea, I send new print output, Yes in a bar today at 10:24 am

      I already activated the option

      Calculate = Calculate.OnEachTick;
      EntriesPerDirection = 1;
      EntryHandling = EntryHandling.AllEntries;
      IsExitOnSessionCloseStrategy = true;
      ExitOnSessionCloseSeconds = 30;
      IsFillLimitOnTouch = false;
      MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
      OrderFillResolution = OrderFillResolution.Standard;
      Slippage = 0;
      StartBehavior = StartBehavior.WaitUntilFlat;
      TimeInForce = TimeInForce.Day;
      TraceOrders = true;
      RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
      StopTargetHandling = StopTargetHandling.PerEntryExecution;

      Attached Files

      Comment


        #48
        specific bars where all of the conditions are true today



        10/13/2020 10:24:00 AM Times[0][0].TimeOfDay: 10:24:00 => Apertura.TimeOfDay: 09:35:00

        10/13/2020 10:24:00 AM Times[0][0].TimeOfDay: 10:24:00 < Cierre.TimeOfDay: 11:30:00

        10/13/2020 10:24:00 AM Position.MarketPosition: Flat == MarketPosition.Flat: Flat

        10/13/2020 10:24:00 AM VolumeUpDown1.UpVolume[0]: 3914 > 1300

        10/13/2020 10:24:00 AM Close[1]: 12089 < Swing1.SwingHigh[1]: 12099.75 && Close[0]: 12107.5 > Swing1.SwingHigh[0]: 12099.75

        10/13/2020 10:24:00 AM Close[0]: 12107.5 > EMA1[0]: 12079.4276085236

        10/13/2020 10:24:00 AM Operaciones: 0 < TradeDay: 1

        10/13/2020 10:24:00 AM Long: True == true: True

        Comment


          #49
          Hello jmarcano,

          Is TraceOrders set to true in State.Configure as directed or is that in State.SetDefaults?

          In side of the condition set action block add a print:

          Print(Time[0] + " Condition true");

          This will actually go inside of the action block on the condition set that triggers the actions, so we can know the condition is triggering the actions at 10:24.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #50

            Sorry I put it in this area

            } else if (State == State.Configure) {
            TraceOrders = true;
            Attached Files

            Comment


              #51
              jmarcano,

              If the order submission is not appearing from TraceOrders, then TraceOrders is not enabled or the condition is not evaluating as true.

              The print "Condition true" is not appearing in the output. This means either this was not added as directed to the action block of the condition set that places the order, or that the condition is not evaluating as true.

              This could mean that your condition does not match what is being printed.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #52

                This would be the departure of the candle that gave the parameters today



                10/12/2020 10:20:00 AM Times[0][0].TimeOfDay: 10:20:00 => Apertura.TimeOfDay: 09:35:00

                10/12/2020 10:20:00 AM Times[0][0].TimeOfDay: 10:20:00 < Cierre.TimeOfDay: 11:30:00

                10/12/2020 10:20:00 AM Position.MarketPosition: Flat == MarketPosition.Flat: Flat

                10/12/2020 10:20:00 AM VolumeUpDown1.UpVolume[0]: 2611 > 1300

                10/12/2020 10:20:00 AM Close[1]: 11910.25 < Swing1.SwingHigh[1]: 11946.25 && Close[0]: 11917 > Swing1.SwingHigh[0]: 11946.25

                10/12/2020 10:20:00 AM Close[0]: 11917 > EMA1[0]: 11900.5592673627

                10/12/2020 10:20:00 AM Operaciones: 0 < TradeDay: 1

                10/12/2020 10:20:00 AM Long: True == true: True
                10/12/2020 10:20:00 AM Condition true

                10/12/2020 10:22:00 AM Times[0][0].TimeOfDay: 10:22:00 => Apertura.TimeOfDay: 09:35:00

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

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

                10/12/2020 10:22:00 AM VolumeUpDown1.UpVolume[0]: 3393 > 1300

                10/12/2020 10:22:00 AM Close[1]: 11917 < Swing1.SwingHigh[1]: 11946.25 && Close[0]: 11921.75 > Swing1.SwingHigh[0]: 11946.25

                10/12/2020 10:22:00 AM Close[0]: 11921.75 > EMA1[0]: 11902.5774323757

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

                10/12/2020 10:22:00 AM Long: True == true: True
                10/12/2020 10:22:00 AM Condition true

                Comment


                  #53

                  But on the print screen it appears, when I save the txt file it does not appear

                  Comment


                    #54
                    Hello jmarcano,

                    I would find it unlikely that when right-clicking and selecting Save As, that the file saved is not the text in the window.

                    Would you like to schedule a call so that you can demonstrate this for me?

                    I am seeing the Condition true in the screenshot but no information from TraceOrders.

                    May I test the script on my end to confirm you have made the changes?

                    To export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
                    1. Click Tools -> Export -> NinjaScript...
                    2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
                    3. Click the 'Export' button
                    4. Enter a unique name for the file in the value for 'File name:'
                    5. Choose a save location -> click Save
                    6. Click OK to clear the export location message
                    By default your exported file will be in the following location:
                    • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
                    Below is a link to the help guide on Exporting NinjaScripts.
                    http://ninjatrader.com/support/helpG...-us/export.htm
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #55
                      Good afternoon ChelseaB, if I don't know why the file doesn't show it, of course I have already exported the file and sent it to you, there are several commented lines. Only the tests we have performed are active.

                      Comment


                        #56
                        I switched to my personal computer and the file is saved here.
                        Attached Files

                        Comment


                          #57
                          Hello jmarcano,

                          You have added the print Print(Time[0] + " Condition true"); to the action block of the 'if (IsFirstTickOfBar)' where were were are printing information.

                          Just ensure we are talking about the same thing, the action block for the condition set that places the order is from lines 163 to 169, which you have completely commented out.

                          The condition true print, is to let us know that your condition has evaluated as true.

                          This is meant to be inside of the action block on the condition set that triggers the actions, so we can know the condition is triggering the actions at 10:24.

                          May I verify you are understanding what I mean by 'inside of the action block on the condition set that triggers the actions'?


                          I have not directed you to comment out your code on lines 119 to 220.

                          The point of prints is to print the information being used in the conditions.

                          We simply want to understand the behavior of the logic. We are not trying to remove the existing logic. We simply want to print the values used in the condition, so we know how the condition will evaluate.

                          If the code is commented out, it won't run. If it won't run, there will be no order and nothing to investigate.

                          TraceOrders isn't showing anything, because all of the code to place orders has been commented out.

                          Please uncomment the code you have commented out.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #58
                            Good afternoon Chelsea, I thought that the condition is placed in another place, I send you the correction code and the printing output. now an entry is executed in each bar.
                            Attached Files
                            Last edited by jmarcano; 10-13-2020, 06:12 PM.

                            Comment


                              #59
                              Hello jmarcano,

                              In this latest file you have uncommented the action block of the condition that sends an order but not all of the code, and specifically the condition set that when true sends the order.

                              The action block in this case would also be triggered because there is no condition for it.

                              Please uncomment all of the code you have commented out.
                              Chelsea B.NinjaTrader Customer Service

                              Comment


                                #60
                                Good afternoon Chelsea, I send you the update of the code and the output now if you run only at the indicated times.
                                Check with this code, can I perform playback tests?

                                Thanks you.
                                Attached Files

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by GussJ, 03-04-2020, 03:11 PM
                                16 responses
                                3,281 views
                                0 likes
                                Last Post Leafcutter  
                                Started by WHICKED, Today, 12:45 PM
                                2 responses
                                19 views
                                0 likes
                                Last Post WHICKED
                                by WHICKED
                                 
                                Started by Tim-c, Today, 02:10 PM
                                1 response
                                9 views
                                0 likes
                                Last Post NinjaTrader_ChelseaB  
                                Started by Taddypole, Today, 02:47 PM
                                0 responses
                                5 views
                                0 likes
                                Last Post Taddypole  
                                Started by chbruno, 04-24-2024, 04:10 PM
                                4 responses
                                53 views
                                0 likes
                                Last Post chbruno
                                by chbruno
                                 
                                Working...
                                X