Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Indicator Development

Indicator Development Support for the development of custom indicators using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 02-07-2010, 02:11 PM   #16
Paul79
Junior Member
 
Join Date: Feb 2010
Posts: 20
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks Ralph but what i mean by highestsince is different (this is from amibroker AFL and this is what i want):

AFL Function Reference - HIGHESTSINCE HIGHESTSINCE
- highest value since condition met





SYNTAX highestsince( EXPRESSION, ARRAY, Nth = 1 ) RETURNS ARRAY FUNCTION Returns the highest ARRAY value since EXPRESSION was true on theNth most recent occurrence. EXAMPLE highestsince( Cross( macd(), 0 ), Close, 1 ) returns the highest close price since macd() has crossed above zero.
Also there is valuewhen

AFL Function Reference - VALUEWHEN VALUEWHEN
- get value of the array when condition met





SYNTAX valuewhen(EXPRESSION, ARRAY, n = 1) RETURNS ARRAY FUNCTION Returns the value of the ARRAY when the EXPRESSION was true on the n -th most recent occurrence. Note: this function allows also 0 and negative values for n - this enables referencing future EXAMPLE valuewhen( cross( close, ma(close,5) ) ,macd(), 1)
so basically the above ready made function I search. In the end i will probably manage to solve them and if i define them within "UserdefinedMethods" I should be able to use them in any indicator. what I do not understand is why they are not already defined, should be extremely easy for a programmer but for me its pretty difficult to learn c++ and I dont need C++ to trade. That is why I said that Ninja programmers should make this easier for traders by defining such functions because I personally am really not interested in learning computer languages.

PS:
Ralph if you can solve them fast and put them here I wont mind
Paul79 is offline  
Reply With Quote
Old 02-07-2010, 02:55 PM   #17
Ralph
Senior Member
 
Join Date: Jul 2008
Posts: 531
Thanks: 0
Thanked 11 times in 8 posts
Default

Something like this?
Note that BarsSince starts with 1 for this application.

int BarsSince;
int hBar;

protected override void OnBarUpdate()
{
BarsSince = CrossAbove(CCI(14), 100, 1) ? 1 : BarsSince++;
hBar = HigestBar(<High,Low,Open,Close>, BarsSince);
}

Regards
Ralph
Ralph is offline  
Reply With Quote
Old 02-07-2010, 03:11 PM   #18
Paul79
Junior Member
 
Join Date: Feb 2010
Posts: 20
Thanks: 0
Thanked 0 times in 0 posts
Default

