Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

bool declarations

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

    bool declarations

    I created a new strategy using the Strategy Builder and within it there were 2 bool variables which the Builder declared in 'Public Class' and made the assignments of false in 'SetDefaults'. When I use Print statements to check the status they are always 'True'. The only thing within the body that would change them to true is if a trade were taken which is not happening because the bool must be false is a condition of entering the trade,which would be followed with changing the bool to true. Is the declaration correct in 'Public Class'?

    #2
    Hello galsermil,

    Thank you for your post.

    Can you provide the script you're testing with so I may see if the same occurs on my end of things? You can export a script from Tools > Export > NinjaScript add-on. Do not check the box to export as a compiled assembly or I will be unable to review your logic. Please attach the resulting .Zip file to your reply.

    Thanks in advance; I look forward to assisting further.

    Comment


      #3
      Kate, I will certainly export the script to you but I also want to make you are aware of a couple of things that I have done and the result. I commented out all of the text except a few lines of Debugging print statements. I have 18 pairs in my Demo account but I used only three as my guinea pigs when I commented out the lines and they are AUD/USD, GBP/USD, and USD/CAD. The result was that all three reported my bools as false. I then removed the comment lines for the script that set conditions for and entered a Short trade. When I did this, the AUD/USD and GBP/USD remained false but the USD/CAD reported true.

      Kate, the export facility will not export the strategy.. The message is make sure all of the elements are include. I'm not sure what that means but there are two indicators referenced one of which is in the list and I included it and the other is RSI and it is not referenced so I can't include it.

      Comment


        #4
        Hello galsermil,

        Thank you for your reply.

        Can you provide a screenshot of the log tab of the Control Panel showing the error?

        Thanks in advance; I look forward to assisting you further.

        Comment


          #5
          Kate

          I am attaching the .cs file. I hope that works. The divergence indicator is third party proprietary so I am not sure what to do about it. If worst comes to worst, can you log into my computer through Team Viewer?
          Attached Files

          Comment


            #6
            Hello galsermil,

            Thank you for your reply.

            I was able to strip out the bits referencing the proprietary indicator, and it looks like what's occurring is that an order is being submitted before the strategy has processed at least the number of bars specified by its BarsRequiredToTrade property. Since the order was triggered, but gets ignored because we haven't reached 20 bars yet, your bool gets flipped to true but no order is seen, which means you can't exit and flip that bool back to false.

            Try the following:

            protected override void OnBarUpdate()
            {

            Print("Top "+Instrument.FullName+" "+ Time[0]+" First_Trade_Open = " + First_Trade_Open + " Second_Trade_Open: " + Second_Trade_Open);
            if (BarsInProgress != 0)
            return;

            if (CurrentBars[0] < 20)
            return;


            This way no orders get placed until we're past the number of bars required to trade.

            Please let us know if we may be of further assistance to you.

            Comment


              #7
              Kate,

              I assume you are speaking of the export error. If so it did not appear in the log but on the face of the Export screen. See this screencast :https://www.screencast.com/t/bx4qRaJc3

              Comment


                #8
                Kate,

                When I comment out Set1 and Set2, my 4 Guinea pigs report 'false'.

                Comment


                  #9
                  Hello galsermil,

                  Thank you for your replies.

                  The export error was due to referencing a 3rd party assembly, which I stripped out of your code to run it. I am not talking about the export error or needing to comment out any logic, I am saying to simply change your current bars check at the top of OnBarUpdate as in the bolded version below:

                  Code:
                  protected override void OnBarUpdate()
                  {
                  
                  Print("Top "+Instrument.FullName+" "+ Time[0]+" First_Trade_Open = " + First_Trade_Open + " Second_Trade_Open: " + Second_Trade_Open);
                  if (BarsInProgress != 0)
                  return;
                  
                  [B]if (CurrentBars[0] < 20)
                  return;[/B]
                  
                  //  OnBarUpdate code continues - don't comment out sets
                  Please let us know if we may be of further assistance to you.

                  Comment


                    #10
                    Kate,

                    Did this change deal with why the bool variables were being changed to 'open'. I can't check it as yet on my end as I have created a compile error which I need to sort out. By the way. may I ask you what is the instruction for determining the profit/loss on a single trade. What I am using, I believe is for all trades?

                    Comment


                      #11
                      Hello galsermil,

                      Thank you for your reply.

                      Yes. Please see this section of my prior reply:

                      ...what's occurring is that an order is being submitted before the strategy has processed at least the number of bars specified by its BarsRequiredToTrade property. Since the order was triggered, but gets ignored because we haven't reached 20 bars yet, your bool gets flipped to true but no order is seen, which means you can't exit and flip that bool back to false.
                      As far as getting PnL from a specific trade, that can be done with the TradeCollection:



                      There's an example there of getting PnL from specific trades.

                      Please let us know if we may be of further assistance to you.

                      Comment


                        #12
                        Kate,

                        Thank you very much. That paragraph was missing from your previous reply or I did not know how to find it.

                        Comment


                          #13
                          Kate,

                          I hate to be so much bother but I made the change you suggested but my bools are still being flipped..

                          Comment


                            #14
                            Hello galsermil,

                            Thank you for your reply.

                            What I would suggest here is first, to turn on TraceOrders so you can see if the orders are being submitted and ignored.

                            Strategy Builder > Default Properties > More Properties > Trace Orders, or in your State == State.SetDefaults section of OnStateChange:

                            if (State == State.SetDefaults)
                            {
                            TraceOrders = true;
                            }

                            This will print a log of any orders submitted by the strategy during while it's running, along with any ignored orders, which would trigger your bool to change without seeing an actual order. You can then look through and see what may be occurring.

                            Please let us know if we may be of further assistance to you.

                            Comment


                              #15
                              Is the Trace Log printed in Output or where?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by NullPointStrategies, Yesterday, 05:17 AM
                              0 responses
                              56 views
                              0 likes
                              Last Post NullPointStrategies  
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              133 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              73 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              45 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              49 views
                              0 likes
                              Last Post TheRealMorford  
                              Working...
                              X