Why is my code using historical data? - NinjaTrader Programming | futures io social day trading
futures io futures trading


Why is my code using historical data?
Updated: Views / Replies:948 / 4
Created: by ShruggedAtlas 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
 

Why is my code using historical data?

  #1 (permalink)
Atlas
Bloomington
 
Futures Experience: Beginner
Platform: NinjaTrader
Broker/Data: Interactive Brokers
Favorite Futures: Stocks
 
ShruggedAtlas's Avatar
 
Posts: 191 since Apr 2011
Thanks: 78 given, 74 received

Why is my code using historical data?

If anyone cares to take the time to look over my code and help me figure out why it is using an accumulation of historical data to make the 'final calculations' rather than recalculating everything tick by tick.

this code is fairly straightforward, it detects a few conditions for each time frame and then is supposed to evaluate market direction and price extreme and then keep track of a score. the score is supposed to represent the "likelyhood" of a change of direction. for example: if everything is bullish and price is at the extremes of the regression channel then the likelihood of success for a short position is higher ie. higher score. The scoring system assigns the following to each time frame:

1 for daily, 2 for hourly, 6 for ten minute and 18 for two minute. Therefore, if price is bullish and reaching upper extremes on all 4 time frames then the maximum score for short (ShortScore) is 27 for at any point in time. My output is showing numbers like 414 which means it's factoring previous ticks on all time frames. I just want one score number and it can never go above 27 for ShortScore and never below -27 for LongScore.

Here is the code:

public class MyCustomStrategy : Strategy
{
#region Variables
// Wizard generated variables
private int myInput0 = 1; // Default setting for MyInput0
// User defined variables (add any user defined variables below)
#endregion
int LongScore = 0; //keeps track of probablilities for Long success
int ShortScore = 0; //keeps track of probablilities for Short success



protected override void Initialize()
{
CalculateOnBarClose = false; //score must be calculated at each tick
Add(PeriodType.Minute, 10); //adding 10 minute data
Add(PeriodType.Minute, 60); //adding 60 minute data
Add(PeriodType.Day, 1); //adding daily data
}



protected override void OnBarUpdate()
{
if (CurrentBars[0] <= BarsRequired ||
CurrentBars[1] <= BarsRequired ||
CurrentBars[2] <= BarsRequired ||
CurrentBars[3] <= BarsRequired)
return;

int DailyScore = 1; int HourlyScore = 2; //score to be added for each time frame
int TenMinScore = 6; int TwoMinScore = 18; //score to be added for each time frame

for (int x = 0; x <= 3; x++)
{
if (BarsInProgress == x) //for each time frame
{
//local variables used to track indicator states
bool MaUp; //tracks if EMA is above SMA - bullish sign
bool SmaRising; //tracks if SMA is rising
bool PriceAboveMedian; //tracks if price is above the median of regression channel
int PriceToRcUp = 0; //tracks how far price is above upper regression channel
int PriceToRcDown = 0; //tracks how far price is above the lower regression channel
string LongOrShort; //used to track if the entry should be long or short
double[] ChannelSD = new double[] {2, 2.5, 3, 3.5};
//regression channels standard deviations

// check to see if price is above the median of channel - bullish
if (Close[0] > RegressionChannel(150, 2)[0])
{
PriceAboveMedian = true;
}
else PriceAboveMedian = false;

//check to see if longer term trendline is rising - bullish
if (Rising(SMA(25)))
{
SmaRising = true;
}
else SmaRising = false;

//check to see if EMA is above SMA - bullish
if (EMA(8)[0] > SMA(25)[0])
{
MaUp = true;
}
else MaUp = false;

/// for each standard deviation on the regression channels
/// add a number to PriceToRc so we can track where price is
/// relative to the regresion channel extrememes
foreach (double i in ChannelSD)
if(Close[0] > RegressionChannel(150, i).Upper[0])
{
PriceToRcUp = PriceToRcUp + 1;
}

foreach (double i in ChannelSD)
if(Close[0] < RegressionChannel(150, i).Lower[0])
{
PriceToRcDown = PriceToRcDown + 1;
}

//evaluate which direction trade should go - long or short?
if(PriceAboveMedian && SmaRising && MaUp && PriceToRcUp > 0)
{
LongOrShort = "SHORT"; //this line not needed - used for debugging
switch(x)
{
case 0:
LongScore = LongScore + DailyScore;
ShortScore = ShortScore - DailyScore;
break;
case 1:
LongScore = LongScore + HourlyScore;
ShortScore = ShortScore - HourlyScore;
break;
case 2:
LongScore = LongScore + TenMinScore;
ShortScore = ShortScore - TenMinScore;
break;
case 3:
LongScore = LongScore + TwoMinScore;
ShortScore = ShortScore - TwoMinScore;
break;
}
}
else
if(PriceAboveMedian == false && SmaRising == false && PriceToRcDown > 0)
{
LongOrShort = "LONG"; //this line not needed - used for debugging
switch (x)
{
case 0:
LongScore = LongScore - DailyScore;
ShortScore = ShortScore + DailyScore;
break;
case 1:
LongScore = LongScore - HourlyScore;
ShortScore = ShortScore + HourlyScore;
break;
case 2:
LongScore = LongScore - TenMinScore;
ShortScore = ShortScore + TenMinScore;
break;
case 3:
LongScore = LongScore - TwoMinScore;
ShortScore = ShortScore + TwoMinScore;
break;
}
}
else
LongOrShort = "NOTRADE"; //this line not needed - used for debugging
}
}
Print("LongScore is " + LongScore);
Print("ShortScore is " + ShortScore);
}

#region Properties
[Description("")]
[GridCategory("Parameters")]
public int MyInput0
{
get { return myInput0; }
set { myInput0 = Math.Max(1, value); }
}
#endregion
}
}

