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

Indicator Using Bool (Problem)

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

    Indicator Using Bool (Problem)

    Dear Sir or Madam,

    With reference to the code below,
    I want to inform you that I tried everything, read every treat, downloaded every solution to create my request without issues, without a hope I decided to right you in the forum.



    My request is simple when 3 steps in order are fulfilled, and a final entry steps shows I want to plot an arrow. At the final step which will be my entry point manually.

    Somehow, the indicator do not define the bool.
    To find my mistake I plotted an arrow at the end of each step to understand the issue. So the code run without a bug, however, it plots regarding the situation without considering the bool I created, did I missed something?

    Please, can you help me.
    Code:
        [COLOR=blue][FONT=&quot]public[/FONT][/COLOR][COLOR=blue][FONT=&quot]class[/FONT][/COLOR][COLOR=black][FONT=&quot] bool_V10 : Indicator[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]    {[/FONT][/COLOR]
      [COLOR=blue][FONT=&quot]#region[/FONT][/COLOR][COLOR=black][FONT=&quot] Variables[/FONT][/COLOR]
      [COLOR=green][FONT=&quot]// Wizard generated variables[/FONT][/COLOR]
      [COLOR=blue][FONT=&quot]private[/FONT][/COLOR][COLOR=blue][FONT=&quot]bool[/FONT][/COLOR][COLOR=black][FONT=&quot] condition1 = [/FONT][/COLOR][COLOR=blue][FONT=&quot]false[/FONT][/COLOR][COLOR=black][FONT=&quot]; [/FONT][/COLOR][COLOR=green][FONT=&quot]// Default setting for Condition1[/FONT][/COLOR]
      [COLOR=blue][FONT=&quot]private[/FONT][/COLOR][COLOR=blue][FONT=&quot]bool[/FONT][/COLOR][COLOR=black][FONT=&quot] condition2 = [/FONT][/COLOR][COLOR=blue][FONT=&quot]false[/FONT][/COLOR][COLOR=black][FONT=&quot]; [/FONT][/COLOR][COLOR=green][FONT=&quot]// Default setting for Condition2[/FONT][/COLOR]
      [COLOR=blue][FONT=&quot]private[/FONT][/COLOR][COLOR=blue][FONT=&quot]bool[/FONT][/COLOR][COLOR=black][FONT=&quot] condition3 = [/FONT][/COLOR][COLOR=blue][FONT=&quot]false[/FONT][/COLOR][COLOR=black][FONT=&quot]; [/FONT][/COLOR][COLOR=green][FONT=&quot]// Default setting for Condition3[/FONT][/COLOR]
      [COLOR=green][FONT=&quot]// User defined variables (add any user defined variables below)[/FONT][/COLOR]
      [COLOR=blue][FONT=&quot]#endregion[/FONT][/COLOR]
      
      [COLOR=gray][FONT=&quot]///[/FONT][/COLOR][COLOR=gray][FONT=&quot]<summary>[/FONT][/COLOR]
      [COLOR=gray][FONT=&quot]///[/FONT][/COLOR][COLOR=green][FONT=&quot] This method is used to configure the indicator and is called once before any bar data is loaded.[/FONT][/COLOR]
      [COLOR=gray][FONT=&quot]///[/FONT][/COLOR][COLOR=gray][FONT=&quot]</summary>[/FONT][/COLOR]
      [COLOR=blue][FONT=&quot]protected[/FONT][/COLOR][COLOR=blue][FONT=&quot]override[/FONT][/COLOR][COLOR=blue][FONT=&quot]void[/FONT][/COLOR][COLOR=black][FONT=&quot] Initialize()[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]        {[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]            Add([/FONT][/COLOR][COLOR=blue][FONT=&quot]new[/FONT][/COLOR][COLOR=black][FONT=&quot] Plot([/FONT][/COLOR][COLOR=blue][FONT=&quot]new[/FONT][/COLOR][COLOR=black][FONT=&quot] Pen(Color.SpringGreen,[/FONT][/COLOR][COLOR=purple][FONT=&quot]5[/FONT][/COLOR][COLOR=black][FONT=&quot]), PlotStyle.TriangleUp, [/FONT][/COLOR][COLOR=maroon][FONT=&quot]"Plot1"[/FONT][/COLOR][COLOR=black][FONT=&quot]));[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]            Add([/FONT][/COLOR][COLOR=blue][FONT=&quot]new[/FONT][/COLOR][COLOR=black][FONT=&quot] Plot([/FONT][/COLOR][COLOR=blue][FONT=&quot]new[/FONT][/COLOR][COLOR=black][FONT=&quot] Pen(Color.Crimson,[/FONT][/COLOR][COLOR=purple][FONT=&quot]5[/FONT][/COLOR][COLOR=black][FONT=&quot]), PlotStyle.TriangleDown, [/FONT][/COLOR][COLOR=maroon][FONT=&quot]"Plot2"[/FONT][/COLOR][COLOR=black][FONT=&quot]));[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]            Add([/FONT][/COLOR][COLOR=blue][FONT=&quot]new[/FONT][/COLOR][COLOR=black][FONT=&quot] Plot([/FONT][/COLOR][COLOR=blue][FONT=&quot]new[/FONT][/COLOR][COLOR=black][FONT=&quot] Pen(Color.DodgerBlue,[/FONT][/COLOR][COLOR=purple][FONT=&quot]5[/FONT][/COLOR][COLOR=black][FONT=&quot]), PlotStyle.TriangleUp, [/FONT][/COLOR][COLOR=maroon][FONT=&quot]"Plot3"[/FONT][/COLOR][COLOR=black][FONT=&quot]));[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]            Add([/FONT][/COLOR][COLOR=blue][FONT=&quot]new[/FONT][/COLOR][COLOR=black][FONT=&quot] Plot([/FONT][/COLOR][COLOR=blue][FONT=&quot]new[/FONT][/COLOR][COLOR=black][FONT=&quot] Pen(Color.Yellow,[/FONT][/COLOR][COLOR=purple][FONT=&quot]5[/FONT][/COLOR][COLOR=black][FONT=&quot]), PlotStyle.TriangleDown, [/FONT][/COLOR][COLOR=maroon][FONT=&quot]"Plot4"[/FONT][/COLOR][COLOR=black][FONT=&quot]));[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]            Overlay                      = [/FONT][/COLOR][COLOR=blue][FONT=&quot]true[/FONT][/COLOR][COLOR=black][FONT=&quot];[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]        }[/FONT][/COLOR]
      
      [COLOR=gray][FONT=&quot]///[/FONT][/COLOR][COLOR=gray][FONT=&quot]<summary>[/FONT][/COLOR]
      [COLOR=gray][FONT=&quot]///[/FONT][/COLOR][COLOR=green][FONT=&quot] Called on each bar update event (incoming tick)[/FONT][/COLOR]
      [COLOR=gray][FONT=&quot]///[/FONT][/COLOR][COLOR=gray][FONT=&quot]</summary>[/FONT][/COLOR]
      [COLOR=blue][FONT=&quot]protected[/FONT][/COLOR][COLOR=blue][FONT=&quot]override[/FONT][/COLOR][COLOR=blue][FONT=&quot]void[/FONT][/COLOR][COLOR=black][FONT=&quot] OnBarUpdate()[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]        {[/FONT][/COLOR]
      
      
      [COLOR=blue][FONT=&quot]if[/FONT][/COLOR][COLOR=black][FONT=&quot] (Step A == True)[/FONT][/COLOR]
      
      [COLOR=black][FONT=&quot]            Plot3.Set(Low[[/FONT][/COLOR][COLOR=purple][FONT=&quot]0[/FONT][/COLOR][COLOR=black][FONT=&quot]] - ([/FONT][/COLOR][COLOR=purple][FONT=&quot]3[/FONT][/COLOR][COLOR=black][FONT=&quot] * TickSize));      [/FONT][/COLOR]
      [COLOR=black][FONT=&quot]                  condition1 = [/FONT][/COLOR][COLOR=blue][FONT=&quot]true[/FONT][/COLOR][COLOR=black][FONT=&quot];[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]                  condition2 = [/FONT][/COLOR][COLOR=blue][FONT=&quot]false[/FONT][/COLOR][COLOR=black][FONT=&quot];[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]                  condition3 = [/FONT][/COLOR][COLOR=blue][FONT=&quot]false[/FONT][/COLOR][COLOR=black][FONT=&quot];[/FONT][/COLOR]
      
      
      [COLOR=blue][FONT=&quot]if[/FONT][/COLOR][COLOR=black][FONT=&quot]  ( Step B == [/FONT][/COLOR][COLOR=blue][FONT=&quot]true[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]                        && condition1 == [/FONT][/COLOR][COLOR=blue][FONT=&quot]true[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]                        && condition2 != [/FONT][/COLOR][COLOR=blue][FONT=&quot]true[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]                        && condition3 != [/FONT][/COLOR][COLOR=blue][FONT=&quot]true[/FONT][/COLOR][COLOR=black][FONT=&quot])[/FONT][/COLOR]
      
      
      [COLOR=black][FONT=&quot]            Plot4.Set(High[[/FONT][/COLOR][COLOR=purple][FONT=&quot]0[/FONT][/COLOR][COLOR=black][FONT=&quot]] + ([/FONT][/COLOR][COLOR=purple][FONT=&quot]3[/FONT][/COLOR][COLOR=black][FONT=&quot] * TickSize));     [/FONT][/COLOR]
      [COLOR=black][FONT=&quot]                  condition1 = [/FONT][/COLOR][COLOR=blue][FONT=&quot]false[/FONT][/COLOR][COLOR=black][FONT=&quot];[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]                  condition2 = [/FONT][/COLOR][COLOR=blue][FONT=&quot]true[/FONT][/COLOR][COLOR=black][FONT=&quot];[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]                  condition3 = [/FONT][/COLOR][COLOR=blue][FONT=&quot]false[/FONT][/COLOR][COLOR=black][FONT=&quot];[/FONT][/COLOR]
      
      
      
      [COLOR=blue][FONT=&quot]if[/FONT][/COLOR][COLOR=black][FONT=&quot] (Step C == true[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]&& condition1 != [/FONT][/COLOR][COLOR=blue][FONT=&quot]true[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]                  && condition2 == [/FONT][/COLOR][COLOR=blue][FONT=&quot]true[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]                  && condition3 != [/FONT][/COLOR][COLOR=blue][FONT=&quot]true)[/FONT][/COLOR]
      
      [COLOR=black][FONT=&quot]                  Plot1.Set(Low[[/FONT][/COLOR][COLOR=purple][FONT=&quot]0[/FONT][/COLOR][COLOR=black][FONT=&quot]] - ([/FONT][/COLOR][COLOR=purple][FONT=&quot]3[/FONT][/COLOR][COLOR=black][FONT=&quot] * TickSize)); [/FONT][/COLOR]
      [COLOR=black][FONT=&quot]                  condition1 = [/FONT][/COLOR][COLOR=blue][FONT=&quot]false[/FONT][/COLOR][COLOR=black][FONT=&quot];[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]                  condition2 = [/FONT][/COLOR][COLOR=blue][FONT=&quot]false[/FONT][/COLOR][COLOR=black][FONT=&quot];[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]                  condition3 = [/FONT][/COLOR][COLOR=blue][FONT=&quot]true[/FONT][/COLOR][COLOR=black][FONT=&quot];[/FONT][/COLOR]
      
      [COLOR=blue][FONT=&quot]if[/FONT][/COLOR][COLOR=black][FONT=&quot] (Final Step == True[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]&&condition1 == [/FONT][/COLOR][COLOR=blue][FONT=&quot]false[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]                  && condition2 == [/FONT][/COLOR][COLOR=blue][FONT=&quot]false[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]                  && condition3 == [/FONT][/COLOR][COLOR=blue][FONT=&quot]true)[/FONT][/COLOR]
      
    
    [COLOR=black][FONT=&quot]                  Plot2.Set(High[[/FONT][/COLOR][COLOR=purple][FONT=&quot]0[/FONT][/COLOR][COLOR=black][FONT=&quot]] + ([/FONT][/COLOR][COLOR=purple][FONT=&quot]3[/FONT][/COLOR][COLOR=black][FONT=&quot] * TickSize));     [/FONT][/COLOR]
      [COLOR=black][FONT=&quot]                  condition1 = [/FONT][/COLOR][COLOR=blue][FONT=&quot]false[/FONT][/COLOR][COLOR=black][FONT=&quot];[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]                  condition2 = [/FONT][/COLOR][COLOR=blue][FONT=&quot]false[/FONT][/COLOR][COLOR=black][FONT=&quot];[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]                  condition3 = [/FONT][/COLOR][COLOR=blue][FONT=&quot]false[/FONT][/COLOR][COLOR=black][FONT=&quot];[/FONT][/COLOR]
    
      [COLOR=black][FONT=&quot]        }[/FONT][/COLOR]
    Attached Files

    #2
    Hello Yassine.Chetouani ,

    Is the issue that your condition1/2/3 are not being set after you set the plot? That could because you need to use brackets like the following,

    Code:
      if (Step A == True)
    {
                  Plot3.Set(Low[0] - (3 * TickSize));      
                        condition1 = true;
                        condition2 = false;
                        condition3 = false;
    }
    If this is not the issue could you please provide more information as to what is expected vs what you are seeing, along with a full copy of the code exported in the following format.

    To export a NinjaScript from NinjaTrader 7 do the following:
    From the Control Center window select File -> Utilities-> Export NinjaScript...
    Select the file in the left column then click “>”, then press export and name the file.
    Then attach that file you saved; under My Docs>NT7>Bin>Custom>Select the downloaded .zip file.

    I look forward to your reply.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Dear Mr. Alan,

      Thank you for answering me,
      I checked your answer &&
      You are right I didn't add the brackets.
      As soon as I added them, the code worked.
      Thank you.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by jclose, Today, 09:37 PM
      0 responses
      6 views
      0 likes
      Last Post jclose
      by jclose
       
      Started by WeyldFalcon, 08-07-2020, 06:13 AM
      10 responses
      1,414 views
      0 likes
      Last Post Traderontheroad  
      Started by firefoxforum12, Today, 08:53 PM
      0 responses
      11 views
      0 likes
      Last Post firefoxforum12  
      Started by stafe, Today, 08:34 PM
      0 responses
      11 views
      0 likes
      Last Post stafe
      by stafe
       
      Started by sastrades, 01-31-2024, 10:19 PM
      11 responses
      169 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Working...
      X