25.10.2016 Views

Expert Advisor Programming by Andrew R. Young

Expert Advisor Programming by Andrew R. Young

Expert Advisor Programming by Andrew R. Young

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Tips and Tricks<br />

string SettingsComment = "FastMAPeriod: "+FastMAPeriod+" SlowMAPeriod: "+SlowMAPeriod;<br />

string StatusComment = "Buy order placed";<br />

Comment(SettingsComment+"\n"+StatusComment);<br />

We declare and set the values of the SettingsComment<br />

and StatusComment strings inside the start()<br />

function. At the end of the start function, we call the<br />

Comment() function and use it to print our comments to<br />

the chart. We use a newline character (\n) to separate<br />

the comments into two lines.<br />

Fig 8.1: Chart comment using a newline character<br />

Check Settings<br />

There are several expert advisor properties that must be enabled before the expert advisor may be<br />

allowed to trade. These settings are located under the Common tab in the <strong>Expert</strong> Properties dialog.<br />

The setting Allow live trading must be enabled before trading can commence. If it is not enabled, a<br />

frowning face will appear in the top right hand corner of the chart, next to the expert advisor name.<br />

You can check for this condition in your EA <strong>by</strong> using the IsTradeAllowed() function. If it returns<br />

false, the setting Allow live trading is disabled.<br />

If you'd like to display a message to the user indicating that this setting should be activated, you can<br />

do as follows:<br />

if(IsTradeAllowed() == false) Alert("Enable the setting \'Allow live trading\' in the<br />

<strong>Expert</strong> Properties!");<br />

If your expert advisor uses an external .ex4 library, the setting Allow import of external experts must<br />

be enabled in the <strong>Expert</strong> Properties. You can check for this using the IsLibrariesAllowed()<br />

function:<br />

if(IsLibrariesAllowed() == false) Alert("Enable the setting \'Allow import of external<br />

experts\' in the <strong>Expert</strong> Properties!");<br />

The same thing can be done for DLLs using the IsDllsAllowed() function:<br />

if(IsDllsAllowed() == false) Alert("Enable the setting \'Allow DLL imports\' in the<br />

<strong>Expert</strong> Properties!");<br />

123

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!