buy next bar... and set stop immediately and not for the bar after - EasyLanguage Programming | futures io social day trading
futures io futures trading


buy next bar... and set stop immediately and not for the bar after
Updated: Views / Replies:7,976 / 12
Created: by Nicolas11 Attachments:7

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

buy next bar... and set stop immediately and not for the bar after

  #1 (permalink)
Elite Member
near Paris, France
 
Futures Experience: Beginner
Platform: -
Favorite Futures: -
 
Nicolas11's Avatar
 
Posts: 1,070 since Aug 2011
Thanks: 2,232 given, 1,729 received

buy next bar... and set stop immediately and not for the bar after

Hello,

I am facing the following difficulty with Easy Language in MultiCharts.

Typically, I have the following code which buys and sets a stop-loss (on EUR.GBP 5 min):

If MarketPosition = 0 AND condition1 then
Buy next bar at xxx stop;
If Market Position = 1 then
Sell ("stop loss") next bar at yyy stop;


This work fines except when the "buy" bar is a long bear candlestick and when the stop-loss level is reached within this "buy" bar. In such case, the stop is not triggered within the "buy" bar, since the stop-loss is only activated on the bar after the "buy" bar.

Such behaviour seems consistent with the code, but is more conservative than in real life (where the stop order could have been placed just after the buy, and the stop actually triggered in the same 5-minute window).

Do you confirm that there is no way to avoid this, or am I missing something?

( I think that Bar Magnifier does not help. With Bar Magnifier (1 min), MultiCharts could see that the stop-loss level would have been reached after the "buy", within the same "buy" 5 minutes bar. So he could trigger it... but the code just activates the stop loss for the next 5-minute bar. )

Thanks in advance for your help! :-)

Nicolas

Attached Thumbnails
buy next bar... and set stop immediately and not for the bar after-image1.jpg  

Last edited by Nicolas11; November 24th, 2011 at 02:40 PM.
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)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,238 since Jun 2009
Thanks: 29,350 given, 83,214 received


Bar Magnifier takes non-tick level bar types (minute, daily) and adds tick accuracy to them behind the scenes. But for tick level dataseries bar types like Range or Volume, you cannot use Bar Magnifier (pointless).

IntraBarOrderGeneration is what allows you to place and manage orders intrabar. By default it is off, you need to turn it on in the Format section of your strategy. When on, the strategy is evaluated on a tick-by-tick basis and when your conditions are met new orders are generated.

With regards to backtesting, MultiCharts by default assumes a worst case scenario. As you know, when testing using minute data (without bar magnifier), the order of the OHLC is not known. So in your scenario, it is not known if you bought before or after the low (and thus, your stop) was made. But MultiCharts assumes the worst case already. Be careful, as other platforms assume the best case.

But with IOG and Bar Magnifier, you can be assured backtest results are as accurate as possible.

Mike

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
The following 2 users say Thank You to Big Mike for this post:
 
  #4 (permalink)
Elite Member
near Paris, France
 
Futures Experience: Beginner
Platform: -
Favorite Futures: -
 
Nicolas11's Avatar
 
Posts: 1,070 since Aug 2011
Thanks: 2,232 given, 1,729 received

Thanks Mike and sorry for this late reply.

Let's suppose that I work with 5-minute bars.

I would like the calculation (value of condition1) to be done on the close of the bar only, and not during the bar.
However, I would like the stop order to be sent immediately after MarketPosition = 1 during the same 5-minute bar as the "buy", and not waiting for the next bar, in order that the stop could be trigerred (if necessary) during the same bar as the "buy".

I have the feeling that these requests are contradictory with respect to IBOG and/or Bar Magnifier.

Has some one an opinion on this subject?

Thanks in advance for any help!

Nicolas


Last edited by Nicolas11; November 24th, 2011 at 03:13 PM.
Reply With Quote
 
  #5 (permalink)
Elite Member
Warsaw, Poland
 
Futures Experience: Beginner
Platform: MultiCharts
Broker/Data: IB, IQFeed
Favorite Futures: TF
 
Posts: 5 since Aug 2011
Thanks: 13 given, 6 received

Hi,
You can try this:

setstopcontract;
setprofittarget(target$$$);
setstoploss(loss$$$);

Reply With Quote
The following 2 users say Thank You to kzaorski for this post:
 
  #6 (permalink)
 Vendor: tradingcode.net 
The Netherlands
 
Futures Experience: None
Platform: MultiCharts, TradingView
Favorite Futures: ...
 
Jura's Avatar
 
Posts: 774 since Apr 2010
Thanks: 2,347 given, 661 received


Nicolas11 View Post
I would like the calculation (value of condition1) to be done on the close of the bar only, and not during the bar.
However, I would like the stop order to be sent immediately after MarketPosition = 1 during the same 5-minute bar as the "buy", and not waiting for the next bar, in order that the stop could be trigerred (if necessary) during the same bar as the "buy".

