NexusFi: Find Your Edge


Home Menu

 





importing .Net into Ninja


Discussion in NinjaTrader

Updated
    1. trending_up 2,549 views
    2. thumb_up 2 thanks given
    3. group 2 followers
    1. forum 3 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 
spinnybobo's Avatar
 spinnybobo 
Crete, IL/USA
 
Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Trading: ES, CL, EUR/USD, TF
Posts: 173 since Aug 2009
Thanks Given: 105
Thanks Received: 61

Hello

I currently am trying to write a program to do the following:

On current Bar (using Daily time frame) of the ES, find out which contract is the current contract and then which contract is the next contract.
So, if the last bar is Friday Feb 03 2012, then it would be
 
Code
string currentDate = "03 Feb 2012";
//The first day of trading on March to last day before rollover
     if ((currentDate >= "08 Dec 2011") && currentDate <= "07 March 2012")) 
string currentContract = "201203"; //March 2012 ES contract
Then the next thing I want to do is figure out that the next contract is June
 
Code
string nextContract = "201206"; //so I have to add 3 to the end

Then I want to take the current close of the current bar for 201203 and 201206 and take the difference.
if the currentDate.Close[0] > nextContract.Close[0]
    print Green Dot
else
    print Grey Dot
So, I have like 55 or so ES contracts from 1997 and wanted to figure this out. So, for each bar, it would have to check first which contract is being traded, which is the next contract, and then take the different of the current bar close of each contract, and if the currentContract > nextContract, show that as a bullish sign on the chart.

Also, I went through all 55 or so contracts the other day, and made an excel spread sheet according to contract rollover, and manually put in the Start Date, End Date, Contract Name

So, I have all of that start and stop data. Now I just need to know how to use this in Ninja Trader.
Also, I want to have this be an indicator in the bottom panel and therefore do not care if it is ES, or DJIA, or SPX, or GOOG in the upper panel as it does not depend on the upper panel data

I dont know how hard this would be.

I know that in C# (ASP.Net in this case), you can use something like this:
 
Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }
    protected void btnResults_Click(object sender, EventArgs e)
    {

        DateTime start = Convert.ToDateTime(txtStartDate.Text);
        
        DateTime end = Convert.ToDateTime(txtEndDate.Text);
        DateTime today = DateTime.Today;
        if ((start <= today) && (end >= today))
        {
            lblOutput.Text = "Valid";
        }
        else
            lblOutput.Text = "Not Valid";
    }
}
Also, that leads to the title of this post: I dont see the DateTime class in NinjaTrader.
I thought NinjaTrader included all of the entire .Net Libraries Framework. Maybe I am confused, but if I dont see that DateTime class in Ninja
and it is in Visual Studio 2012, how do I get it into NinjaTrader, so I can develop with it?

thanks
Spencer


Follow me on X Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Iran Lebanon Problem Kills Switzerland Talks, Brent at $ …
Prediction Markets & Event Contracts
Would a node-based workflow for automated trading be useful?
Traders Hideout
Irans Dual Probability: Guns Quiet at 99.95% While Forma …
Prediction Markets & Event Contracts
Iran Update May 8: Still Reviewing MOU, Demands Reparati …
Traders Hideout
Al Arabiya: US-Iran Draft Deal Within Hours Contains Hor …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
NexusFi site changelog and issues/problem reporting
10 thanks
Darmok and Jalad at Tanagra
3 thanks
Big Mike in Ecuador
1 thanks
30 Sessions
1 thanks
  #2 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,759 since Jun 2009
Thanks Given: 3,828
Thanks Received: 4,645

???
DateTime in included in "System", so you can use it directly in NinjaScript:
 
Code
                            
System.DateTime   m = new DateTime(20120209224735);; 


Success requires no deodorant! (Sun Tzu)
Reply With Quote
Thanked by:
  #3 (permalink)
 
spinnybobo's Avatar
 spinnybobo 
Crete, IL/USA
 
Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Trading: ES, CL, EUR/USD, TF
Posts: 173 since Aug 2009
Thanks Given: 105
Thanks Received: 61


HI Sam

thanks. I got confused because when I just typed DateTime in NinjaTrader, no intelisense popped up.
However, when I do it in visual studio, it pops up.

So, I am used to Java more than C# and how it works with libraries. Java is very portable and I always have to add the library to eclipse, then just import com.etc.......

In .Net, everything is already in the GAC so does that mean everything accessible by Visual Studio is also accessible by NinjaTrader by default-----no need to install additional .dll's, just word it correctly

Visual Studio:
DateTime start = Convert.ToDateTime("10 May 2010");

Ninja Trader:
System.DateTime start = Convert.ToDateTime("10 May 2010");

Does this sound right since both say using System; in the top?

thanks
Spencer


Follow me on X Started this thread Reply With Quote
  #4 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,759 since Jun 2009
Thanks Given: 3,828
Thanks Received: 4,645

You can write
 
Code
                            
System.DateTime start Convert.ToDateTime("10 May 2010"); 

or
 
Code
                            
DateTime start Convert.ToDateTime("10 May 2010"); 

it doesn't matter, it's the same thing.


Success requires no deodorant! (Sun Tzu)
Reply With Quote
Thanked by:




Last Updated on February 5, 2012


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts