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 andrewtrades, Today, 04:57 PM
          0 responses
          2 views
          0 likes
          Last Post andrewtrades  
          Started by chbruno, Today, 04:10 PM
          0 responses
          3 views
          0 likes
          Last Post chbruno
          by chbruno
           
          Started by josh18955, 03-25-2023, 11:16 AM
          6 responses
          436 views
          0 likes
          Last Post Delerium  
          Started by FAQtrader, Today, 03:35 PM
          0 responses
          6 views
          0 likes
          Last Post FAQtrader  
          Started by rocketman7, Today, 09:41 AM
          5 responses
          19 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X