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

problem with two instructions

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

    problem with two instructions

    Hi everyone!

    I have a problem with the these "If" instruction. I create these lines of code in OnBarUpdate with two diferent instructions.

    if (Close[1] != Open[0]);
    {
    If(xxx)
    {
    ​​​​​​ Draw.Rectangle(xxxx, blue);
    }
    If(yyy)
    {
    Draw.Rectangle(xxxx.green):
    }
    If (xxx) == (yyy)return;



    My problem is when loading the indicator it does not draw the two different rectangles on the chart. In the data output window it does print correctly everything I want it, but I not find the way to draw it correctly on the Chart.

    If I erase one of the two variables it works perfectly but I only get it to draw correctly one type of the instruction. Any way to can make work the chart with the 2 instructions at same time.

    Thanks in advance

    #2
    Hello BIOK.NT,

    Thank you for your post.

    In what way is it drawing the rectangles incorrectly compared to the data in the output window?

    Are you using unique tag names to draw two different objects, or are you reusing the tag name to update an existing drawing object? To give a drawing object a unique tag name, please see the forum post linked below:





    If you have already implemented prints to start debugging, can you share the results of your output?

    The prints should include the time of the bar and should print all values from all variables and all hard coded values in all conditions that must evaluate as true for this action to be triggered. It is very important to include a text label for each value and for each comparison operator in the print to understand what is being compared in the condition sets.

    I am happy to assist you with analyzing the output from the output window.

    Run the script and when the output from the output window appears save this by right-clicking the output window and selecting Save As... -> give the output file a name and save -> then attach the output text file to your reply.

    Below is a link to a forum post that demonstrates using informative prints to understand behavior and includes a link to a video recorded using the Strategy Builder to add prints.



    Please let me know if I may further assist with analyzing the output or if you need any assistance creating a print.
    Gaby V.NinjaTrader Customer Service

    Comment


      #3
      Hi NinjaTrader_Gaby

      Thanks for your reply

      I used a CurrentBar variable to make unique the tag of each rectangle. The problem I found when use the two instructions is the first of them draw a rectangle on each candle without logical, but on the output window only appear the correct rectangles. I attach the output file, please if you think any information is missing, let me know.


      these are my 2 Draw.Rectangle line, maybe something is wrong.
      {
      Draw.Rectangle(this, "Tag1"+CurrentBar, true, 1, closePrice, -4, openPrice, Brushes.Green, Brushes.Green, 25);
      }

      {
      Draw.Rectangle(this, "Tag2"+CurrentBar, true, 1, openPrice2, -4, closePrice2, Brushes.Blue, Brushes.Blue, 25);
      }

      Thanks on advance.
      Attached Files

      Comment


        #4
        Hello,

        Please note negative barsAgo indexes are not supported. If you want the rectangle to end 4 bars ago, the endBarsAgo should be positive 4.

        It looks like you are supplying similar arguments to both rectangles. Add prints for closePrice/openPrice and closePrice2/openPrice2. Are the rectangles being drawn on top of eachother? Checking the Drawing Objects window and see if there are two objects, and compare their anchor price/times are.

        What are the conditions to draw the two different rectangles? It isn't clear from your print statements what these conditions are.

        Is it possible you could share a reduced sample script for testing?

        Thank you in advance.
        Last edited by NinjaTrader_Gaby; 01-12-2024, 08:28 AM.
        Gaby V.NinjaTrader Customer Service

        Comment


          #5
          Thanks for your help

          I want to expand the rectangle to the future, for that I put in negative, is the only way I found.

          Yes, one of the problems I find when put the two instruction, is just draw the first instruction, if I erase the return condition for the first rectangle, the second condition draws me well but in the first it draws all the candles without respecting the first instruction.

          if (Close[1] != Open[0]);
          {
          if(Low[0] > High[1])Print(string.Format("{0}Gap Up| Max {1} | Min {2}", Time[0], High[1], Low[0]));
          {
          if (Low[0] <= High[1])return;
          {
          Draw.Rectangle(this, "Gap Alcista"+CurrentBar, true, 1, closePrice, -4, openPrice, Brushes.Green, Brushes.Green, 25);
          }
          }
          if((High[0]) < Low[1])Print(string.Format("{0}Gap Down| Min {1} | Max {2}", Time[0], Low[1], High[0]));
          {
          if (High[0] >= Low[1])return;
          {
          Draw.Rectangle(this, "Gap Bajista"+CurrentBar, true, 1, openPrice2, -4, closePrice2, Brushes.Blue, Brushes.Blue, 25);
          }
          }
          }

          if (Close[1] == Open[0])return;​

          and the details of open and closePrice for Draw.Rectangle instruction are these
          openPrice = Low[0];
          closePrice = High[1];
          openPrice2 = High[0];
          closePrice2 = Low[1];

          Thanks for your help!.

          Comment


            #6
            Hello,

            You can't extend a drawing object into the future, as the method can't draw on bars that doesn't exist yet. This is why negative barsAgo indexes are not supported.

            If you would like, I can add your vote to a feature request for supporting extending drawing objects into the future.

            Additionally,

            I'm a little bit confused by your syntax:


            if (Low[0] <= High[1])return;

            {

            Draw.Rectangle(this, "Gap Alcista"+CurrentBar, true, 1, closePrice, -4, openPrice, Brushes.Green, Brushes.Green, 25);

            }

            if (High[0] >= Low[1])return;

            {

            Draw.Rectangle(this, "Gap Bajista"+CurrentBar, true, 1, openPrice2, -4, closePrice2, Brushes.Blue, Brushes.Blue, 25);

            }



            Do you want these to return if Low[0] <= High[1] or High[0] >= Low[1] else use Draw.Rectangle?
            Gaby V.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by samish18, Today, 11:26 AM
            0 responses
            1 view
            0 likes
            Last Post samish18  
            Started by Trader146, 03-29-2024, 01:22 PM
            2 responses
            14 views
            0 likes
            Last Post Trader146  
            Started by tsantospinto, 04-12-2024, 07:04 PM
            7 responses
            126 views
            0 likes
            Last Post aligator  
            Started by futtrader, 04-21-2024, 01:50 AM
            5 responses
            56 views
            0 likes
            Last Post NinjaTrader_Eduardo  
            Started by PeakTry, Today, 10:49 AM
            0 responses
            2 views
            0 likes
            Last Post PeakTry
            by PeakTry
             
            Working...
            X