I have the feeling that these requests are contradictory with respect to IBOG and/or Bar Magnifier.

Don't know if I follow you completely, but if you submit a buy order for the next bar (which gets executed on the first tick of that bar), and also submit a stop order for that bar, you'll get a stop submitted on the "right bar" and not the bar after entry? (There's no need for the Bar Magnifier for that as far as I know)

In other words, buy next bar and submit stop for next bar will not (in my opinion) give you the scenario pictured in your first post (buying on bar 1 and that the stop gets triggered on bar 2).

Btw, since you want to do the calculations on the last tick of the bar, per definition the buy/sell orders need to be submitted for the next bar, because if the last tick is evaluated by MultiCharts, you can't trade that bar any more (since it's the last tick). So, the buy and sell orders need to be submitted for the next bar, and if the stop orders are also submitted for the next bar, then the stop would get executed on the same bar that the trade was entered.

Perhaps a picture says its better:
Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


Code:
 
Code
[IntraBarOrderGeneration = TRUE]    

Variables: maFast(0), maSlow(0), longCondition(False), shortCondition(False), posSize(10000);

maFast = XAverage(Close, 5);
maSlow = XAverage(Close, 15);

longCondition     = maFast > maSlow;
shortCondition = maFast < maSlow;

// Only on close of bar
if BarStatus(1) = 2 then begin

    if longCondition = True then    
        Buy ("EL") posSize contracts next bar at market;

        
    if shortCondition = True then     
        SellShort ("SE") posSize  contract next bar at market;
        
end;

// Transmit stop orders
if MarketPosition(0) = 1 then
    Sell ("XL Stop") posSize contracts next bar at (Low - 0.0001) stop;
    
if MarketPosition(0) = -1 then
    BuyToCover ("XS stop") posSize contracts next bar at (High + 0.0001) stop;
Warning: the code above was written to generate a order for every bar. Don't apply it to a chart with a lot of bars, since the calculation will take up a lot of CPU and can make MultiCharts unresponsive.

Regards,
Jura

Reply With Quote
The following 2 users say Thank You to Jura for this post:
 
  #7 (permalink)
Elite Member
near Paris, France
 
Futures Experience: Beginner
Platform: -
Favorite Futures: -
 
Nicolas11's Avatar
 
Posts: 1,070 since Aug 2011
Thanks: 2,232 given, 1,729 received

Thanks @Jura and sorry for this late answer.

I have thought again about this issue...

My rephrased question is the following: After having entered "at market" (= at the open), is it possible to have a stop loss triggered on the same bar as the said entry?

My conclusion is: it depends on the way the stop loss is coded.

1. With a manual stop loss, answer is NO.

I take the example of a (stupid) signal which enters long at market after an inside bar, with a 5 ticks stop loss.

 
Code
Variables:
    TickSize    ( MinMove / PriceScale );
    
if MarketPosition = 0 and H < H[1] and L > L[1] {inside bar} then begin
    Buy ("Entry LONG") next bar at market;
end;

if MarketPosition = 1 then begin
    Sell ("Stop Loss LONG") next bar at EntryPrice - 5 * TickSize or lower;
    Sell ("Take Profit LONG") next bar at EntryPrice + 5 * TickSize or higher;
    if BarsSinceEntry >= 3 then sell ("Time Exit LONG") next bar at market;
end;
The stop loss begins to be considered only at the bar following the entry:
Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


2. With a built-in stop loss (SetStopLoss), answer is YES.

 
Code
Variables:
    TickSize    ( MinMove / PriceScale );
    
if MarketPosition = 0 and H < H[1] and L > L[1] {inside bar} then begin
    Buy ("Entry LONG") next bar at market;
    SetStopLoss(5 * TickSize * BigPointValue);
end;

if MarketPosition = 1 then begin
    Sell ("Take Profit LONG") next bar at EntryPrice + 5 * TickSize or higher;
    if BarsSinceEntry >= 3 then sell ("Time Exit LONG") next bar at market;
end;
With such built-in stop loss, stop loss can be triggered as soon as the entry bar:
Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


Note. It is consistent with Easy Language documentation.

"SetStopLoss function is evaluated intra-bar and not only on close of a bar, and can exit within the same bar as the entry."

"Normally strategies generate orders on the close of the bar for execution on the next bar, SetStopLoss allows you to generate orders and exit on the same bar as the bar of entry, this is especially useful when working with longer during bars, (e.g. 30-min, 60-min, daily, weekly, monthly)."

Any comment welcome!

Nicolas

Reply With Quote
The following 4 users say Thank You to Nicolas11 for this post:
 
  #8 (permalink)
Elite Member
Portland, OR
 
Futures Experience: Intermediate
Platform: Sierra Chart
Favorite Futures: ES
 
Posts: 269 since Jan 2011
Thanks: 326 given, 179 received

For the first case - can you try to set the option "allow unlimited entries"? If I remember correctly it should work fine.

Signal -> format

- for the entry code - you would have to make sure you don't enter it one more time ( probably need to use barssinceentry to filter out the re-entry trades for the bar).

Attached Thumbnails
buy next bar... and set stop immediately and not for the bar after-mc_unlimited_entries.jpg  
Reply With Quote
The following 2 users say Thank You to ejtrader for this post:
 
  #9 (permalink)
 Vendor: tradingcode.net 
The Netherlands
 
Futures Experience: None
Platform: MultiCharts, TradingView
Favorite Futures: ...
 
Jura's Avatar
 
Posts: 774 since Apr 2010
Thanks: 2,347 given, 661 received


Nicolas11 View Post
(..)
My conclusion is: it depends on the way the stop loss is coded.

1. With a manual stop loss, answer is NO.

2. With a built-in stop loss (SetStopLoss), answer is YES.

Hi Nicolas,

Your conclusion is correct, but there is a third way:

3. With a manual stop loss, and IntrabarOrderGeneration set to True, the answer is Yes.

Let's walk through an example: with your 'inside bar stop loss code'-strategy, I used this code...

 
Code
Variables:
    TickSize    ( MinMove / PriceScale );
    
if MarketPosition = 0 and H < H[1] and L > L[1] {inside bar} then begin
    Buy ("Entry LONG") next bar at market;
end;

if MarketPosition = 1 then begin
    Sell ("Stop Loss LONG") next bar at EntryPrice - 1 * TickSize or lower;
    Sell ("Take Profit LONG") next bar at EntryPrice + 5 * TickSize or higher;
    if BarsSinceEntry >= 3 then sell ("Time Exit LONG") next bar at market;
end;
(only changed the stop loss to one tick since I'm testing it on another instrument)

...and got the following result:

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


(Which is exactly what you've got in your post).

However, if we use IntrabarOrderGeneration set to true (meaning that on every tick the strategy logic is evaluated and on every tick orders can be submitted) we'll get the following code:

 
Code
[IntrabarOrderGeneration = TRUE]

Variables:
    TickSize    ( MinMove / PriceScale );
    
if (BarStatus(1) = 2) and // only submit buy orders at the close of the bar
    (MarketPosition = 0) and H < H[1] and L > L[1] {inside bar} then begin
       
        Buy ("Entry LONG") next bar at market;

end;

// In the code below, there is no BarStatus check; these orders are submitted on a tick by tick basis.
//        So if the buy is executed on tick 1 of the bar, the stop loss should be submitted on tick 2 of the bar.
if (MarketPosition = 1) then begin 
    Sell ("Stop Loss LONG") next bar at EntryPrice - 1 * TickSize or lower;
    Sell ("Take Profit LONG") next bar at EntryPrice + 5 * TickSize or higher;
    if BarsSinceEntry >= 3 then sell ("Time Exit LONG") next bar at market;
end;
...this gives the following result:

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).



PS: No need to apologize for a late answer.

Reply With Quote
The following 5 users say Thank You to Jura for this post:
 
  #10 (permalink)
Elite Member
near Paris, France
 
Futures Experience: Beginner
Platform: -
Favorite Futures: -
 
Nicolas11's Avatar
 
Posts: 1,070 since Aug 2011
Thanks: 2,232 given, 1,729 received


Thanks a lot, Jura!

This "BarStatus" was exactly what I was missing in order the entry order to be triggered on the close, but the exit order to be triggered any time (in the context of IntrabarOrderGeneration = true).

And I love this feeling of having learnt a new thing!

Thanks again,

Nicolas

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

Reply



futures io > > > > > buy next bar... and set stop immediately and not for the bar after

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
Book Discussion: Reading Price Charts Bar by Bar by Al Brooks cunparis Traders Hideout 530 October 19th, 2016 08:45 PM
End of bar strategies with advanced bar types (Renko, Range, Kagi, etc) RM99 Elite EasyLanguage Automated Trading 2 September 9th, 2011 09:38 AM
Whats the difference between Bar Magnifier & look inside bar testing? crbucks MultiCharts 1 May 4th, 2011 01:22 AM
Image:al brooks reading price charts bar by bar.jpg Big Mike Trading Wiki Images 0 July 1st, 2010 09:00 PM
Stop using the value of an indicator on previous bar nanobiotech NinjaTrader Programming 6 March 29th, 2010 11:20 PM


All times are GMT -4. The time now is 10: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-10 in 0.15 seconds with 20 queries on phoenix via your IP 54.221.73.186