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)
I want to try a simple backtest for EUR/USD, which
- Buys when the current price is just above the previous daily bar's high, and has a fixed stop loss / take profit / break even
- Adjusts position size to be 10% of the total equity in that account per trade
I have intrabar generation as true because I want to buy when the 'current price' of the bar exceeds the previous high. Not the O/H/L/C numbers. Running the code below on the backtest tends to generate way too few trades, only when the daily open is above the previous day's high (even with bar magnifier enabled). Please help!
How can I achieve this? Here's where I stand currently. Thanks in advance!
Can you help answer these questions from other members on NexusFi?
Trading: Primarily Energy but also a little Equities, Fixed Income, Metals and Crypto.
Frequency: Many times daily
Duration: Never
Posts: 5,049 since Dec 2013
Thanks Given: 4,388
Thanks Received: 10,208
May not answer your question completely but if you replace
With
I think you'll see something similair to what you want.
Your code is looking at the high of bar 1, comparing it to the open of bar 2, and then sending an order on the open of bar 3. Using the stop code, it looks at the high of bar 1, and enters a buy (stop) order to buy immediately if the market equals the high of bar 1 DURING bar 2.
Can't help on position sizing cause I trade futures.
The previous day’s high is HighD(1).
If you use High[1] you’re watching at previous candle. It is the same only in daily TF but you can use HighD in every TF and it will always return previous day’s High.
Notice that HighD is a function and High is an array.
About your entry think about this: do you want a market entry or a breakout entry at HighD[1] + 1 stop ?
are you applying the code to a daily chart or an intraday chart?
Your code tells MC to do exactly what you are seeing as you are using the reserved word "Open", which just returns the open of the bar and does not change during the bar. The reserved word Close on the other hand will get updated throughout the bar and return the last traded price.
As @SMCJB and @Al3cs have pointed out the correct approach will depend whether you want to issue a market order when your condition is met or place a stop order upfront at the desired entry price.
Got it to do exactly what was needed. I wanted the flexibility of testing on multiple timeframes so went with High[1] rather than HighD, but appreciate the suggestion.
Any ideas on how to get started on the position sizing?
Right now, trading 1 contract (and no leverage settings) seems to be tiny and I am trying to get it to trade 10% of the equity on my account. I'm also assuming that leverage will be calculated in my algo rather than an MC setting.
for your backtests it might be simpler to create an input allowing you to specify the start account equity and then
size your position based on that (maybe store the starting equity in a variable and add the NetProfit to keep track of the changes in the account equity).
The actual formula for the sizing depends on your broker as some deal in units and others in lots.
I would suggest to use the print reserved word to keep track of the values that your code sees and what you compute internally.
Besides that, if you want to include more than one expression in your conditions, you will have to use "if... then begin...end" statements. https://www.multicharts.com/trading-software/index.php/If