Not quite, Highestbar method (function returns number of bars ago highest price value occured for lookback period and I need the highest high for the data series since the event took place. Besides that highestsince should be able to return more than last highest high. Its hard to explain but this says all:

highestsince( EXPRESSION, ARRAY, Nth = 1 )

Returns the highest ARRAY value since EXPRESSION was true on theNth most recent occurrence. Like for example finding the highest high of the close price since second last time when CCI(14) crosses 100 would be

highestsince(CrossAbove(CCI(14)[0],100,1),Close,2)

...just as a example if it would be defined, so basically thats what I want to create and then define with "UserDefinedMethods" so I can replace CCI and Close with any other indicators or prices.

Thanks anyway Ralph.
Paul79 is offline  
Reply With Quote
Old 02-07-2010, 05:35 PM   #19
Ralph
Senior Member
 
Join Date: Jul 2008
Posts: 531
Thanks: 0
Thanked 11 times in 8 posts
Default

The List hBars should contain the bar numbers of the highest bar after each crossover event (not tested).

Regards
Ralph


List<int> hBars = new List<int>();
int lastIndex = -1;
double lastHigh;

protected override void OnBarUpdate()
{
if (CurrentBar < 2) return;
if (FirstTickOfBar)
{
if (CCI(14)[1] > 100 && CCI(14)[2] < 100)
{
hBars.Add(CurrentBar - 1);
lastHigh = High[1];
lastIndex++;
}
else if (lastIndex >= 0)
{
if (High[1] > lastHigh)
{
lastHigh = High[1];
hBars[lastIndex] = CurrentBar - 1;
}
}
}
Ralph is offline  
Reply With Quote
Old 02-08-2010, 05:45 AM   #20
Paul79
Junior Member
 
Join Date: Feb 2010
Posts: 20
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks Ralph but its not what I want. Thanks anyway. However here`s a new problem: i have defined barssince function (method) within "UserDefinedMethods" so I can use it with any custom indicator but the problem is that it only works once. I mean if i try to use it 2 times in the same custom indicator then it messes up everything and does not give the right result.

here is the code used in "UserDefinedMethods"

partial class Indicator
{
int trigger;
public int barssince(bool array)
{
if (array==true)
{
trigger=CurrentBar;
}
if(CurrentBar>trigger)
{
return(CurrentBar-trigger);
}
else
{
return(0);
}
}
}


the above code defines a function barssince(event) that will count the number of bars since event was true.

It works like this barssince(CrossAbove(CCI(14),100,1)) this will count the number of bars after each cross of CCI14 above 100 then will reset to zero and count again at the next cross. It works fine alone but if I try to add another barssince like this barssince(CrossBelow(CCI(14),-100,1)) in the same custom indicators then it does not give the right result. see the code bellow;

double a;
double b;


protected override void OnBarUpdate()
{
if(CurrentBar>0)
{
a=barssince(CrossAbove(CCI(14),100,1));
}
if(CurrentBar>0)
{
b=barssince(CrossBelow(CCI(14),-100,1));
}
Plot0.Set(a);
Plot1.Set(b);
}


Maybe someone knows why and how to solve it? Maybe there is something I did not do right in "UserDefinedMethods" and because of that it messes up everything when used twice in the same custom indicator?

...help???
Paul79 is offline  
Reply With Quote
Old 02-08-2010, 05:56 AM   #21
Paul79
Junior Member
 
Join Date: Feb 2010
Posts: 20
Thanks: 0
Thanked 0 times in 0 posts
Default

It seems, I post i answer, however sometimes the simpliest solutions are the hardest to see. I just added another barssince named barssince1 in to the userdefined methods like this

partial class Indicator
{
int trigger;
public int barssince(bool array)
{
if (array==true)
{
trigger=CurrentBar;
}
if(CurrentBar>trigger)
{
return(CurrentBar-trigger);
}
else
{
return(0);
}
}
int trigger1;
public int barssince1(bool array1)
{
if (array1==true)
{
trigger1=CurrentBar;
}
if(CurrentBar>trigger1)
{
return(CurrentBar-trigger1);
}
else
{
return(0);
}
}
}
Paul79 is offline  
Reply With Quote
Old 02-08-2010, 06:01 AM   #22
Ralph
Senior Member
 
Join Date: Jul 2008
Posts: 531
Thanks: 0
Thanked 11 times in 8 posts
Default

Exactly Paul,

you need one for CrossAbove and one for CrossBelow. A better approach would be to implement barssince() as a class. Then you could instantiate class instances as often as you desire and use them independently without the need to duplicate code.

Regards
Ralph
Ralph is offline  
Reply With Quote
Old 02-08-2010, 06:09 AM   #23
Paul79
Junior Member
 
Join Date: Feb 2010
Posts: 20
Thanks: 0
Thanked 0 times in 0 posts
Default

what is that Ralph? I mean..what is a class? and how to implement it?. If you mean to have a single barssince(event) method that works anywhere like a new function then that will be great. If you know how to do it then maybe we could add a few new functions to Ninja to make it a little easier. i have no ideea what a class means but I supose that is what you meant.
Paul79 is offline  
Reply With Quote
Old 02-08-2010, 07:28 AM   #24
Ralph
Senior Member
 
Join Date: Jul 2008
Posts: 531
Thanks: 0
Thanked 11 times in 8 posts
Default

An indicator is implemented as a class for instance.
First you design a class.
Second you instantiate an instance of your class in your application and then you can access the class' public methods and properties.

However, since this concept is unknown to you lets consider this task from another side: Why even implement it as a function? I mean the functionality required is as simple as this:

int BarsSinceCrossAbove;

protected override void OnBarUpdate()
{
BarsSinceCrossAbove= CrossAbove(CCI(14), 100, 1) ? 1 : BarsSinceCrossAbove++;
Plot0.Set(BarsSinceCrossAbove);
}

Regards
Ralph
Ralph is offline  
Reply With Quote
Old 02-08-2010, 07:42 AM   #25
Paul79
Junior Member
 
Join Date: Feb 2010
Posts: 20
Thanks: 0
Thanked 0 times in 0 posts
Default

Ralph, the below code does not work, however I solved barssince and it would be truly nice to implement it as a class from what I understand. I am not used with all the "nuts and bolts" C++ requires and honestly dont want to know them but I know very well to code in languages like Metstock`s or easylanguage or amibroker`s. Implementing functions like barssince(event) as a class so they could be used as easy as a SMA for example would be great and I think would not be such a big deal for someone that is a programmer. I dont understand why ninja people want to make programmers out of traders. Now I have to solve that highestsince function (method) and again I am stuck...by the time I will finish I could start to write a new software myself and I trade not develop software...LOL. Thanks for your help.
Paul79 is offline  
Reply With Quote
Old 02-08-2010, 07:56 AM   #26
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 25,793
Thanks: 432
Thanked 1,689 times in 1,646 posts
Default

Paul79, jumping in here...did you check into the MRO / LRO methods supplied per default for those tasks?
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 02-08-2010, 08:09 AM   #27
Paul79
Junior Member
 
Join Date: Feb 2010
Posts: 20
Thanks: 0
Thanked 0 times in 0 posts
Default

Bertrand I have no clue what MRO / LRO or whatever means, and about jumping in here, I expected to solve some simple problems in less than 1 hour as i did with whatever other software for traders BUT Ninja that took me 2 days to solve barssince(event)... "nuts and bolts" as I was saying. Now if you are kind enough to explain MRO /LRO and enlighten me that would be great else thanks for mention I will search them myself.
Paul79 is offline  
Reply With Quote
Old 02-08-2010, 08:11 AM   #28
Paul79
Junior Member
 
Join Date: Feb 2010
Posts: 20
Thanks: 0
Thanked 0 times in 0 posts
Default

Oh..Bertrand you sure you know how to talk with customers? 995$ paid for the software its not a small amount and I hate when people are rude after I paid money.
Paul79 is offline  
Reply With Quote
Old 02-08-2010, 08:19 AM   #29
Paul79
Junior Member
 
Join Date: Feb 2010
Posts: 20
Thanks: 0
Thanked 0 times in 0 posts
Default

For that matter your MRO /LRO Bertrand has nothing to do with solving methods like valuewhen, highestsince or others and pretty much makes no difference, barssince I solve it already...after 2 days.
Paul79 is offline  
Reply With Quote
Old 02-08-2010, 11:18 AM   #30
Ralph
Senior Member
 
Join Date: Jul 2008
Posts: 531
Thanks: 0
Thanked 11 times in 8 posts
Default

Hi Paul, here is an implementation of the trigger bar counter as a separate class (HelperClass). In HelperClassTest you can see how this class is applied 2 times (up- and down-counter). Just use File->Utilities->NinjaScriptImport to install.

The little picture depicts the HelperClassTest in action. The green line counts the bars after the down trigger events, the orange line accordingly vice versa.

However, with this example you can see which way to go if using this approach. You should try to understand this concept before starting own developments, otherwise you won't get happy with that.

Regards
Ralph
Attached Images
File Type: jpg HelperClassTest.jpg (42.5 KB, 51 views)
Attached Files
File Type: zip HelperClassTest.zip (5.8 KB, 23 views)
Ralph is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Minimum bars required condition. ju1234 Strategy Development 11 06-01-2010 01:07 PM
Enter on bars, exit on ticks and min bars requirment coolraz Strategy Development 3 12-15-2008 10:59 AM
Painting bars based on condition question ericadam General Programming 7 09-05-2008 09:07 AM
Bars are wrong on strategy performance (negative bars) woodside Historical NinjaTrader 6.5 Beta Threads 2 01-13-2008 11:22 PM
Momentum bars or Price Range Bars Akros Indicator Development 7 06-10-2007 04:55 AM


All times are GMT -6. The time now is 07:03 AM.

FULL RISK DISCLOSURE: Futures trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.