NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


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 12-17-2009, 05:07 PM   #1
Lobo
Junior Member
 
Join Date: Oct 2006
Location: , ,
Posts: 11
Thanks: 0
Thanked 0 times in 0 posts
Default Bollinger unaffected by gaps.

If somebody could help convert this to NinjaScript for me I will insert into remainder of code and then display as a whole to finish the conversion as there will be errors. This Bollinger is unaffected by opening gaps. Great indicator.


if date<>date[1] then
begin
gap = GapCoef*(O-C[1]);
Accum = Accum+gap;
end;
Last edited by Lobo; 12-17-2009 at 05:26 PM. Reason: More info.
Lobo is offline  
Reply With Quote
Old 12-17-2009, 07:21 PM   #2
mrlogik
Certified NinjaScript Consultant
 
mrlogik's Avatar
 
Join Date: Sep 2006
Location: New York, USA
Posts: 774
Thanks: 1
Thanked 7 times in 5 posts
Default

hey lobo,

is GapCoef a custom function? I don't see it in my TS library.

It should to something like this

Code:
double gap = 0;
double accum = 0;
if(Time[0].Date != Time[1].Date)
{
    gap = GapCoef(Open[0] - Close[1]);
    accum += gap;
}
But this assumes you have the GapCoef() function in NT.

hope this helps.
"You look closely enough, you can find everything has a ... weak spot where it can break, sooner or later"

PureLogikTrading
mrlogik is offline  
Reply With Quote
Old 12-18-2009, 09:23 AM   #3
Lobo
Junior Member
 
Join Date: Oct 2006
Location: , ,
Posts: 11
Thanks: 0
Thanked 0 times in 0 posts
Default

Hey MrLogic. GapCoef is basically an input. Can be exchanged for 1.0 for now.
1.0*(O-C[1]); accomplishes the same thing. I will include a more detailed explaination soon. I can see this code is going to need a bit of modifying. Thanks for your help.
Lobo is offline  
Reply With Quote
Old 12-18-2009, 09:29 AM   #4
mrlogik
Certified NinjaScript Consultant
 
mrlogik's Avatar
 
Join Date: Sep 2006
Location: New York, USA
Posts: 774
Thanks: 1
Thanked 7 times in 5 posts
Default

No problem.

Good Luck
"You look closely enough, you can find everything has a ... weak spot where it can break, sooner or later"

PureLogikTrading
mrlogik is offline  
Reply With Quote
Old 12-18-2009, 10:23 AM   #5
Lobo
Junior Member
 
Join Date: Oct 2006
Location: , ,
Posts: 11
Thanks: 0
Thanked 0 times in 0 posts
Default

Well, having a problem with StdDev function so I will post EL code in it's whole to save some time.

inputs:
Length( 19),
NumDevsUp( 1.9),
NumDevsDn( -1.9);

variables:
Avg( 0 ),
SDev( 0 ),
LoBand( 0 ),
MidLine( 0 ),
UpBand( 0 ) ;
// gapless day transitions - John McCormick May 2008

Vars:
RelC(0), // Relative Close
gap(0), // the opening gap (modified by the gap coefficient)
GapCoef(1.0), // Gap Coefficient
Accum(0); // The sum of all the daily gaps

if date<>date[1] then
begin
gap = GapCoef*(O-C[1]);
Accum = Accum+gap;
end;

RelC = C-Accum;

// Gapless - end

MidLine = AverageFC( RelC, Length ) + accum ;
SDev = StandardDev( RelC, Length, 1 );

UpBand = MidLine + NumDevsUp * SDev ;
LoBand = MidLine + NumDevsDn * SDev ;


Plot1( UpBand, "BolUpBand" ) ;
Plot2( LoBand, "BolLoBand" ) ;
Plot3( MidLine, "BolMidL" ) ;
Lobo is offline  
Reply With Quote
Old 12-18-2009, 11:18 AM   #6
mrlogik
Certified NinjaScript Consultant
 
mrlogik's Avatar
 
