Algorithmic and Mechanical Forex Strategies | OneStepRemoved

  • Articles
  • Sophisticated Web Sites
  • Automated Trading
  • Testimonials
  • Contact

NinjaTrader Screenshot

July 26, 2013 by Shaun Overton Leave a Comment

Taking a screenshot of a chart in NinjaTrader is a 3 step process. You don’t need any outside software or special skills.

  1. Open a chart
  2. Right click. Select “Image” from the menu, then “Save As”
  3. Select the location where you’d like to save the file
ninjatrader screenshot

Right click on the chart to take a screenshot.

I always recommend saving files to the desktop if you’re not very savvy with computers. You can find them easily.

Filed Under: NinjaTrader Tips Tagged With: ninjatrader, screenshot

MQL Debugging

March 6, 2012 by Shaun Overton 1 Comment

MQL is a very simple scripting language. Debugging MQL, unfortunately, is not easy at all. The MetaEditor compiler that MetaQuotes supplies simply does not contain the sophisticated tools that most programmers are accustomed to using.

MQL debugging problems

Visual Studio and other sophisticated IDEs (integrated development environments) contain a number of features that make it easy to debug code while the programmer writes it. The biggest example of this are break points. A break point is a point in the code where the compiler tells the computer to cease running the program when it arrives at a certain line of code.

Consider the example where a trailing stop sets the new stop incorrectly. The natural instinct for most programmers would be to run the expert advisor on the visual backtester, then insert break points on the lines of code shortly after the trailing stop calculations. Break points halt the code, allowing the programmer to peer inside the brains of the software to see what it thought at the time it made a decision. The key advantage in Visual Studio is that the values of all of the variables are clearly visible. It is possible to walk through the program step by step. Whenever one of the steps does not follow the desired rules, the required change is usually obvious. MetaQuotes thankfully included break points in MQL5. They are not available in MQL4.

The lack of full intellisense support affects my programming speed more than anything. Intellisense detects the use of reserved words like OrderSelect() or ObjectGet(). The MetaEditor includes a rudimentary intellisense, but it lacks the fine details that make it so convenient in Visual Studio.

I am used to programming in C# where I can type the first few letters of a variable or class, then the IDE fills out the rest. When I type “Mes” in C# and push the space bar, I know that the MessageBox option will appear (assuming that I declared the appropriate namespace). The MetaEditor provides a list of candidates for reserved words. The programmer must then either select the option with the mouse or press enter.

I know it seems trivial to require pressing enter instead of the space bar, but think about how many times code resuses the same reserved words or variables. The extra key presses really do add up to a lot of unnecessary typing motions. That’s doubly true for a thirty year old that already wears a wrist brace for carpal tunnel pain.

The MetaEditor’s biggest weakness is that it does not detect variable names. We often write expert advisors that contain several thousand lines of code. Tracking the names of tens of variables poses its own challenges. When the coder types in the same set of variable names repeatedly, it would be nice to simply type the first three letters and move on. Copy and paste might provide a decent alternative. The problem is that variables usually group together. You cannot keep 5 different copy and paste items readily available.

The MetaEditor allows functions to return invalid types. Functions declared as double can return strings, integers or nothing at all. The MQL4 compiler does not track whether or not these are valid. It leaves it up to the programmer to discover the invalid type during real time testing. This oversight is a nightmare for the unwitting programmer that mistakenly returns the wrong type.

This is doubly true when a double function is mistakenly returned to an integer variable. MQL4 does not prevent illegal double to int casts. Even worse, the expert advisor continues running with a 0 value for the interger instead of throwing an exception or error message. I cannot count how many hours that I’ve wasted tracking down variables that look perfect, only to realize that I declared the wrong data type. This usually happens when I’m on autopilot, pounding out code. What seems efficient at the time usually costs several hours of hair pulling frustration.

MQL debugging techniques

The MQL programmers on staff here usually resort to any of the following techniques. You may find that using them in combinations helps improve the debugging process even more.

Debug compiler error

This one can be the most frustrating. The MetaEditor attempts to hint at which line of code causes the compiling error. I say attempts because it gets it wrong more often than it gets it right. There’s nothing more irritating than looking at a perfectly legitimate line of code that the compiler flags as problematic.

I almost always resort to commenting out increasingly large sections of code until the error disappears. I start with commenting out a single line of code. If that doesn’t work, then I comment out ten lines. If that doesn’t work, I might comment out entire functions or sections of code. When the compiler finally runs properly, you know that the last section of commented out code contains the bug.

Next, you backtrack. Start making the offending commented-out section smaller and smaller until the error reappears. Now, you have finally zeroed in on the actual source of the problem.

Debug in real time or on the backtester

My preferred method of debugging is to comment most of the relevant decision information onto the screen, which is done using the Comment() function. I then run the visual backtester, watching how the data behaves in relation to the visual information.

