Multiple trades in Same Bar - AmiBroker | futures io social day trading
futures io futures trading


Multiple trades in Same Bar
Updated: Views / Replies:1,003 / 6
Created: by raghavan 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
 
Thread Tools Search this Thread
 

Multiple trades in Same Bar

  #1 (permalink)
Trading Apprentice
Bangalore + India
 
Futures Experience: Beginner
Platform: NinjaTrader, MetaTrader
Favorite Futures: Futures
 
Posts: 13 since Jan 2015
Thanks: 3 given, 2 received

Multiple trades in Same Bar

I am trying to enter into multiple trades at same bar. In the attached image, I first Long at first bar and then first short in 5th bar and immediately Long in 5th bar. When I backtest, for the 5th bar, I just see Long trade entry and there is no entry for short trade that I've made in 5th bar. May I know why is this and how to get the entry of both short and Long trade details for the same bar in backtest result.

I tried using SetOption("AllowSameBarExit", True ); and SetOption("HoldMinBars", 1); but in vain.

Attached Thumbnails
Multiple trades in Same Bar-multipletradesinabar.png  
Reply With Quote
 
  #2 (permalink)
Membership Temporarily Revoked
Zurich/Switzerland
 
Futures Experience: Advanced
Platform: -
Favorite Futures: -
 
Posts: 79 since Oct 2014
Thanks: 0 given, 33 received

In backtest settings 'General' tab choose 'Long and short' at the 'Positions' setting.

Reply With Quote
 
  #3 (permalink)
Trading Apprentice
Bangalore + India
 
Futures Experience: Beginner
Platform: NinjaTrader, MetaTrader
Favorite Futures: Futures
 
Posts: 13 since Jan 2015
Thanks: 3 given, 2 received


I've selected both Long and Short in Settings. I've attached two new images with Time mentioned.

At 09:59, I expect backtest to show me both short and Long trades entry. In the attached snippet(sorted by Date), at 09:59, it just shows Long trade and not the short trade. May I know why is that

Attached Thumbnails
Multiple trades in Same Bar-multipletradesinabar.png   Multiple trades in Same Bar-multipletradesinabar2.png  
Reply With Quote
 
  #4 (permalink)
Membership Temporarily Revoked
Zurich/Switzerland
 
Futures Experience: Advanced
Platform: -
Favorite Futures: -
 
Posts: 79 since Oct 2014
Thanks: 0 given, 33 received

It's some mistake on your end. Upload a project file or send it to the AmiBroker guys. They have a support channel for a reason.

Reply With Quote
 
  #5 (permalink)
Trading Apprentice
Bangalore + India
 
Futures Experience: Beginner
Platform: NinjaTrader, MetaTrader
Favorite Futures: Futures
 
Posts: 13 since Jan 2015
Thanks: 3 given, 2 received

Here's the code I am using

 
Code
_SECTION_BEGIN("Test");

SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 

Buy = Cross(MA(C, 5), MA(C, 20));
Short = Cross(MA(C, 20), MA(C, 5)) OR C<O;

Sell = short;
cover = buy;
PlotShapes(shapeUpArrow*Buy, colorBlue, 0, low);
PlotShapes(shapeDownArrow*Short, colorPink, 0, high);


dist = -12;
fnt = "Arial";
fntsize = 8;
txtdist = 25 - dist;
bi = Barindex();
fvb = FirstVisiblevalue( bi );
lvb = LastVisiblevalue( bi );
for( i = fvb; i <= lvb; i++ ) { // iterate through visible chart area only
        if( Buy[i] ) 
            PlotTextSetFont( StrFormat( "B@\n%g", BuyPrice[ i ] ), fnt, fntsize, i, L[ i ], colorBlue, colorDefault, -txtdist + fntsize );
       	if( Short[i] )
            PlotTextSetFont( StrFormat( "Sh@\n%g", ShortPrice[ i ] ), fnt, fntsize, i, H[ i ], colorYellow, colorDefault, txtdist);
}
_SECTION_END();

At 3:25:59, a short trade and Buy trade is placed. But, when i Backtest, the backtest result just shows the buy trade that I have placed. In addition, I have short trades at 3:18 PM and 3:24 PM and other times. Even they are not part of backtest results.

