• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

So many Alerts and errors especially sendmail and share

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

    So many Alerts and errors especially sendmail and share


    Duplicate title and content problem is solved with Bars.TickCount, but there are many other problems such as time limit error, server response error, update limit error and so on. I tried to fix it with something like an alarm cycle(Timer, Thread Sleep, Task Delay and so on), but it did not work. Help me please. PS : I compile the code -> Calculate = Calculate.OnEachTick; i don't want OnBarClose.
    protected override void OnBarUpdate()
    {
    //Add your custom indicator logic here.
    if (CrossAbove(Close, SMA(Period), 1))
    {
    Draw.ArrowUp(this, "Buy", true, 0, Low[0] - 0.01, Brushes.Red);
    PlaySound(NinjaTrader.Core.Globals.InstallDir + @"\sounds\Alert1.wav");
    SendMail("[email protected]", "Buy", "Buy");
    // Duplicate error : SendMail("[email protected]", "Buy"+ Bars.TickCount, "Buy");
    Share("Twitter", "Buy");
    }

    Value[0] = SMA(Period)[0];
    }.
    Attached Files

    #2
    Hello hontips0023,

    The current code allows for rapid emails to be sent on each new tick when the crossabove is true.

    Is the issue that too many emails are being sent too rapidly?

    If so, it might be helpful to only send one email per bar. You can use a bool that is reset when IsFirstTickOfBar is true to prevent the script from sending more than one email per bar.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your comment. However, there are some questions. With IsFirstTickOfBar, it just work only the first tick of bar.
      In other words, if the condition is satisfied from the second tick, it will not work.
      Attached Files

      Comment


        #4
        Hello hontips0023,

        Not quite. This would use a bool. The bool would be set so that anytime the condition was true while the bar was open the condition will trigger, the action performed and the bool set to the opposite position. It is not reset back until the first tick of the next bar. Then again it waits until the condition is true in real-time.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          That's right. But as I said before, with IsFirstTickOfBar, alert and sendmail just work only the first tick of bar.
          Please refer to the time of log in the picture.
          Attached Files

          Comment


            #6
            Hello hontips0023,

            Your analysis of how to use a bool is incorrect.

            The action such as the Alert() or SendMail() call would not occur on the first tick of the bar. This would occur sometime while the bar is open on any received tick and would only occur once until the next bar opens.

            For example:

            Code:
            private bool actionTriggered;
            
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Calculate                                    = Calculate.OnEachTick;         
                }
                else if (State == State.DataLoaded)
                {
                    actionTriggered = false;
                }
            }
            
            protected override void OnBarUpdate()
            {
                // reset the trigger bool when the new bar opens to allow for the condition to be checked again
                if (IsFirstTickOfBar)
                {
                    actionTriggered = false;
                }
            
            // on each new tick anywhere intra-bar check your conditions. Once the conditions are true, set actionTriggered to true to stop alerts until new bar
                if (actionTriggered == false /* && your conditions  trigger action intra-bar*/)
                {
                    Alert("myAlert", Priority.Low, "alert text", string.Empty, 1, Brushes.White, Brushes.Black);
                    actionTriggered = true;
                }
            }
            Below is a public link to a 3rd party educational site on the bool object type.
            https://www.dotnetperls.com/bool
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Thank u so much!!
              The example is very helpful.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Mykro, Today, 01:42 PM
              0 responses
              3 views
              0 likes
              Last Post Mykro
              by Mykro
               
              Started by EF Hutton, Today, 01:19 PM
              1 response
              4 views
              0 likes
              Last Post NinjaTrader_PatrickG  
              Started by Mykro, Today, 01:10 PM
              1 response
              2 views
              0 likes
              Last Post NinjaTrader_PatrickG  
              Started by Velhinho, Today, 12:30 PM
              1 response
              5 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by EF Hutton, Today, 12:36 PM
              1 response
              7 views
              0 likes
              Last Post NinjaTrader_Melissa  
              Working...
              X