Multiple time frame strategy sharing a variable - NinjaTrader Programming | futures io social day trading
futures io futures trading


Multiple time frame strategy sharing a variable
Updated: Views / Replies:1,851 / 7
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
 

Multiple time frame strategy sharing a variable

  #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

Multiple time frame strategy sharing a variable

Please take a look at the code below. I'm working on a multitime frame strategy that tests for some conditions on three different time frames 2/10/60 and then updates a "Score" variable based on the findings.
Rather than update the score and print just one updated number, the output is showing three different scores one for each time frame. When added together they are correct but why are they printing to the output window separately?

I want one updated score that updates at each tick on all time frames at once.

code below
-------------------------------------------------------------------------------------------------------------------
 
Code
                            
namespace NinjaTrader.Strategy
{
/// <summary>
/// for testing strategy componants
/// </summary>
[Description("for testing strategy componants")]
public class 
TESTSTRATEGY2 Strategy
{
#region Variables

//These are the amounts to add or subtract to score
int HourlyScore 1int TenMinScore 2int TwoMinScore 6;

#endregion


protected override void Initialize()
{
CalculateOnBarClose false;

Add(PeriodType.Minute10);     //adding 10 minute data
Add(PeriodType.Minute60);     //adding 60 minute data
}


protected 
override void OnBarUpdate()
{
ClearOutputWindow();

if (
CurrentBars[0] <= BarsRequired || 
CurrentBars[1] <= BarsRequired || 
CurrentBars[2] <= BarsRequired)
return;

//reset score on each bar update
int Score 0;    

//------------------------------------------------------------------------------------    
//for each BarsInProgress
for(int x 0<= 2x++)
{
if(
BarsInProgress == x)
{
bool MaUp;     //define moving average up variable
string LongOrShort;    //define Long or short string

// determines if 8ema is above the 15sma
if (EMA(8)[0] > SMA(25)[0])
{
MaUp true;
}
else 
MaUp false;


if(
MaUp)
{
LongOrShort "SHORT";    //set short bias

switch(x)    //score for each time frame
{
case 
2:
Score Score HourlyScore;
break;
case 
1:
Score Score TenMinScore;
break;
case 
0:
Score Score TwoMinScore;
break;
}

}
else    
if(
MaUp == false)
{
LongOrShort "LONG";    //set long bias

switch(x)    //score for each time frame
{
case 
2:
Score Score HourlyScore;
break;
case 
1:
Score Score TenMinScore;
break;
case 
0:
Score Score TwoMinScore;
break;
}
}    
else 

LongOrShort "NOTRADE"//set no trade bias
}
}    
Print(
ToTime(Time[0]));     //print time of score
Print("Score is " Score);    //print score
}

#region Properties
#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
Multiple time frame strategy sharing a variable-output.jpg  

Last edited by sam028; February 7th, 2012 at 07:42 PM. Reason: add [php] ... [/php] tag
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)
Elite Member
Bala, PA, USA
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: Mirus, IB
Favorite Futures: SPY, Oil, Euro
 
monpere's Avatar
 
Posts: 1,858 since Jul 2010
Thanks: 300 given, 3,276 received


If I understand correctly, try printing only in one timeframe, i.e the lowest timeframe, if BarsInProgress == 0 for instance.


Last edited by monpere; February 7th, 2012 at 06:53 PM.
Reply With Quote
The following 2 users say Thank You to monpere 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!

It looks like I'm going to have to forgo the for loop in favor of using BarsArray references within the primary series. I was hoping to have to avoid this as it means a lot more duplicate code. Thx for the suggestion.

"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
 
  #5 (permalink)
Trading for Fun
Little Rock, Arkansas
 
Futures Experience: None
Platform: MarketDelta
Favorite Futures: Options
 
r3algood's Avatar
 
Posts: 198 since Jul 2011
Thanks: 106 given, 105 received

Did you initialize your two minute data?

In the Initialize section I see you added the 10 and 60 but not the 2?

Maybe that has something to do with it?

Very beginner level programmer here so take my words with a grain of salt!

Reply With Quote
The following user says Thank You to r3algood for this post:
 
  #6 (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


r3algood View Post
Did you initialize your two minute data?

In the Initialize section I see you added the 10 and 60 but not the 2?

Maybe that has something to do with it?

Very beginner level programmer here so take my words with a grain of salt!

Yes, I read through the info on syncing dataseries and was successfully able to sync all the series. 2/10/60 and the daily which I added as well. So far the code looks decent although not nearly as elegant as I had originally wanted. I had originally hoped to find a way to do this while looping through the BarsInProgress using a for loop but it doesn't allow me to do what I want it to do. I'll have to duplicate a lot of code unfortunately but at least it works.

"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
 
  #7 (permalink)
 Vendor: www.sharkindicators.com 
Calgary, AB
 
Futures Experience: Intermediate
Platform: NinjaTrader
Favorite Futures: futures, forex
 
Posts: 11 since Aug 2010
Thanks: 1 given, 39 received

Hi Shrugged,

Are you trying to test

EMA(8)[0] > SMA(25)[0] using the 60 min timeframe based indicators, 10 min based indicators and 2 min based indicators for each tick?

If so, then what you're looking for on each bar update is basically this:
 
Code
if (EMA(BarsArray[0], 8) > SMA(BarsArray[0], 25)) // 2 min timeframe
{
 Score += TwoMinScore;
}

if (EMA(BarsArray[1],8) > SMA(BarsArray[1],25)) // 10 min timeframe
{
Score += TenMinScore;
}

if (EMA(BarsArray[2],8) > SMA(BarsArray[2],25)) // 60 min timeframe
{
Score += HourlyScore;
}

Jeremy

Reply With Quote
The following 2 users say Thank You to jeremytang for this post:
 
  #8 (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

sorry to reply so late...thanx JeremyT for the code. I like the easier way you incremented the variables. I'm using that now thanks to you.

Score += TwoMinScore;

is much better than Score = Score + SomethingElse;

thx!

"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

Reply



futures io > > > > > Multiple time frame strategy sharing a variable

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
help code multiple Time Frame indicator ttmarok ThinkOrSwim Programming 25 March 3rd, 2014 09:42 PM
Multiple Time Frame Bollinger Bands Saroj The Elite Circle 3 April 28th, 2013 03:34 PM
Multiple Time Frame Equidistant Bars DavidHP NinjaTrader Programming 21 April 25th, 2012 04:25 AM
Multiple Time Frame Moving Average Indicator Aragorn NinjaTrader 6 November 8th, 2011 11:59 PM


All times are GMT -4. The time now is 05:44 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-17 in 0.14 seconds with 21 queries on phoenix via your IP 54.82.81.154