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 -- discounts are available after registering.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
I am very new to EasyLanguage and even coding in general, so please bear with me.
I have an ATM strategy in NT that I would like to backtest/automate in MC. I have just started researching how to do this, but I figured if anyone here has some advice, I'd really appreciate it. Allow me to present the facts first and then ask my questions last.
Facts:
Basically the ATM consists of three targets, a stoploss, a breakeven, and finally a trailing stop.
I use MACD as my signal generator. When the fast crosses the slow I enter a trade. The direction of the trade is determined by whether the cross happens above or below the zero line.
Questions:
I don't really know where to start with coding this... Does anyone know of any good resources or threads (I searched NexusFi (formerly BMT) but didn't really find anything related to this) that I could use? I'm here to learn, not to leech.
In NT, backtesting this strategy was way beyond my skill level and even some skilled coders I spoke to said this was difficult to code in NT due to the trailing stoploss and breakeven since they need to be triggered intra bar. This is possible to do in MC, right? From what I've read it seems possible...
Is there someplace I can go to learn some basic EasyLanguage coding fundamentals and logic?
Any help you can provide will be much appreciated!
Happy Trading,
ARich
Can you help answer these questions from other members on NexusFi?
Last year I did a video tutorial on creating an advanced NinjaTrader strategy, and you guys liked it. So I thought that since I don't use NT any more it would be a good idea to do the same strategy as an example in EasyLanguage with MultiCharts.
I finished my first set of code! There were some errors and such, but I finally got it to compile. The only problem is that when applied to a chart it only produced one entry (a "buy") when it should have produced at least 20-30 entries over that time frame. Here is my code:
if MyMACD > MACDAvg and MyMACD <= 0 and MACDAvg <= 0 then begin
Buy ("Enter Long1") 100000 contract next bar at market;
Buy ("Enter Long2") 100000 contract next bar at market;
Buy ("Enter Long3") 100000 contract next bar at market;
end;
if MyMACD < MACDAvg and MyMACD >= 0 and MACDAvg >= 0 then begin
Sell ("Enter Short1") 100000 contract next bar at market;
Sell ("Enter Short2") 100000 contract next bar at market;
Sell ("Enter Short3") 100000 contract next bar at market;
end;
if CurrentContracts = 1 then begin
Sell ("Exit l3-c1 Target") 100000 Contract Next Bar at (EntryPrice + t3) Limit;
Sell ("Exit l3-c1 Stop") 100000 Contract Next Bar at st3 Stop;
end;
if CurrentContracts = 2 then begin
Sell ("Exit l2-c2 Target") 100000 Contract Next Bar at (EntryPrice + t2) Limit;
Sell ("Exit l2-c2 Stop") 100000 Contract Next Bar at st2 Stop;
Sell ("Exit l3-c2 Target") 100000 Contract Next Bar at (EntryPrice + t3) Limit;
Sell ("Exit l3-c2 Stop") 100000 Contract Next Bar at st3 Stop;
end;
if CurrentContracts = 3 then begin
Sell ("Exit l1-c3 Target") 100000 Contract Next Bar at (EntryPrice + t2) Limit;
Sell ("Exit l1-c3 Stop") 100000 Contract Next Bar at st1 Stop;
Sell ("Exit l2-c3 Target") 100000 Contract Next Bar at (EntryPrice + t2) Limit;
Sell ("Exit l2-c3 Stop") 100000 Contract Next Bar at st2 Stop;
Sell ("Exit l3-c3 Target") 100000 Contract Next Bar at (EntryPrice + t3) Limit;
Sell ("Exit l3-c3 Stop") 100000 Contract Next Bar at st3 Stop;
end;
end;
if CurrentContracts = 1 then begin
BuyToCover ("Exit s3-c1 Target") 100000 Contract Next Bar at (EntryPrice - t3) Limit;
BuyToCover ("Exit s3-c1 Stop") 100000 Contract Next Bar at st3 Stop;
end;
if CurrentContracts = 2 then begin
BuyToCover ("Exit s2-c2 Target") 100000 Contract Next Bar at (EntryPrice - t2) Limit;
BuyToCover ("Exit s2-c2 Stop") 100000 Contract Next Bar at st2 Stop;
BuyToCover ("Exit s3-c2 Target") 100000 Contract Next Bar at (EntryPrice - t3) Limit;
BuyToCover ("Exit s3-c2 Stop") 100000 Contract Next Bar at st3 Stop;
end;
if CurrentContracts = 3 then begin
BuyToCover ("Exit s1-c3 Target") 100000 Contract Next Bar at (EntryPrice - t2) Limit;
BuyToCover ("Exit s1-c3 Stop") 100000 Contract Next Bar at st1 Stop;
BuyToCover ("Exit s2-c3 Target") 100000 Contract Next Bar at (EntryPrice - t2) Limit;
BuyToCover ("Exit s2-c3 Stop") 100000 Contract Next Bar at st2 Stop;
BuyToCover ("Exit s3-c3 Target") 100000 Contract Next Bar at (EntryPrice - t3) Limit;
BuyToCover ("Exit s3-c3 Stop") 100000 Contract Next Bar at st3 Stop;
end;
end;
Can anyone see why it is only executing one trade? It only enters one position too (instead of three positions). Is there a simpler way to code this?
I have tried it: the first trade is never closed. The problem is probably linked to the exit.
In case of problem, you should simplify the code to identify the issue.
Just keep one side (long or short).
Just keep one lot (not the 3 lots).
And debug.
When the short code will work, add back the other features.
People here will be happy to help you.
But it would be easier with a "simple" but non-working code rather than with a 100-line code.
In other words: a SSCCE.
Thank you for the suggestion! A big question for me is why it didn't enter all three positions. That's a big part of the strategy, and I have no idea why it won't enter all three positions... If it entered one, why not the others? Should I write it as:
Buy ("Enter Long1") 3 100000 contracts next bar at market;
instead of:
Buy ("Enter Long1") 100000 contracts next bar at market;
Buy ("Enter Long2") 100000 contracts next bar at market;
Buy ("Enter Long3") 100000 contracts next bar at market;
Ah, thank you for the URL; I didn't know what you were referring to earlier.
This is the shortened code:
// Open new Positions
if MarketPosition = 0 then begin
if MyMACD > MACDAvg and MyMACD <= 0 and MACDAvg <= 0 then begin
Buy ("Enter Long1") 300000 contracts next bar at market;
end;
end;
// Manage open orders
if MarketPosition = 1 then begin
st1 = EntryPrice - (StopSize * TickSize);
if CurrentContracts = 1 then begin
Sell ("Exit l1-c1 Target") 3 * 100000 contracts Next Bar at (EntryPrice + t1) Limit;
Sell ("Exit l1-c1 Stop") 3 * 100000 contracts Next Bar at st1 Stop;
end;
end;
That's as bare-bones as it gets I'm afraid. Is there anything that jumps out at you? I've tried changing the lot size too, but I can't get it to show anything other than "100,000" on the chart. I'm not sure how to troubleshoot the exit part of the code either... Thanks for your help!