highest bar close occuring within the last X number of bars . . . . - NinjaTrader Programming | futures io social day trading
futures io futures trading


highest bar close occuring within the last X number of bars . . . .
Updated: Views / Replies:11,768 / 37
Created: by jmejedi Attachments:5

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
 5  
 
Thread Tools Search this Thread
 

highest bar close occuring within the last X number of bars . . . .

  #31 (permalink)
Urban Samurai
Chicago IL
 
Futures Experience: Intermediate
Platform: Ninja, MT4,TOS, SC, Matlab
Broker/Data: CQG, AMP, MB, DTN
Favorite Futures: E/U, G/U
 
forrestang's Avatar
 
Posts: 1,039 since Jun 2010
Thanks: 226 given, 688 received


Loukas View Post
I am running this in strategy analyzer, I think your are speaking about Order Properies which has 3 options 1. By default quantity 2. by strategy 3. by account size. I selected By Default quantity and then at the default quuantity box I entered 2 but it doesnt execute more trades.

No not that one.

Go to THIS link, and look under the tab "Understanding Backtest Properties."

It should explain everything you need to understand the order handling. Pay attention to "order handling."

Reply With Quote
The following user says Thank You to forrestang for this post:
 
  #32 (permalink)
Trading Apprentice
London
 
Futures Experience: None
Platform: NinjaTrader
Favorite Futures: Currencies
 
Posts: 27 since Jun 2011
Thanks: 4 given, 2 received

Losses and Profit more than expected

Hi Forrestang,
I have an issue this Stop Loss and take Profit Target and I want your thoughts on it. I have applied stop loss(SL) and take profit(TP) with CalculationMode.Percent and at OnBarUpdate() a dynamic SL when I am in a trade. The problem is arizing when I am running back test. I believe the worst loss could be iccure should be the ST at CalculationMode.Percent because is lower. However, I had losses and profits much more than my orders. How is this possible? a part of my code is below.

if (Position.MarketPosition== MarketPosition.Long)
{
if( Close[0] < EMA (30)[0] )
{
ExitLong();
Print(Time[0]+"Exit Long Close below EMA");
}

else if (Close[0]>= Position.AvgPrice+BreakEvenTarget * TickSize)

{
NewStopTarget = Position.AvgPrice + SetNewTarget * TickSize;
SetStopLoss(CalculationMode.Price, Position.AvgPrice);
Print(Time[0]+" Exit Long due to BreakEven Ticks");
}
}

if (Position.MarketPosition== MarketPosition.Short)
{
if( Close[0] > EMA (30)[0] )
{
ExitShort();
Print(Time[0]+" Exit Short because of Close cross above EMA");
}

else if (Close[0]<= Position.AvgPrice-BreakEvenTarget * TickSize)

{
NewStopTarget = Position.AvgPrice- SetNewTarget * TickSize;
SetStopLoss(CalculationMode.Price, NewStopTarget);
Print(Time[0]+" Exit Short due to BreakEven Ticks");
}
}

Reply With Quote
 
  #33 (permalink)
Urban Samurai
Chicago IL
 
Futures Experience: Intermediate
Platform: Ninja, MT4,TOS, SC, Matlab
Broker/Data: CQG, AMP, MB, DTN
Favorite Futures: E/U, G/U
 
forrestang's Avatar
 
Posts: 1,039 since Jun 2010
Thanks: 226 given, 688 received


Not sure exactly what your error is based on your explanation. Here is a general structure of how you should program your strategy. This is just for a long. Please take note of all the comments in there.

Basically, you have some setup in the initialize block with setting your target and stop.

Next in your update block, you want to:
Check if flat, if so set your stoploss to your hard stop.

Next, I've added in the OPTION to use a Breakeven adjust stop, you see that there. If you don't need it, you can just delete that statement. Also done at this point while checking if we are long, you'll see there is an option there to EXIT immediately if some condition happens. For example if you wanted to put oscillator crossing below zero in there.

