NexusFi: Find Your Edge


Home Menu

 





Multiple time frame strategy sharing a variable


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one ShruggedAtlas with 4 posts (0 thanks)
    2. looks_two monpere with 1 posts (2 thanks)
    3. looks_3 tmp123 with 1 posts (0 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 3,650 views
    2. thumb_up 5 thanks given
    3. group 3 followers
    1. forum 7 posts
    2. attach_file 1 attachments




 
Search this Thread

Multiple time frame strategy sharing a variable

  #1 (permalink)
 
ShruggedAtlas's Avatar
 ShruggedAtlas 
Bloomington
 
Experience: Beginner
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: Stocks
Posts: 191 since Apr 2011
Thanks Given: 78
Thanks Received: 75

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 Images
 
Visit my NexusFi Trade Journal Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
PowerLanguage & EasyLanguage. How to get the platfor …
EasyLanguage Programming
How to apply profiles
Traders Hideout
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
REcommedations for programming help
Sierra Chart
MC PL editor upgrade
MultiCharts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
29 thanks
Just another trading journal: PA, Wyckoff & Trends
25 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
21 thanks
GFIs1 1 DAX trade per day journal
17 thanks
  #3 (permalink)
 
monpere's Avatar
 monpere 
Bala, PA, USA
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Mirus, IB
Trading: SPY, Oil, Euro
Posts: 1,854 since Jul 2010
Thanks Given: 300
Thanks Received: 3,371


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

Reply With Quote
Thanked by:
  #4 (permalink)
 
ShruggedAtlas's Avatar
 ShruggedAtlas 
Bloomington
 
Experience: Beginner
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: Stocks
Posts: 191 since Apr 2011
Thanks Given: 78
Thanks Received: 75

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
Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #5 (permalink)
r3algood
Little Rock, Arkansas
 
Posts: 198 since Jul 2011
Thanks Given: 106
Thanks Received: 109

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
Thanked by:
  #6 (permalink)
 
ShruggedAtlas's Avatar
 ShruggedAtlas 
Bloomington
 
Experience: Beginner
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: Stocks
Posts: 191 since Apr 2011
Thanks Given: 78
Thanks Received: 75


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
Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #7 (permalink)
 
jeremytang's Avatar
 jeremytang  SharkIndicators is an official Site Sponsor
Site Sponsor

Web: SharkIndicators
AMA: Ask Me Anything
Webinars: SharkIndicators Webinars
Elite offer: Click here
 
Posts: 16 since Aug 2010
Thanks Given: 4
Thanks Received: 53

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
Thanked by:
  #8 (permalink)
 
ShruggedAtlas's Avatar
 ShruggedAtlas 
Bloomington
 
Experience: Beginner
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: Stocks
Posts: 191 since Apr 2011
Thanks Given: 78
Thanks Received: 75

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
Visit my NexusFi Trade Journal Started this thread Reply With Quote




Last Updated on February 17, 2012


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts