NexusFi: Find Your Edge


Home Menu

 





Help Coding In Ninja From TS


Discussion in NinjaTrader

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




 
Search this Thread

Help Coding In Ninja From TS

  #1 (permalink)
 
marketprofiletrader's Avatar
 marketprofiletrader 
Fort Lupton, CO/ USA
 
Experience: Intermediate
Platform: NinjaTrader, Market Delta
Broker: AMP Futures and CQG Data
Trading: 30yr Bonds ZB
Posts: 7 since Aug 2009
Thanks Given: 2
Thanks Received: 1

Hello All,

I am new to ninja trader development and trying to see if anyone can help me to create an indicator that plots current days price + or - to previous days close as of 4:15pm EST on each bar of the current day as a histogram.

ie; ES close previous day 982.00 & Current 5min or whatever period bar closes at 984.00

so histogram at close of current bar below it would plot, +2.00

or if current bar closed at 980.00 then the histogram at close of bar below it would plot, -2.00

If anyone could put me on the path or show me how that would be written in ninja, I would greatly appreciate it! God Bless and Good Trading To All.

Brian

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
How to apply profiles
Traders Hideout
Trade idea based off three indicators.
Traders Hideout
MC PL editor upgrade
MultiCharts
What broker to use for trading palladium futures
Commodities
ZombieSqueeze
Platforms and Indicators
 
  #2 (permalink)
 
caprica's Avatar
 caprica 
USA
 
Experience: Master
Platform: NinjaTrader
Posts: 155 since Jul 2009
Thanks Given: 45
Thanks Received: 114


marketprofiletrader View Post
Hello All,

I am new to ninja trader development and trying to see if anyone can help me to create an indicator that plots current days price + or - to previous days close as of 4:15pm EST on each bar of the current day as a histogram.

ie; ES close previous day 982.00 & Current 5min or whatever period bar closes at 984.00

so histogram at close of current bar below it would plot, +2.00

welcome to the forum there bud. i see you and i think alike it seems because this is exactly the kind of work i like to do and discover and research. i think this type of method has much more value than traditional indicators.

thinking out loud...

 
Code
                            

