Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
buy next bar... and set stop immediately and not for the bar after
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
Can you help answer these questions from other members on NexusFi?
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.
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:
Code:
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.
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.
The stop loss begins to be considered only at the bar following the entry:
2.With a built-in stop loss (SetStopLoss), answer is YES.
With such built-in stop loss, stop loss can be triggered as soon as the entry bar:
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)."
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).
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...
(only changed the stop loss to one tick since I'm testing it on another instrument)
...and got the following result:
(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:
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!