This is really simple, but throwing it out there as it’s a noob way of getting into C (I’m a noob at C) and it’s somewhat fun.  This is also something I’ll extend to some other testing/UI related stuff with MetaTrader.

What is MetaTrader?

MetaTrader is a charting software solution. It’s free.  It’s a Windows application, but can be used on OSX via PlayOnMac.  MetaTrader links to a brokerage account (demo or live account) and will pull their (the broker’s) data feed for the commodities, stocks, indices, Forex that they support.

Basically you get charts and data that a trader can use for Technical Analysis.  By Technical Analysis, I refer to the use of indicators (MACD, Bollinger Bands, RSI, etc.) as well as data analysis (like Fibonacci retracements.)  Tools like this analyze the data in the chart and provide some visual reference for a prediction of price change in the future.

There’s a huge market for these tools.  One specific type of plugin is the Expert Adviser (EA for short.)  This is an automated tool. It will take positions for you (through your broker) based on some automated logic.  This can be both wonderful, or scary.

Screen Shot 2015-02-06 at 10.46.11 AM
MetaTrader 4 window.

These indicators work directly with your broker through an API.  All code is written in a MetaTrader language that is based on C.

Modification of an Indicator

I wanted to use an indicator but modify it so that it outputs some text on screen.  As you’ll see this mod is really simple but it opens up a plethora of opportunity to create our own indicators in the future.

There is a public indicator available called “Candle Pip Range,” which outputs to screen a number for the range (spread) of a candle in pips.  After I downloaded the indicator, I had to modify it to make it to output to screen the words “Good Spread” or “Low Spread” based on the size of pips in the current candle.

After installing the indicator, to modify it, you simply click the editor icon Screen Shot 2015-02-06 at 10.54.12 AM and then pick the indicator in your indicator folder.  In the editor, the C code that makes the indicator work, will be displayed in the right side.  I scrolled down to the area I wanted to deal with (the outputting of the values to screen.)  

   ObjectCreate("Ki",OBJ_LABEL,0,0,0);
   ObjectCreate("Ki2",OBJ_LABEL,0,0,0);
   
   if(Range_Buffer[0] > 78) ObjectSetText("Ki","GOOD SPREAD",12,"Arial",Red); else ObjectSetText("Ki","LOW SPREAD",12,"Arial",Red);

   if(Range_Buffer[0] > 78) ObjectSetText("Ki2",DoubleToStr(Range_Buffer[0],0),10,"Arial",Red); else ObjectSetText("Ki2",DoubleToStr(Range_Buffer[0],0),10,"Arial",Red);

   ObjectSet("Ki",OBJPROP_CORNER,1);

   ObjectSet("Ki",OBJPROP_XDISTANCE,10);

   ObjectSet("Ki",OBJPROP_YDISTANCE,30);
   
  ObjectSet("Ki2",OBJPROP_CORNER,1);

   ObjectSet("Ki2",OBJPROP_XDISTANCE,10);

   ObjectSet("Ki2",OBJPROP_YDISTANCE,50);

In the above code I added a new object Ki2, using the ObjectCreate function. I added some if statements which said, if the spread has a value in a range greater than 78, to output to the screen the words “GOOD SPREAD” in red.

I also output the numeric value below it.

After that I use the ObjectSet function to choose where the Ki2 text object will be placed.

That’s it. Now we compile and recheck our chart with the indicator… it should now read LOW SPREAD in the upper right of the screen, when the candle has a value at 78 or less and GOOD SPREAD when it is above 78.

 

Leave a Reply

Your email address will not be published. Required fields are marked *