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

Sendmail to subscriberlist

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

    Sendmail to subscriberlist

    I have a strategy sending emails to a subscriberlist in .csv format.
    Everything works but only for the subscriber on the first row.
    What should I do to send an email to every row?

    This is the code:

    protected override void OnBarUpdate()
    {

    string path = NinjaTrader.Cbi.Core.UserDataDir + usersFile;

    // This command clears all data from the output window.
    ClearOutputWindow();

    ToField="";

    // This command will just print a blank line in the output window.
    Print("MorningSignals_Email_Service");

    string readText = File.ReadAllText(path);
    string [] split = readText.Split(new Char [] { ',' , '\n'});
    int splitCounter = 0;
    int rows = 0;
    ToList = "";
    foreach (string s in split)
    {
    if (s.Trim() != "")
    {
    splitCounter++;
    Print(splitCounter.ToString() + ':' + s);
    if (splitCounter == 1) field1 = s;
    if (splitCounter == 2)
    {
    field2 = s;
    if(ToList!="") ToList=ToList + ", " + s;
    else if(ToList=="") ToList=s;

    }
    if (splitCounter == 3) field3 = s;
    if (splitCounter == 4) field4 = s;
    }
    }
    Print("ToList: "+ToList);
    Print("rows: "+ rows);
    }
    string[] ToListArray = ToList.Split(',');

    #2
    Hello daxtrading,

    This is more C# related than NinjaScript so unfortunately outside our scope of support.

    You can likely iterate through the objects in the array with a for loop.

    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_RyanM View Post
      Hello daxtrading,

      This is more C# related than NinjaScript so unfortunately outside our scope of support.

      You can likely iterate through the objects in the array with a for loop.

      http://www.ninjatrader.com/support/h...g_commands.htm
      I soved my problem but want your advise on the fills of the orders.

      Now I use this line: "\nPrice: " + Close[0].ToString()
      This is alway on barclose and the real fill isn't.
      What could I do to get the fillprice?

      Comment


        #4
        You can use Position.AvgPrice to get an average of your position fill prices. If you wanted the fill for a specific order, you'd have to work with the IExecution interface and expose this.



        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_RyanM View Post
          You can use Position.AvgPrice to get an average of your position fill prices. If you wanted the fill for a specific order, you'd have to work with the IExecution interface and expose this.



          http://www.ninjatrader.com/support/h...iexecution.htm
          What should be the code for the IExecution in instead of this: "\nPrice: " + Close[0].ToString()

          Comment


            #6
            Working with IExecution is advanced NinjaScript. This sample can help get you started working with these methods:

            Using OnOrderUpdate() and OnExecution() methods to submit protective orders

            The price is then exposed with Order.Price

            There's a change in this area in version 7. When comparing orders for equality, you compare the IOrders objects directly, rather than the token.
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_RyanM View Post
              Working with IExecution is advanced NinjaScript. This sample can help get you started working with these methods:

              Using OnOrderUpdate() and OnExecution() methods to submit protective orders

              The price is then exposed with Order.Price

              There's a change in this area in version 7. When comparing orders for equality, you compare the IOrders objects directly, rather than the token.
              Not being a programmer at all, but very interested in the way my strategies work, I think I am almost there with Execution.

              Let me show you what I have now...
              For the entry:
              if (Contracts==1) {entryOrder = EnterLong(1,"EL1");}

              For the OnExecution() methode:
              protected override void OnExecution(IExecution execution)
              {
              if (entryOrder != null && entryOrder.Token == execution.Order.Token)
              {
              if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
              {
              // Resets the entryOrder object to null after the order has been filled or partially filled
              if (execution.Order.OrderState != OrderState.PartFilled)
              {
              entryOrder = null;
              }
              }
              }

              }
              Now I need help for my Price in my Email....
              What should I do for the following row: "\nPrice: " + Close[0].ToString()

              Comment


                #8
                The part highlighted in red is no longer used in version 7. You compare objects directly.

                You can capture the execution price in a variable when it's filled.

                protected override void OnExecution(IExecution execution)
                {
                if (entryOrder != null && entryOrder.Token == execution.Order.Token)
                {
                if (execution.Order.OrderState == OrderState.Filled)
                double myExecutionPrice = execution.Price;
                }
                }
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_RyanM View Post
                  The part highlighted in red is no longer used in version 7. You compare objects directly.

                  You can capture the execution price in a variable when it's filled.

                  protected override void OnExecution(IExecution execution)
                  {
                  if (entryOrder != null && entryOrder.Token == execution.Order.Token)
                  {
                  if (execution.Order.OrderState == OrderState.Filled)
                  double myExecutionPrice = execution.Price;
                  }
                  }
                  Can you tell me what to do with:
                  double myExecutionPrice = execution.Price;
                  and where to put this code?

                  Comment


                    #10
                    This is a variable that captures the execution price during a fill. From this point how you use this variable is up to you.
                    Ryan M.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_RyanM View Post
                      This is a variable that captures the execution price during a fill. From this point how you use this variable is up to you.
                      Where do I put the line: double myExecutionPrice = execution.Price;
                      Is it in #region Internal Variables?
                      Where do I put it to get the price in my email?

                      Comment


                        #12
                        Hi Dax,

                        This is an example of capturing execution price. Where it goes is indicated in the example. It's part of the whole IExecution interface.

                        What you do with this variable in your code is completely up to you. We unfortunately can't provide custom coding services. If you're looking for this please see a list of NinjaScript consultants at the link below:
                        Ryan M.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_RyanM View Post
                          Hi Dax,

                          This is an example of capturing execution price. Where it goes is indicated in the example. It's part of the whole IExecution interface.

                          What you do with this variable in your code is completely up to you. We unfortunately can't provide custom coding services. If you're looking for this please see a list of NinjaScript consultants at the link below:
                          http://www.ninjatrader.com/webnew/pa...injaScript.htm
                          Ok, I am almost there and got it working, only the executionprice is not correct.
                          Does it not work because of testing in replay?
                          Where do I put the call for the price to send by mail to get the right price?
                          Maybe I should use IOrder?

                          Comment


                            #14
                            There's no shortcut to debugging. You'll have to use plenty of Print() statements and TraceOrders output.

                            Debugging your NinjaScript Code

                            This is not a simple property you can access. Yes, IOrder is a necessary aspect to work with IExecution interface. You need all the components of the sample and an understanding of the mechanics in order to work this successfully into your code. If this example is too complex, you might want to use Position.AvgPrice to capture the average price for your positions.
                            Ryan M.NinjaTrader Customer Service

                            Comment


                              #15
                              Getting smarter every day and think I have it almost fixed,

                              I changed from IEcecution to IOrder and put this code before OnBarUpdate:
                              protected override void OnOrderUpdate(IOrder order)
                              {
                              if (entryOrder != null && entryOrder == order)
                              {
                              if (order.OrderState == OrderState.Filled)
                              Print(order.AvgFillPrice.ToString());

                              myOrderPrice = order.AvgFillPrice;

                              entryOrder = null;
                              }
                              }

                              I did this cause this works for 1 email by SendMail.
                              Can you tell me why myOrderPrice shows zero and not the OrderFillPrice?
                              Is this because the Order is in OnBarUpdate and if so, help me to fixe it.
                              Last edited by daxtrading; 11-05-2010, 03:11 AM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by cre8able, Yesterday, 01:16 PM
                              3 responses
                              11 views
                              0 likes
                              Last Post cre8able  
                              Started by ChartTourist, Today, 08:22 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post ChartTourist  
                              Started by LiamTwine, Today, 08:10 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post LiamTwine  
                              Started by Balage0922, Today, 07:38 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post Balage0922  
                              Started by JoMoon2024, Today, 06:56 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post JoMoon2024  
                              Working...
                              X