double PrevDayClose
()
{

double _prevclose 0;

try
{
DateTime _prevday Time[0].AddDays(-1);

// make sure prior day is always mon-fri never sat or sun

if (Time[0].DayOfWeek == DayOfWeek.Monday)
 
_prevday Time[0].AddDays(-3);

if (
Time[0].DayOfWeek == DayOfWeek.Sunday)
 
_prevday Time[0].AddDays(-2);

_prevclose Close[GetBar(new DateTime(_prevday.Year_prevday.Month_prevday.Day16150))]; // where 16,15,0 means 4:15:00pm based on local PC time

}
catch(
Exception e)
{
Print (
e.ToString()); // just incase index is exceeded somewhere
}


return 
_prevclose;


i think that will get you the prev day close and account for weekends and lack of historical data, etc.

then you need to compare that value vs current close of last bar... something like:

 
Code
                            
double difference PrevDayClose() - Close[0]; 

you should be able to then plot that difference easily if you've ever written any indicator before. once you have the final product please do post it back and share it!

"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

Reply With Quote
Thanked by:
  #3 (permalink)
 
marketprofiletrader's Avatar
 marketprofiletrader 
Fort Lupton, CO/ USA
 
Experience: Intermediate
Platform: NinjaTrader, Market Delta
Broker: AMP Futures and CQG Data
Trading: 30yr Bonds ZB
Posts: 7 since Aug 2009
Thanks Given: 2
Thanks Received: 1


Hi Caprica,

Thanks for this code, I will play around and see if I can get what I want from here and then I will repost as requested. Since I am new here, when I get it the way I want it you will be the first to know!

Thanks again for your help in this.

Started this thread Reply With Quote
  #4 (permalink)
 
marketprofiletrader's Avatar
 marketprofiletrader 
Fort Lupton, CO/ USA
 
Experience: Intermediate
Platform: NinjaTrader, Market Delta
Broker: AMP Futures and CQG Data
Trading: 30yr Bonds ZB
Posts: 7 since Aug 2009
Thanks Given: 2
Thanks Received: 1

Here is an exact copy of the TS code I am trying to Reproduce in NinjaTrader,
I am not sure, but I don't think I can have 2 symbols on the same chart in NinjaTrader, like you can in TS so I am only interested in the Plot working for the current symbol that I would be able to place the indicator on. If I needed to place 2 seperate charts up to get the same effect as TS with 1 chart that would be fine also. Thanks all, Brian.

Inputs: PriceES(Close of Data1),
PriceNDQ(Close of Data2);
Vars: ESLevel(0), NDQLevel(0), ESYDC(0), NDQYDC(0),
Started(FALSE);
if Date<>Date[1] then
begin
ESYDC = Close[1];
NDQYDC = PriceNDQ[1];
Started=TRUE;
end;
if Started then
begin

ESLevel = Close-ESYDC;
NDQLevel = PriceNDQ-NDQYDC;

end;

Plot1(ESLevel,"es");
Plot2(NDQLevel,"ndq");
Plot3(0,"zero");

if Date<>Date[1] then begin

Print("");
Print("");

end;

Print(Date:10:0,Time:6:0,"ES=",ESLevel," NQ=",NDQLevel);

Started this thread Reply With Quote
  #5 (permalink)
 David 
UK
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Futures
Posts: 88 since Jun 2009
Thanks Given: 35
Thanks Received: 84

Theres actually a bug in Caprica's code.

You should change this line:

 
Code
_prevclose = Close[0][GetBar(new DateTime(_prevday.Year, _prevday.Month, _prevday.Day, 16, 15, 0); // where 16,15,0 means 4:15:00pm based on local PC time 
to
 
Code
                
_prevclose = Close[GetBar(new DateTime(_prevday.Year, _prevday.Month, _prevday.Day, 16, 15, 0))]; // where 16,15,0 means 4:15:00pm based on local PC time
It creates an interesting indicator :-)

David

Reply With Quote
Thanked by:
  #6 (permalink)
 David 
UK
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Futures
Posts: 88 since Jun 2009
Thanks Given: 35
Thanks Received: 84

Here is a working indicator based on Caprica's code

David

Attached Thumbnails
Click image for larger version

Name:	ES 09-09  25_06_2009 (4 Range).jpg
Views:	250
Size:	130.2 KB
ID:	1003  
Attached Files
Elite Membership required to download: ClosingPriceComparison.zip
Reply With Quote
Thanked by:
  #7 (permalink)
 
caprica's Avatar
 caprica 
USA
 
Experience: Master
Platform: NinjaTrader
Posts: 155 since Jul 2009
Thanks Given: 45
Thanks Received: 114


David View Post
Theres actually a bug in Caprica's code.

You should change this line:

 
Code
_prevclose = Close[0][GetBar(new DateTime(_prevday.Year, _prevday.Month, _prevday.Day, 16, 15, 0); // where 16,15,0 means 4:15:00pm based on local PC time 
to
 
Code
                
_prevclose = Close[GetBar(new DateTime(_prevday.Year, _prevday.Month, _prevday.Day, 16, 15, 0))]; // where 16,15,0 means 4:15:00pm based on local PC time
It creates an interesting indicator :-)

David

oops thanks david I typed that by hand as i went because i've got some similar code that i use for some other functions and i had to take only the relevant portion out of my code.

if you have thrown it all the way into an indicator can you post it and a screenshot? do you find it useful?

"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

Reply With Quote
  #8 (permalink)
 
caprica's Avatar
 caprica 
USA
 
Experience: Master
Platform: NinjaTrader
Posts: 155 since Jul 2009
Thanks Given: 45
Thanks Received: 114

oh cool you just did

"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

Reply With Quote
  #9 (permalink)
 David 
UK
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Futures
Posts: 88 since Jun 2009
Thanks Given: 35
Thanks Received: 84

Caprica, you did all the hard work, I just threw it into an indicator

Its too early to tell if the indicator is useful. It seems to be one of those that intuitively should provide a good insight - I personally think yesterdays closing, high and low do influence trading today, however I won't be using it as part of my ATS.

David

Reply With Quote




Last Updated on August 3, 2009


© 2024 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 - Privacy Policy - Downloads - Top
no new posts