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

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;
                }
            
            [B]// 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*/)[/B]
                {
                    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.
            Test the bool type, which holds true or false. A bool occupies 1 byte of memory.
            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 cls71, Today, 04:45 AM
              0 responses
              1 view
              0 likes
              Last Post cls71
              by cls71
               
              Started by mjairg, 07-20-2023, 11:57 PM
              3 responses
              213 views
              1 like
              Last Post PaulMohn  
              Started by TheWhiteDragon, 01-21-2019, 12:44 PM
              4 responses
              544 views
              0 likes
              Last Post PaulMohn  
              Started by GLFX005, Today, 03:23 AM
              0 responses
              3 views
              0 likes
              Last Post GLFX005
              by GLFX005
               
              Started by XXtrader, Yesterday, 11:30 PM
              2 responses
              12 views
              0 likes
              Last Post XXtrader  
              Working...
              X