Join Date: Sep 2006
Location: New York, USA
Posts: 774
Thanks: 1
Thanked 7 times in 5 posts
Default

Happy holidays.

Attached.
Attached Files
File Type: zip Lobo_indie.zip (5.5 KB, 13 views)
"You look closely enough, you can find everything has a ... weak spot where it can break, sooner or later"

PureLogikTrading
mrlogik is offline  
Reply With Quote
Old 12-18-2009, 02:58 PM   #7
Lobo
Junior Member
 
Join Date: Oct 2006
Location: , ,
Posts: 11
Thanks: 0
Thanked 0 times in 0 posts
Wink

Thanks for the effort! These gapless indicators can't be beat as far as I'm concerned. There is still something strange here though as it is preforming as though it is a normal Bollinger. I have checked the identical code that I posted with TS and works correctly there. Will look deeper into it tomorrow and let you know. Will try to post image to show what it should look like. Hope you can get some use of this indicator once it's working. Merry Christmas to you.
Last edited by Lobo; 12-18-2009 at 03:01 PM.
Lobo is offline  
Reply With Quote
Old 12-18-2009, 03:21 PM   #8
Lobo
Junior Member
 
Join Date: Oct 2006
Location: , ,
Posts: 11
Thanks: 0
Thanked 0 times in 0 posts
Default

Thought I'd include a bit of an explanation supplied by the creator, John McCormick.
I'll figure how to upload images tomorrow and you'll see the large difference it makes.

I use a routine I call, "gapless," which avoids these problems by treating separate days in a manner similar to continuous contracts.
This is how it works: The opening “gap” is recorded for the first bar of each trading day.

A relative stream of OHLC's are calculated by subtracting this “gap” from the actual prices. This relative stream of OHLC’s are maintained right along side of the real OHLC’s. If the EL programmer needs to convert between the relative prices and the real price data, the sum of all the gap values is stored in the variable, “accum,” which makes the conversion simple.

If you’re squeamish about eliminating the opening gap altogether, I’ve included a “GapCoef,” that you can set between 0.00 and 1.00 to reduce part or all of the gap as you choose. For example, set the coefficient to 0.5 to reduce the gap by half. I prefer to eliminate the gap altogether so I set the coefficient to 1.0, which eliminates 100% of the opening gap.

Indicators, such as RSI and Stochastics, (see below examples) work fine with this relative price stream and never need to be converted back to real prices.

If you have an indicator that needs to be displayed on the same scale as the underlying data, simply add “accum,” i.e. (indicator + accum) as the last step prior to plotting. You can see an example of this with the Bollinger Band below (code included below in Gapless.ELD).

In order to work correctly, all manipulations (adding, averaging, etc...) should only be done with the relative data (RelO, RelH, RelL and RelC), then if the data needs to be returned to the real domain the variable "accum" is added as the last step.

// gapless day transitions - John McCormick May 2008

Vars:
RelO(0), // Relative Open
RelH(0), // Relative High
RelL(0), // Relative low
RelC(0), // Relative Close
gap(0), // the opening gap (modified by the gap coefficient)
GapCoef(1.0), // Gap Coefficient
Accum(0); // The sum of all the daily gaps

if date<>date[1] then
begin
gap = GapCoef*(O-C[1]);
Accum = Accum+gap;
end;

RelO = O-Accum;
RelC = C-Accum;
RelH = H-Accum;
RelL = L-Accum;

// Gapless - end
Lobo 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
convert tradestation to ninjatrader - 3 lines of code fudge Indicator Development 11 06-02-2010 06:40 PM
Convert Metastock Code cmach123 General Programming 2 07-30-2009 03:42 AM
how to program Farley's accumulation distribution accelerator? (see EL code) suedeuno Indicator Development 3 01-12-2009 02:17 PM
pullback code in Ninjascript newtonslab Indicator Development 10 10-09-2008 07:41 AM
Convert TradeStation code to Ninja Razor_Trader General Programming 2 07-25-2008 12:45 AM


All times are GMT -6. The time now is 04:00 AM.