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

Email OnExecution

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

    Email OnExecution

    Hi, i want my strategy to alert me via mail when it bought /sold or got stopped out, so reading around i added this to the script after OnBarUpdate

    protected override void OnExecution(IExecution execution)
    {
    if ( sLMailAlerts == true && execution.Name == "Stop Loss")
    {
    SendMail( emailFrom , emailTo, Instrument.FullName + " | " + BarsPeriod.Id.ToString() +" : " + BarsPeriod.Value.ToString( ) + "Stop Loss Triggered", "Stop Loss");

    Print("Stop Loss Triggered");


    }


    but i dont get the option to set it tue or false in the parameters window and im not getting an error from the Logs.. help please

    #2
    Hello,

    Thank you for the question.

    Have you removed the strategy from the Strategy tab in the control center to ensure there are no instances of it, and then re applied the strategy? Items in Initialize and properties can not get updated between refreshes of the script depending on the change so this could be the case.

    If that is not what the problem is, can you provide the public property you have created for your sLMailAlerts variable?

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

    Comment


      #3
      Hi Jesse, sorry the delayed answer, had to leave to work yesterday after i posted my question, yes i removed the strategy a couple times nothing changed, i restarted Ninja also, but the new Boolean options wont appear in parameters window.

      here's the strategy, thanks for the help Jesse
      Attached Files
      Last edited by kabott; 09-08-2015, 01:31 PM.

      Comment


        #4
        Hello kabott,

        Thank you for sending in your code. In your email parameters you are using Category instead of GridCategory. Please update your code accordingly and it will work:
        Code:
        [[B]GridCategory[/B]("04.Send Email Alert")]
        [Gui.Design.DisplayName("04.Email From")]
        public string EmailFrom
        {
        	get { return emailFrom; }
        	set { emailFrom = value; }
        }
        Please let me know if you have any questions or if I may be of further assistance.
        Michael M.NinjaTrader Quality Assurance

        Comment


          #5
          Hi Michael, again thanks for your help, an other question:
          Should the "execution.Name" be the same name as the SetStopLoss?

          im confused, cause if i use "target1" as the name my TP and Entry orders are also called "target1"

          in which case the question is: How do i define a condition for entries and Take Profit exits?

          I basically want the strategy to alert me via mail of any action it takes, be it bought/sold, got stopped out or exited the market trough Take Profit.


          private void GoLong()
          {
          SetStopLoss ("target1", CalculationMode.Ticks, initialStopLoss , false); // Default Stop, 45 ticks
          EnterLong ( "target1" );
          SetProfitTarget ("target1" , CalculationMode.Price, Close[0] + ( takeProfitTarget * TickSize));
          doItOnce = true;
          }


          if ( sLMailAlerts == true && execution.Name == "Stop Loss")
          {
          SendMail( emailFrom , emailTo, Instrument.FullName + " | " + BarsPeriod.Id.ToString() +" : " + BarsPeriod.Value.ToString( ) + "Stop Loss Triggered", "Stop Loss");
          }

          Comment


            #6
            Hello kabott,

            Have you tried the following:
            Code:
            if(sLMailAlerts == true)
            {
                if([B]execution.Order.Name[/B] == "Stop loss")
                {
                    SendMail( emailFrom , emailTo, Instrument.FullName + " | " + BarsPeriod.Id.ToString() +" : " + BarsPeriod.Value.ToString( ) + "Stop Loss Triggered", "Stop Loss"); 
                }
            }
            Please see this forum post for more information: http://ninjatrader.com/support/forum...24&postcount=2

            If you have a specific case where this is not working, you could go off of the order type (if you are only using market orders for your entries):
            Code:
            if([B]execution.Order.OrderType == OrderType.Stop || execution.Order.OrderType == OrderType.StopLimit[/B])
                {
                    SendMail( emailFrom , emailTo, Instrument.FullName + " | " + BarsPeriod.Id.ToString() +" : " + BarsPeriod.Value.ToString( ) + "Stop Loss Triggered", "Stop Loss"); 
                }
            Please let me know if I may be of further assistance.
            Michael M.NinjaTrader Quality Assurance

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by frankthearm, Yesterday, 09:08 AM
            14 responses
            47 views
            0 likes
            Last Post NinjaTrader_Clayton  
            Started by gentlebenthebear, Today, 01:30 AM
            2 responses
            13 views
            0 likes
            Last Post gentlebenthebear  
            Started by Kaledus, Today, 01:29 PM
            2 responses
            8 views
            0 likes
            Last Post Kaledus
            by Kaledus
             
            Started by PaulMohn, Today, 12:36 PM
            2 responses
            16 views
            0 likes
            Last Post PaulMohn  
            Started by Conceptzx, 10-11-2022, 06:38 AM
            2 responses
            56 views
            0 likes
            Last Post PhillT
            by PhillT
             
            Working...
            X