"I've missed more than 9,000 shots in my career. I've lost almost 300 games. 26 times, I've been trusted to take the game-winning shot and missed. I've failed over and over and over again in my life. And that is why I succeed."
- Michael Jordan, 5-Time NBA Most Valuable Player, 6-Time NBA Champion
Attached Thumbnails
Why is my code using historical data?-output.jpg  
Reply With Quote
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
 Vendor: www.traderwerks.com 
Taipei Taiwan
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: Optimus
Favorite Futures: TW
 
Posts: 693 since Jun 2009
Thanks: 440 given, 440 received


Move longScore and shortScore into onbarupdate or reset them to zero there.

Math. A gateway drug to reality.
Reply With Quote
The following 3 users say Thank You to traderwerks for this post:
 
  #4 (permalink)
Atlas
Bloomington
 
Futures Experience: Beginner
Platform: NinjaTrader
Broker/Data: Interactive Brokers
Favorite Futures: Stocks
 
ShruggedAtlas's Avatar
 
Posts: 191 since Apr 2011
Thanks: 78 given, 74 received

Thx traderwerks!

I see my mistake. I was thinking that those variables needed to be outside the scope of the BarsInProgress but now I see that it needs to be reset after each bar update. Thx. The fix worked.

This is my first substantial programming project so your help was very much appreciated!

"I've missed more than 9,000 shots in my career. I've lost almost 300 games. 26 times, I've been trusted to take the game-winning shot and missed. I've failed over and over and over again in my life. And that is why I succeed."
- Michael Jordan, 5-Time NBA Most Valuable Player, 6-Time NBA Champion
Reply With Quote
The following user says Thank You to ShruggedAtlas for this post:
 
  #5 (permalink)
Elite Member
Atkinson, NH USA
 
Futures Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker/Data: NinjaTrader Brokerage
Favorite Futures: Futures, CL, ES, ZB
 
NJAMC's Avatar
 
Posts: 1,925 since Dec 2010
Thanks: 2,962 given, 2,294 received


ShruggedAtlas View Post
Thx traderwerks!

I see my mistake. I was thinking that those variables needed to be outside the scope of the BarsInProgress but now I see that it needs to be reset after each bar update. Thx. The fix worked.

This is my first substantial programming project so your help was very much appreciated!

Hi,

I don't know if this will help you in the future but there is a flag that NT sets when it is running Historical Data:
Historical

This can be used to filter bars in the OnBarUpdate() function.

Nil per os
-NJAMC [Generic Programmer]

LOM WIKI: NT-Local-Order-Manager-LOM-Guide
Artificial Bee Colony Optimization
Reply With Quote
The following user says Thank You to NJAMC for this post:

Reply



futures io > > > > > Why is my code using historical data?

Thread Tools Search this Thread
Search this Thread:

Advanced Search



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

Linda Bradford Raschke: Reading The Tape

Elite only

Adam Grimes: TBA

Elite only

NinjaTrader: TBA

January

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Historical CL Tick Data and Minute Data Big Mike The Elite Circle 112 July 26th, 2014 07:07 PM
Historical data into Multicharts TexasTrader MultiCharts 13 January 15th, 2014 02:17 PM
historical data Khedr Reviews of Brokers and Data Feeds 4 December 22nd, 2011 04:22 AM
historical tick data rowdy Reviews of Brokers and Data Feeds 6 August 17th, 2011 05:41 PM
Reload Historical Data Dragon Reviews of Brokers and Data Feeds 1 February 12th, 2010 10:03 AM


All times are GMT -4. The time now is 03:17 PM.

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-11 in 0.11 seconds with 20 queries on phoenix via your IP 54.226.172.30