Lastly, we check if we are NOT flat, if we are IN a trade, then exit the loop and start over. But this is basically how you do it.

 
Code
        protected override void Initialize()
        {
            
		CalculateOnBarClose = true;
		EntryHandling       = EntryHandling.UniqueEntries;
		EntriesPerDirection = 1;
		ExitOnClose = true;
		ExitOnCloseSeconds = 30;
		TraceOrders = true;
		SetProfitTarget(CalculationMode.Ticks, profitTarget);	//Note replace with whatever variable you have[/COLOR]
		SetStopLoss(CalculationMode.Ticks, initialStop);		//Note replace with whatever variable you have
			
        }
		
	protected override void OnBarUpdate()
        {

		//Notice here we set the initial stop EACH time we execute the loop IF we are flat,
		//I.e. reinitializing at the very beginning of the OnBarUpdate
		if (Position.MarketPosition == MarketPosition.Flat)
		{
			SetStopLoss(CalculationMode.Ticks, initialStop);	//again replace with YOUR variable
		}
				
				
		//Now we check if we are long, if we are, then we want to initialize our stops
		if (Position.MarketPosition == MarketPosition.Long)
		{
			//Loukas, this first IF statement sets the stop loss to BE+2 tics if price moves
			//past a certain point of entry.  If you do not wish to havea BE adjustment, 
			//just delete it
			if (High[0] >= Position.AvgPrice + beMove*TickSize)	//beMove is the distance after entry before going to BE
				SetStopLoss( CalculationMode.Price, Position.AvgPrice + 2*TickSize); //Note we are changing the stoploss
					
			//This IF statement provides an emergency exit based on something. Say you have a condition
			//that you will want to exit a trade immediately if it occurs. Delete if you dont need
			if (Something happens ......)
				ExitLong("ExitLong1", "Long1");
		}
				
		//This IF statement says that if we are in a position, then exit the loop, b/c we don't need 
		//to execute the buy signal.
		if (Position.MarketPosition != MarketPosition.Flat) return;
				
		//Now, put your ENTRY SIGNAL @ the bottom of the OnBarUpdate.  This is the last thing you want to
		//do each time through.  Replace with your conditions for buy signal.
		if (Buy signal occurrs.....)
			EnterLong("Long1");
		
        }

Attached Thumbnails
highest bar close occuring within the last X number of bars . . . .-prime2011-09-23_231531.png  

Last edited by forrestang; September 24th, 2011 at 01:25 AM.
Reply With Quote
The following 2 users say Thank You to forrestang for this post:
 
  #34 (permalink)
Trading Apprentice
London
 
Futures Experience: None
Platform: NinjaTrader
Favorite Futures: Currencies
 
Posts: 27 since Jun 2011
Thanks: 4 given, 2 received

Many thanks forrestang, my losses have been reduced significanlty! I didnt know that it is so important to put at the beging of the of strategy the SL and TP orders. I will always following this structure. Once again thanks for your imput. I would like to ask you also why the following code execute the same number of trades if I have 3 or 5 condition ?

if ( EMA(5)[0]>EMA(40)[0]
// && EMA(90)[0]>EMA(100)[0]/// If I add those two conditions
// && RSI(14,3)[0]> 60////// the number of the executed trades stay the same.
&& Rising(ATR(Close,14))
&& Closes[1][0]>EMA(150)[0])/// Different time frame
{
EnterLong()
}

I had made the following changes and the code was working well but I cannot understand why I need to make this

if ( EMA(5)[0]>EMA(40)[0]
&& Rising(ATR(Close,14))
&& Closes[1][0]>EMA(150)[0])/// Different time frame
{
if ( EMA(90)[0]>EMA(100)[0]/
&& RSI(14,3)[0]> 60)
{
EnterLong()
}
}

Reply With Quote
 
  #35 (permalink)
Urban Samurai
Chicago IL
 
