Introduction

Do you use Twitter? Do you want to tweet your daily performance or any other valuable information about your trading activity? Then read further to understand how I tweet my daily strategy performance.

Implementation

Requirements

Before moving on to the implementation itself, please make sure you have the following accounts in place:
  1. Twitter – https://twitter.com/
  2. IFTTT account with Twitter connection setup – https://ifttt.com/
  3. Email account with all the relevant details to send email, for example:

IFTTT Configuration

In this step, we will create a rule in IFTTT to post to twitter any email which reaches a specific monitored email address:
  • In the new screen which opens, click on “this” link to create your own applet:
  • Choose Email as a service by clicking the Email image:

  • Then select “Send IFTT any email” trigger:
  • Now that we have a trigger, we need to select the action, we do that but click the “that” button:
  • From the available services, select “Twitter”:
  • On the next screen, select “Post a tweet” as the action:
  • Complete the action by filling in the “Tweet text” box the following entry – {{Subject}} {{Body}} and click the “Create action” button:
That’s it, now you have a rule saying that if an email arrives to trigger@applet.ifttt.com, it will trigger a post to your twitter account using the email subject and body. 

MetaTrader Configuration

In MetaTrader you must setup the right details to enable sending a mail from an expert adviser. Personally, I am using Gmail so I setup the following details under preferences:
If you did the configuration properly as per the above instructions, you may click the test button and see a test message getting post in your Twitter account, something like (https://twitter.com/IlanTree):
Go ahead and try it yourself. If it doesn’t work, have a look in the journal tab and look for errors. If it worked, you should see the following message:

2019.04.29 17:19:56.201 Mail: ‘Test message’ has been sent

MQL4 Code

Now that we have all the configuration in place, we move on and introduce an expert adviser that will send the emails. I chose to code an expert which runs once a day and calculate the performance for the previous day, so the end results will look in Twitter as such:

const string SUFFIX=”| https://www.darwinex.com/darwin/GFA.4.21″; int TheDay=DayOfYear(); //+——————————————————————+ //| | //+——————————————————————+ void OnTick() { if(TheDay!=DayOfYear()) { int Tickets=0; double TotalProfit=0; double TotalPips=0; for(int i=OrdersHistoryTotal()-1;i>=0;i–) if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) && (OrderType()==OP_BUY || OrderType()==OP_SELL) && TheDay==TimeDayOfYear(OrderCloseTime()) && Year()==TimeYear(OrderCloseTime())) { Tickets++; TotalProfit+=OrderProfit()+OrderCommission()+OrderSwap(); TotalPips+=OrderType()==OP_BUY?(OrderClosePrice()-OrderOpenPrice())/MarketInfo(OrderSymbol(),MODE_POINT)/10:(OrderOpenPrice()-OrderClosePrice())/MarketInfo(OrderSymbol(),MODE_POINT)/10; } if(TotalPips!=0 && SendMail(StringConcatenate(TimeToStr(TimeCurrent()-3600,TIME_DATE),” GFA Trading Update: Closed “,IntegerToString(Tickets),” Order(s), “,DoubleToString(TotalPips,1),” Pips, “,DoubleToString(100*TotalProfit/AccountBalance(),2),”% Return”),SUFFIX)==false) SendNotification(“Failed twitting total orders”); TheDay=DayOfYear(); } }

I start with a constant string which will be used as the email subject, simply a link pointing to my strategy online.

Then, everyday I am going through the historical orders which got closed and some up their profit and pips.
I am checking that the order was closed on the same day and same year (it matters for strategies who are live from more than a year, thus the extra check).
Then, using SendMail uses the information I gathered to construct the email to trigger the twitter post.
Finally, I setup the TheDay variable to the current day and wait for the next day to finish and do the same.
You may noticed that I subtract 3600 from the timedate object, that’s to make sure I am posting for the previous day which was just over.

Conclusion

In this post, I shared with you a mechanism I am using to automatically tweet from within expert adviser relevant information.
You may use the code as is in side an expert adviser to post your daily performance, or modify it to post any other financial information.

Feel free to comment and raise questions if you have any, I am happy to answer.


This entry was posted by . Bookmark the . Titled

Leave a Reply

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