• 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

Sendmail and alert not working

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

    Sendmail and alert not working

    Hi

    I'm using NT7 since a wild and i try to move on NT8 and to transcribe all my scripts.

    I'm trying to use sendmail and alert. I configure the smtp gmail as on NT7 and when i launch the test mail, it is working.

    I want to specify that i receive data 15 minutes delay from esignal.

    I read on your "code breaking changes" page this example for the alert :


    protected override void OnBarUpdate()
    {
    // Generate an alert when the RSI value is greater or equal to 20
    if(RSI(14, 3)[0] >= 20)
    Alert("myAlert", Priority.High, "Reached threshold", NinjaTrader.Core.Globals.InstallDir+...s\Aler t1.wav", 10,Brushes.Black, Brushes.Yellow);
    }

    I copy the same code and add this below the Alert line :

    SendMail("[email protected]", "test", "test corps email");


    My first problem is that when i run the strategy on 2 equities (with the RSI > 20) i do not receive the email and the Alert is not working.

    My second problem is that if i change if(RSI(14, 3)[0] >= 20) to if(RSI(14, 3)[1] >= 20), the strategy is not enabling with this logs : Error on calling "OnBarUpdate" method on bar 0 : you are accessing an index with a value that is invalid since it is out-of-range...

    I'm sorry to put 2 differents problems of this post but the script is working well on NT7 on the equities strategy. Do i have to specify something specific on OnStateChange ?

    Thx for your help.


    #2
    Hello Thomas79,

    Thank you for your note.

    Code:
    Alert("myAlert", Priority.High, "Reached threshold", NinjaTrader.Core.Globals.InstallDir+...s\Aler t1.wav", 10,Brushes.Black, Brushes.Yellow);
    Is this copy-and-pasted directly from your code? "...s\Aler t1.wav" is not a complete file path and there's a space in the center of the word alert. That could well be affecting whether or not it triggers. Do you see any errors in the log tab of the Control Center? If so, what do they report?

    My second problem is that if i change if(RSI(14, 3)[0] >= 20) to if(RSI(14, 3)[1] >= 20), the strategy is not enabling with this logs : Error on calling "OnBarUpdate" method on bar 0 : you are accessing an index with a value that is invalid since it is out-of-range...
    This error is occuring on bar 0, the very first bar of the chart. If you change to RSI(14, 3)[1] you're asking it to give you the value for the bar before the first bar - which doesn't exist. I suggest adding something like this to the top of OnBarUpdate:

    Code:
    if (CurrentBars[0] < BarsRequiredToTrade) 
    {
          return;
    }
    This will allow you to force the strategy to not begin running until there's enough bars on the chart to actually execute its logic.

    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Hi

      Thx for the response kate.

      In NT7 calculate OnBarClose, [0] is yesterday, [1] is two days ago, [2] is three days ago and so on... does it change on NT8 ?

      i add the code you mentionned, the stragety is launching but the sendmail and the alert do not work (there is no space on my alert code on NT8)

      I launch the strategy calculate on bar close.

      I don't understand why on NT7 it is working and not on NT8

      Remember i well configured the smtp gmail and the test email is working.

      Here my complete code : (it looks to be really easy but note working) can you help ?


      #region Using declarations
      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.ComponentModel.DataAnnotations;
      using System.Linq;
      using System.Text;
      using System.Threading.Tasks;
      using System.Windows;
      using System.Windows.Input;
      using System.Windows.Media;
      using System.Xml.Serialization;
      using NinjaTrader.Cbi;
      using NinjaTrader.Gui;
      using NinjaTrader.Gui.Chart;
      using NinjaTrader.Gui.SuperDom;
      using NinjaTrader.Gui.Tools;
      using NinjaTrader.Data;
      using NinjaTrader.NinjaScript;
      using NinjaTrader.Core.FloatingPoint;
      using NinjaTrader.NinjaScript.Indicators;
      using NinjaTrader.NinjaScript.DrawingTools;
      #endregion

      //This namespace holds Strategies in this folder and is required. Do not change it.
      namespace NinjaTrader.NinjaScript.Strategies
      {
      public class testemail : Strategy
      {
      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = @"Entrer la description du nouveau Stratégie ici.";
      Name = "testemail";
      }
      }

      protected override void OnBarUpdate()
      {
      if (CurrentBars[0] < BarsRequiredToTrade)
      {
      return;
      }

      // Ensemble 1
      if(RSI(14, 3)[1] >= 20)

      Alert("myAlert", Priority.High, "Reached threshold", NinjaTrader.Core.Globals.InstallDir+...s\Aler t1.wav", 10, Brushes.Black, Brushes.Yellow);

      SendMail("[email protected]", "test", "test corps email");



      }
      }
      }


      Comment


        #4
        just note that there is no space on "alert", i don't know why it appears when i copy / paste it

        Comment


          #5
          Hello Thomas79,

          Thank you for your replies.

          It looks like there are some issues with your syntax. I'd suggest trying to set this up in the Strategy Builder in NinjaTrader 8 and then unlocking the code so you can see the proper syntax.

          The best way to begin learning NinjaScript for NinjaTrader 8 is to use the Strategy Builder. With the Strategy Builder you can setup conditions and variables and then see the generated code in the NinjaScript Editor by clicking the View Code button.

          I'm also providing a link to a pre-recorded set of videos 'Strategy Builder 301' and 'NinjaScript Editor 401' for you to view at your own convenience.

          Strategy Builder 301
          NinjaScript Editor 401

          You'll want to focus on the Conditions and Actions screen. This will allow you to set up your condition (the RSI being greater than 20) and your actions (throwing an alert and sending an email).

          Here's an example screenshot of how I set this up in the Builder:

          Click image for larger version

Name:	2019-05-23_1236.png
Views:	1
Size:	96.3 KB
ID:	1058576

          Once you've set that up, unlock the code and take a look at the file structure and syntax - this is the best way to understand how you should be setting up your scripts.

          As far as the email part, please make sure in the Share Settings that you can send and receive test emails. You can do this by going to Tools > Options > General > Share Services > Edit Share Service > choose your configured email from the bottom left > Click the Send Email Test button. You should see a notation in the Log Tab of the Control Center and also receive the email if it sends successfully. If not, you'll need to double check your Share Services settings.

          Please let me know if you set this up in the strategy builder and still cannot get the alert to fire.

          Thanks in advance; I look forward to assisting you further.
          Kate W.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by chazyang, Today, 02:01 AM
          1 response
          3 views
          0 likes
          Last Post chazyang  
          Started by tonynt, Today, 01:20 AM
          0 responses
          13 views
          0 likes
          Last Post tonynt
          by tonynt
           
          Started by sdauteuil, Yesterday, 11:02 PM
          1 response
          3 views
          0 likes
          Last Post sdauteuil  
          Started by Jschmelz, Yesterday, 04:45 PM
          1 response
          9 views
          0 likes
          Last Post NinjaTrader_Marco  
          Started by sisenberg, Yesterday, 08:06 PM
          1 response
          11 views
          0 likes
          Last Post sisenberg  
          Working...
          X