On screen comments are essentially jury-rigged break points. Controlling how and when they appear allows the programmer to step through the code to uncover the issue. The only difference is that comments do not forcefully prevent the code from running. The text which appears is very small. Aside from that, I really like that fact that it’s so robust. The comment function always works without a hitch, making it the best friend of a programmer that’s debugging code.

Taking screenshots takes this to the next level. Whenever customers ask questions about why an expert advisor behaved a certain way, the easiest answers come with screenshots. Commenting the imitation break points usually provide bullet proof answers – the programmer and customer can literally see what the EA thought at the time it made a decision. MQL4 offers the WindowScreenShot() function to do this.

The EAs that we program always take screenshots during critical actions, such as entering a trade or adjusting an exit condition. The goal is to provide a visual record of every decision with an eye to answering future questions about the behavior.

Our default template includes a true/false variable called WriteScreenshots. Traders control whether they want to bother with this debugging feature or not. The only downside to it is that every recorded action eats up about 50kb of hard drive space.

Log files represent the final debugging option. The major drawback is that they are so ugly and difficult to read. I almost always prefer screenshots for this reason.

Nonetheless, log files do have their place. The main way to use them is as error catchers. Whenever a process goes awry due to a problem with either MetaTrader itself or with a broker transaction, the log file is the easiest place to catch it.

Debugging MQL files is a skill that takes awhile to learn. The tools at the programmer’s disposal are much different from those available to higher level languages. Once you get used to working with the much simpler tools in the MetaEditor and MetaTrader, the bug clearing process usually gets much easier.

Filed Under: MetaTrader Tips Tagged With: break point, comment, log, metaeditor, MetaQuotes, metatrader, mql, MQL4, MQL5, screenshot, Visual Studio

Top 10 MetaTrader Tips

January 12, 2012 by Shaun Overton Leave a Comment

Buying and selling in MetaTrader is about as simple as it gets. There are, however, a number of features in the platform that most traders don’t know about. Here are the top 10 tips that save me the most time working every day with MetaTrader.

  1. Use templates. Templates are arrangements of indicators and chart settings that maintain a personalized look and feel. They help you avoid doing the same task over and over again. The video below explains how to set them up.
  2. Measure the number of bars back. Select the crosshair tool from the toolbar. Left click on any bar, then drag the mouse around. You’ll see a box with numbers like 8 / 109 / 117.809, which is an example that I just did with the GBP/JPY. In this case, the box tells me that my measurement is 8 bars long, 109 micropips (10.9 pips) tall and the final price is 117.809.
  3. Change the symbol of a chart that you already have open. Put the mouse in the very bottom left corner of an open chart. You’ll see the icon change. When this happens, double click. You can now change the symbol name. Push enter to change the chart.
  4. Use scripts to do the little things like attach stops and limits, opening new orders and deleting all of the pending orders in your account. This is a task that often requires a bit of MQL programming.
  5. Take screenshots inside of MetaTrader. Right click on the chart. You’ll see an option that says “Save screenshot.”

  6. Push F5 to change the properties of an Expert Advisor on the chart. I find this easier than moving my mouse around all the time.
  7. Push F8 to change a chart’s properties. This allows you to change the colors, the grid display and all of the visual elements that drive you crazy.
  8. Use the profiles to keep your desktop space clean. A profile in MetaTrader allows you to use templates on different charts, but to categorize broad groups. Say, for example, that I like to either trade GBP pairs or AUD pairs. I could create two diferent profiles with different chart settings and indicators. Whenever I want to flip between them, I just go to File \ Profiles \ Next. Alternatively, I can just push Control and F5 on the keyboard at the same time. As you can tell, I’m a big fan of keyboard shortcuts.
  9. Reduce the number of bars on your charts if your custom indicators run too slowly. Go to Tools \ Options \ Charts. Change the number of bars to something reasonable like 3,000. You don’t really need to scroll through 50,000 bars while you’re day trading.
    Change the maximum bars in the MetaTrader Options

    Change the maximum bars to something reasonable like 3,000.

  10. Edit the symbols in Market Watch if your broker isn’t showing all of the currencies. Right click on the Market Watch window (the one that shows all of the updating prices). Select “Symbols” from the menu. Use the show and hide buttons to select which currencies you want to turn on and off.

Filed Under: MetaTrader Tips Tagged With: micropip, pip, profile, screenshot, script, template

FREE trading strategies by email

Trending

Sorry. No data so far.

Archives

  • Dominari
  • How does the forex market work?
  • Indicators
  • MetaTrader Tips
  • MQL (for nerds)
  • NinjaTrader Tips
  • Pilum
  • QB Pro
  • Stop losing money
  • Test your concepts historically
  • Trading strategy ideas
  • Uncategorized
  • What's happening in the current markets?

Translation


Free Trading Strategies

Privacy PolicyRisk Disclosure

Copyright © 2022 OneStepRemoved.com, Inc. All Rights Reserved.