The last short trade as per backtest result is at 2:40:59 PM. After that, though I've many short trade entries, they are not shown in backtest. The next result after 2:40:59 PM is at 3:25:59 PM and that is where I enter into Buy trade again(which could be result of cover = Buy). Does it mean that Backtest doesnt show any short trades that i've made after 2:40:59 PM until the short trade I placed at 2:40:59 PM is covered back at 3:25:59 PM. Can't I enter into new short trade when I already have other short trade in open.? Please help clarifying this

Attached Thumbnails
Multiple trades in Same Bar-multipletradesinabar3.png   Multiple trades in Same Bar-multipletradesinabar4.png  
Reply With Quote
 
  #6 (permalink)
Membership Temporarily Revoked
Zurich/Switzerland
 
Futures Experience: Advanced
Platform: -
Favorite Futures: -
 
Posts: 79 since Oct 2014
Thanks: 0 given, 33 received

What about taking a look into the documention?
There for example you can see that there are six backtest modes available.
https://www.amibroker.com/guide/afl/setbacktestmode.html
Default one is backtestRegular.

As aside you should better use sections in your code by using status( "action" ) because otherwise you run redundant code in environments where it is not required to be run. This becomes more essential the longer/ the more resource hungry your entire code becomes.


Status action applied in your case:

 
Code
Buy = Cross(MA(C, 5), MA(C, 20));
Short = Cross(MA(C, 20), MA(C, 5)) OR C<O;

Sell = Short;
Cover = Buy;

if( Status( "action" ) == actionIndicator ) { // code for chart pane
	SetChartOptions(0,chartShowArrows|chartShowDates);
	_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
	
	Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 

	PlotShapes(shapeUpArrow*Buy, colorBlue, 0, low);
	PlotShapes(shapeDownArrow*Short, colorPink, 0, high);

	dist = -12;
	fnt = "Arial";
	fntsize = 8;
	txtdist = 25 - dist;
	bi = Barindex();
	fvb = FirstVisiblevalue( bi );
	lvb = LastVisiblevalue( bi );
	for( i = fvb; i <= lvb; i++ ) { // iterate through visible chart area only
			if( Buy[i] ) 
				PlotTextSetFont( StrFormat( "B@\n%g", BuyPrice[ i ] ), fnt, fntsize, i, L[ i ], colorBlue, colorDefault, -txtdist + fntsize );
			if( Short[i] )
				PlotTextSetFont( StrFormat( "Sh@\n%g", ShortPrice[ i ] ), fnt, fntsize, i, H[ i ], colorYellow, colorDefault, txtdist);
	}
}

Reply With Quote
 
  #7 (permalink)
Trading Apprentice
Bangalore + India
 
Futures Experience: Beginner
Platform: NinjaTrader, MetaTrader
Favorite Futures: Futures
 
Posts: 13 since Jan 2015
Thanks: 3 given, 2 received

Thanks for your input on the status action part.

I went through the setbacktestmode documentation and related doc amibroker.com/guide/h_portfolio.html.

Multiple positions in a bar would be hold back along with exit signals if I use backtestRegularRaw2Multi. I have a below set of code added now.

SetBacktestMode(backtestRegularRaw2Multi); // I also tried with backtestRegularRawMulti
SetOption("AllowSameBarExit", True );
Setoption("holdminbars", 1);

But, Still I dont see two position details for the same bar in Backtest result. I am expecting my backtesting results to show something as below

BANKNIFTY Short 6/12/2015 3:25:59 PM 17521.3
BANKNIFTY Long 6/12/2015 3:25:59 PM 17521.3

May I know what I'm still missing.

Reply With Quote

Reply



futures io > > > > Multiple trades in Same Bar

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
Showing multiple trade behavior in Trades tab Auric NinjaTrader 0 November 5th, 2013 10:58 PM
individual stop and target for multiple trades sunsun EasyLanguage Programming 2 May 7th, 2013 10:12 AM
> Break-Out Bar Trades - that go bad ... Trader8s Traders Hideout 4 November 23rd, 2012 10:34 PM
need help stopping multiple entries on the same bar cboss EasyLanguage Programming 2 October 2nd, 2011 12:04 AM
Daily maximum target for Multiple trades scartree NinjaTrader Programming 2 December 21st, 2010 08:37 AM


All times are GMT -4. The time now is 05:04 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-16 in 0.12 seconds with 20 queries on phoenix via your IP 54.163.210.170