Futures Experience: Intermediate
Platform: Ninja, MT4,TOS, SC, Matlab
Broker/Data: CQG, AMP, MB, DTN
Favorite Futures: E/U, G/U
 
forrestang's Avatar
 
Posts: 1,039 since Jun 2010
Thanks: 226 given, 688 received

Well if you are adding more conditions and getting the same number of trades, it's either because you have some formatting issues, which kinda is what that first code block looks like?

Or you have some conditions that are too highly correlated.

So the check is easy, just run the strategy either in a sim or backtest, put the indicators you are using on a chart, and check and see if your system is plotting the proper trade based on whatever indicators you are using. If need be isolate each condition and check again.

Reply With Quote
 
  #36 (permalink)
Trading Apprentice
London
 
Futures Experience: None
Platform: NinjaTrader
Favorite Futures: Currencies
 
Posts: 27 since Jun 2011
Thanks: 4 given, 2 received

The code "if ( EMA(5)[0]>EMA(40)[0] && EMA(90)[0]>EMA(100)[0]) "execute the same number of trades as the code if ( EMA(5)[0]>EMA(40)[0]
&& EMA(90)[0]>EMA(100)[0]
&& RSI(14,3)[0]> 60
&& Rising(ATR(Close,14))
&& Closes[1][0]>EMA(BarsArray[1],10)[0])
{
EnterLong(DefaultQuantity);
Print(Time[0] +" Enter Long");
}
However, when I am adding an extra if statment is working well
if ( EMA(5)[0]>EMA(40)[0]
&& EMA(90)[0]>EMA(100)[0])
// && RSI(14,3)[0]> 60
// && Rising(ATR(Close,14))
// && Closes[1][0]>EMA(BarsArray[1],10)[0])
{
if ( RSI(14,3)[0]> 60
&& Rising(ATR(Close,14))
&& Closes[1][0]>EMA(BarsArray[1],10)[0])

Print(Time[0] + " Long Momentum");

{
EnterLong(DefaultQuantity);
Print(Time[0] +" Enter Long");
}
}
Why the first code stracture is not working as the second one?

Reply With Quote
 
  #37 (permalink)
Urban Samurai
Chicago IL
 
Futures Experience: Intermediate
Platform: Ninja, MT4,TOS, SC, Matlab
Broker/Data: CQG, AMP, MB, DTN
Favorite Futures: E/U, G/U
 
forrestang's Avatar
 
Posts: 1,039 since Jun 2010
Thanks: 226 given, 688 received

I cant tell what goes with what. Use the 'code' tags or take a screenshot of your editor or something.

Reply With Quote
The following user says Thank You to forrestang for this post:
 
  #38 (permalink)
Elite Member
Orlando, Florida USA
 
Futures Experience: Master
Platform: Think or Swim [How utterly appropriate]
Favorite Futures: es, eur/usd
 
Posts: 18 since May 2012
Thanks: 4 given, 10 received

You really soldiered thru that reply!

I just wanted to say thank you on behalf of most of us traders who glean the little nuggets of gold dust
from folks like you who assist those traders in need. You did a STELLAR job assisting this guy and folks
like us, iitting on the cloud want to send you a big ray of sunshine!

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

Reply



futures io > > > > > highest bar close occuring within the last X number of bars . . . .

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
number of ticks in a bar/ms timestamp ? sam028 NinjaTrader Programming 15 September 21st, 2012 08:50 AM
How to program price cross below a number of previous bars Twiddle NinjaTrader Programming 8 May 17th, 2011 05:58 PM
how to count in nt7 the number of bars that have closed? anniebee321 NinjaTrader 9 April 26th, 2011 12:27 PM
How do I access the bar number under the cursor? koganam NinjaTrader Programming 3 September 6th, 2010 10:25 AM
Close[0] not waiting until bar close dsraider NinjaTrader Programming 4 February 11th, 2010 06:49 PM


All times are GMT -4. The time now is 07:42 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-11 in 0.21 seconds with 20 queries on phoenix via your IP 54.226.132.197