Seeking coding solution – NinjaTrader - NinjaTrader | futures io social day trading
futures io futures trading


Seeking coding solution – NinjaTrader
Updated: Views / Replies:703 / 3
Created: by Abde Attachments:1

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors – all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you don’t need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 
Thread Tools Search this Thread
 

Seeking coding solution – NinjaTrader

  #1 (permalink)
Elite Member
Germany
 
Futures Experience: Intermediate
Platform: FlatTrader
Broker/Data: GFT and Interactive Brokers
Favorite Futures: ES, DAX
 
Posts: 531 since Aug 2010
Thanks: 2,121 given, 719 received

Seeking coding solution – NinjaTrader

Hello Coders,

I made an indicator that colors bars with a smaller open to close range than the previous 3 bars. I used this code:

 
Code
if( Close[0] > Open[0] && Math.Abs(Close[0] - Open[0]) < Math.Abs(Close[1] - Open[1]) && Math.Abs(Close[0] - Open[0]) < Math.Abs(Close[2] - Open[2]) && Math.Abs(Close[0] - Open[0]) < Math.Abs(Close[3] – Open[3]))

else if( Close[0] <= Open[0] && Math.Abs(Close[0] - Open[0]) <= Math.Abs(Close[1] - Open[1]) && Math.Abs(Close[0] - Open[0]) <= Math.Abs(Close[2] - Open[2]) && Math.Abs(Close[0] - Open[0]) <= Math.Abs(Close[3] – Open[3]))
I like now to improve that indicator by adding a selectable look back period and made these changes:

 
Code
#region Variables:
private int		barsback	=	3;

OnBarUpdate():
if (CurrentBar < barsback+1)	
{ return; }

for (int j=1; j<=barsback; j++)

if( Close[0] > Open[0] && Math.Abs(Close[0] - Open[0]) <= Math.Abs(Close[j] – Open[j]))

else if( Close[0] <= Open[0] && Math.Abs(Close[0] - Open[0]) <= Math.Abs(Close[j] – Open[j]))
Unfortunately that didn΄t work and it colors every bar, with a smaller open to close range than the entire selected look back period
(see attached chart). What I΄m doing wrong here?

Many thanks in advance for every tip.

Attached Thumbnails
-iw-stoppingcandlesperiodx.jpg  

Last edited by Abde; December 22nd, 2014 at 08:03 AM.
Reply With Quote
 
  #2 (permalink)
Elite Member
Berlin, Europe
 
Futures Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker/Data: Interactive Brokers
Favorite Futures: Keyboard
 
Fat Tails's Avatar
 
Posts: 9,653 since Mar 2010
Thanks: 4,226 given, 25,601 received
Forum Reputation: Legendary

It colors every bar because the code does not keep in mind the prior result. Basically your condition would be false, if there is a single bar within the lookback period "barsback" that has a smaller body then the current bar. A workaround would be to use a boolean variable "narrowBody", set that variable to true, and then loop through the prior bars. In case that you find a single bar that has a smaller body than the current bar you may set the boolean to false and exit the loop:

 
Code
bool narrowBodyBar = true;
double bodyRange = Math.Abs(Close[0] - Open[0]);
for int j = 1; j <= barsBack; j++)
   if(Math.Abs(Close[j]-Open[j]) < bodyRange)
   {
         narrowBodyBar=false;
         break;  //to exit loop, as the condition narrowBodyBar cannot come true anymore
   }


The baisc logic of the indicator - detecting a narrow range - requires that it runs in mode "CalculateOnBarClose = true". If you wish to run it in "CalculateOnBarClose = false" to get a preliminary result, then the code above would be highly inefficient, as you would need to run through the entire loop with every incoming tick. Therefore to make the indicator efficient for use with "CalculateOnBarClose = false" you would need to modify the code, for example:

 
Code
#region  Variables
double minBody = 0.0;
bool narrowBodyBar = false;
#endregion

// within OnBarUpdate
if(FirstTickOfBar) // executed once per bar
{
    minBody = Math.Abs(Close[1] - Open[1])
    for (int j = 2; j <= barsBack; j++)
        if(Math.Abs(Close[j] - Open[j]) < minBody)
             minBody = Math.Abs(Close[j] - Open[j]);
}
if (Math.Abs(Close[0] - Open[0]) <= minBody) // executed with every incoming tick
   narrowBodyBar = true;

Not tested.

Reply With Quote
The following 3 users say Thank You to Fat Tails for this post:
 
  #3 (permalink)
Elite Member
Germany
 
Futures Experience: Intermediate
Platform: FlatTrader
Broker/Data: GFT and Interactive Brokers
Favorite Futures: ES, DAX
 
Posts: 531 since Aug 2010
Thanks: 2,121 given, 719 received



Fat Tails View Post
It colors every bar because the code does not keep in mind the prior result. Basically your condition would be false, if there is a single bar within the lookback period "barsback" that has a smaller body then the current bar. A workaround would be to use a boolean variable "narrowBody", set that variable to true, and then loop through the prior bars. In case that you find a single bar that has a smaller body than the current bar you may set the boolean to false and exit the loop:

 
Code
bool narrowBodyBar = true;
double bodyRange = Math.Abs(Close[0] - Open[0]);
for int j = 1; j <= barsBack; j++)
   if(Math.Abs(Close[j]-Open[j]) < bodyRange)
   {
         narrowBodyBar=false;
         break;  //to exit loop, as the condition narrowBodyBar cannot come true anymore
   }


The baisc logic of the indicator - detecting a narrow range - requires that it runs in mode "CalculateOnBarClose = true". If you wish to run it in "CalculateOnBarClose = false" to get a preliminary result, then the code above would be highly inefficient, as you would need to run through the entire loop with every incoming tick. Therefore to make the indicator efficient for use with "CalculateOnBarClose = false" you would need to modify the code, for example:

 
Code
#region  Variables
double minBody = 0.0;
bool narrowBodyBar = false;
#endregion

// within OnBarUpdate
if(FirstTickOfBar) // executed once per bar
{
    minBody = Math.Abs(Close[1] - Open[1])
    for (int j = 2; j <= barsBack; j++)
        if(Math.Abs(Close[j] - Open[j]) < minBody)
             minBody = Math.Abs(Close[j] - Open[j]);
}
if (Math.Abs(Close[0] - Open[0]) <= minBody) // executed with every incoming tick
   narrowBodyBar = true;

Not tested.

@Fat Tails

Many Thanks for your help Harry!

It makes no sense to run this indicator in mode "CalculateOnBarClose = false. I will try therefore your first code.
Does the complete code goes to the "OnBarUpdate()" section?

Reply With Quote
 
  #4 (permalink)
Elite Member
Berlin, Europe
 
Futures Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker/Data: Interactive Brokers
Favorite Futures: Keyboard
 
Fat Tails's Avatar
 
Posts: 9,653 since Mar 2010
Thanks: 4,226 given, 25,601 received
Forum Reputation: Legendary

Answer
This post has been selected as an answer to the original posters question Answer


Abde View Post
@Fat Tails

Many Thanks for your help Harry!

It makes no sense to run this indicator in mode "CalculateOnBarClose = false. I will try therefore your first code.
Does the complete code goes to the "OnBarUpdate()" section?

The first example should be included with OnBarUpdate().

Reply With Quote
The following user says Thank You to Fat Tails for this post:

Reply



futures io > > > > Seeking coding solution – NinjaTrader

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Coding question - NinjaTrader Abde NinjaTrader 5 December 5th, 2014 03:57 AM
NinjaTrader vs custom solution for backtesting and strategy optimization dominikos Elite Automated Trading 4 March 27th, 2014 07:10 PM
Stable Server solution - automated trading with NinjaTrader + Interactive Brokers Foerster NinjaTrader 2 August 9th, 2013 06:24 AM
Coding NinjaTrader with F# AstralTrader NinjaTrader Programming 5 October 22nd, 2012 03:00 PM
Seeking advice on NinjaTrader Simulator Settings Paladin NinjaTrader 1 March 2nd, 2011 09:31 AM


All times are GMT -4. The time now is 06:11 AM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts
Page generated 2017-12-14 in 0.11 seconds with 28 queries on phoenix via your IP 54.160.245.121