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

"Use of unassigned local variable 'SendAlert' "

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

    "Use of unassigned local variable 'SendAlert' "

    Hi,

    I am running into the following error message: "Use of unassigned local variable 'SendAlert' ". I know that setting a value at the beginning of the OnBarUpdate( ) section will work but that causes a problem.

    Here's the logic of my script:

    1. I want the custom indicator to send me an email alert when a condition is met
    2. I need to use CalculateOnBarClose = false, so the condition is checked at every tick
    3. I want to receive the alert only once for a given candle, when the condition is met
    4. I want to suppress the alert for the remaining ticks until a new candle is created
    5. When a new candle is created, I re-evaluate whether the condition is met (loop to #3)

    I cannot assign a value to SendAlert at the begining of OnBarUpdate( ) because that may override the value set in a conditional statement during the previous tick. The variable needs to be set outside the protected override void OnBarUpdate() section. Putting bool SendAlert = true in the protected override void Initialize() section did not work. That still generated the error mentionned at the beginning of this post.

    What is the solution to this issue? Thanks.

    - MarcusPlexus
    Last edited by marcusplexus; 09-15-2010, 12:32 PM.

    #2
    Hi marcusplexus,

    Can you use a bool reset in OnBarUpdate?
    If not, can you clarify: "I cannot assign a value to SendAlert at the begining of OnBarUpdate( ) because that may override the value set in a conditional statement during the previous tick."
    TimNinjaTrader Customer Service

    Comment


      #3
      I believe a bool reset would create the problem I am trying to avoid.

      Requested clarification: Suppose the following pseudo-code:

      SendAlert = True

      IF SendAlert = true AND condition_is_met THEN
      Send_the_email_alert
      SendAlert = false
      END_IF

      If SendAlert = true is included at the beginning of the OnBarUpdate() section that equates to not having any evlaluation of SendAlert, as it is reset to true whenever the condition requires it to be "false".

      Comment


        #4
        I found my solution

        I need to put my variable in the (hidden) #region Variables section

        as private bool SendAlert = true;

        You can close the call.

        Comment


          #5
          Hi marcusplexus,

          As another option, you could combine it with FirstTickOfBar: http://www.ninjatrader-support.com/H...FirstTickOfBar

          Something like:

          if (FirstTickOfBar)
          SendAlert=true;

          if (Conditions and SendAlert==true)
          {
          Send the email
          SendAlert = False;
          }
          TimNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by pibrew, Today, 06:10 PM
          0 responses
          4 views
          0 likes
          Last Post pibrew
          by pibrew
           
          Started by pibrew, 04-28-2024, 06:37 AM
          2 responses
          17 views
          0 likes
          Last Post pibrew
          by pibrew
           
          Started by Philippe56140, 04-27-2024, 02:35 PM
          7 responses
          56 views
          0 likes
          Last Post kevinenergy  
          Started by arunkumar3, 08-25-2023, 12:40 PM
          3 responses
          169 views
          0 likes
          Last Post Trader2024!  
          Started by DJ888, 04-26-2024, 10:57 PM
          2 responses
          17 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Working...
          X