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

LineAlert indicator and SendMail method NT7

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

    LineAlert indicator and SendMail method NT7

    Hey,
    I downloaded LineAlert from this link : https://ninjatrader.com/support/foru...esort=d&page=1

    Great indicator, very usefull ! Thank you very much.

    After saving it with a new name, I modified it by adding SendMail, line 140. Syntax like below:
    // Generates an email message
    SendMail("[email protected]", "[email protected]", "LineAlertMail Hit", "LineAlertMail has been hit, go back and see what's up !");
    Emails are sent, it works.

    but once it has been hit, it never stops sending emails, like i receieved nearly 30 emails in 1/2 mn timeframe. I had to remove the indicator from the chart for it to stop...
    Then changed 'ManualReset' option for true and false multiple times, it didnt stop.

    I would like LineAlert to react the same as PriceAlert : once it has been hit, it needs us to move it to be ON again.
    would anyone have a suggestion about where the problem comes from, and what could be done ?
    Thanks a lot.

    #2
    Hello CharlesAmd,

    Thank you for the question.

    In this situation, this indicator uses CalculateOnBarClose = false; so the condition of the alert could become true frequently causing many emails.

    If you only want this to happen one per crossing, you would need to add some logic to account for how the script already works. Because the script uses ResetAlert to reset instead of logic, your code would be executed but not the alert in the cross condition.

    The script is already set up to reset on each new bar and with the manual reset so these would be where you could add your custom reset for the email as well. Here is one example of a way to do this:

    First, define a bool variable in the variables section:

    Code:
    private bool sendMessage = true;
    Find the if (FirstTickOfBar line at the beginning of OnBarUpdate and modify it to look like the following. this is the first reset.

    Code:
    if (FirstTickOfBar)
    [B]{[/B]
    	ResetAlert("AlertLineCrossing");
    	[B]sendMessage = true;[/B]
    [B]}[/B]
    Next modify the ManualReset code:

    Code:
    if (ManualReset)
    {
    	ResetAlert("AlertLineCrossing");
    	ManualReset = false;
    	[B]sendMessage = true;[/B]
    }

    finally, add a condition to check for this new bool and send your email:

    Code:
    if(CrossBelow(Close, lineValueAtLastBar, 1) || CrossAbove(Close, lineValueAtLastBar, 1))
    {
    	Alert("AlertLineCrossing", Cbi.Priority.High, alertMessage, soundFile, 0, Color.White, Color.Black);  
    	[B]if(sendMessage)
    	{
    		Print("here"); // it is easy to test using prints before moving to email. If you send too many emails in a short period of time on accident, some email providers may mark your account as spam
    		sendMessage = false;
    	}[/B]
    }

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi Jesse, thank you
      i tried that and encountered issues compiling.
      Wich line should i paste the bool variable ? i guess that's where the issue comes from. the rest just beeing pasting under something.

      thanks

      Comment


        #4
        Hello CharlesAmd,

        the private variable would need to go in the variables region under the class:

        Code:
        public class LineAlert : Indicator
            {
                #region Variables
                private bool sendMessage = true;
        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by GLFX005, Today, 03:23 AM
        0 responses
        1 view
        0 likes
        Last Post GLFX005
        by GLFX005
         
        Started by XXtrader, Yesterday, 11:30 PM
        2 responses
        11 views
        0 likes
        Last Post XXtrader  
        Started by Waxavi, Today, 02:10 AM
        0 responses
        6 views
        0 likes
        Last Post Waxavi
        by Waxavi
         
        Started by TradeForge, Today, 02:09 AM
        0 responses
        14 views
        0 likes
        Last Post TradeForge  
        Started by Waxavi, Today, 02:00 AM
        0 responses
        3 views
        0 likes
        Last Post Waxavi
        by Waxavi
         
        Working...
        X