Actionscript timestamp string representation - actionscript

I need to get a string representation of the current timestamp in format YYYY-MM-DDThh:mm:ssZ

See the Date class, and the following properties (in order based on your question):
fullYear
month
date
hours
minutes
seconds
var date:Date = new Date();
var answer:String = date.fullYear + "-" + (date.month+1) + "-" + date.date + " " + date.hours + ":" + date.minutes + ":" + date.seconds;
trace(answer); // 2012-1-17 10:48:41

Related

How can I select only the last closed order(s) on Metatrader 4?

Right now I select all history trades using a loop whenever there is a new history trade (onTimer handler with 1 second timer period):
/*
3.) History Trades
*/
static int historyTradesTotal=0;
if(OrdersHistoryTotal()==historyTradesTotal) return;
historyTradesTotal = OrdersHistoryTotal();
int i,hstTotal = OrdersHistoryTotal();
string historical_trades = "";
for(i=hstTotal; i >= 0; i--)
{
//---- check selection result
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) continue;
historical_trades = historical_trades +
"historical_trades|" +
version + "|" +
DID + "|" +
IntegerToString(AccountNumber()) + "|" +
IntegerToString(OrderTicket()) + "|" +
TimeToString(OrderOpenTime(), TIME_DATE|TIME_SECONDS) + "|" +
TimeToString(OrderCloseTime(), TIME_DATE|TIME_SECONDS) + "|" +
IntegerToString(OrderType()) + "|" +
DoubleToString(OrderLots(),2) + "|" +
OrderSymbol() + "|" +
DoubleToString(OrderOpenPrice(),5) + "|" +
DoubleToString(OrderClosePrice(),5) + "|" +
DoubleToString(OrderStopLoss(),5) + "|" +
DoubleToString(OrderTakeProfit(),5) + "|" +
DoubleToString(OrderCommission(),2) + "|" +
DoubleToString(OrderSwap(),2) + "|" +
DoubleToString(OrderProfit(),2) + "|" +
"<" + OrderComment() + ">|";
}
}
So now how can I just select the orders that have been closed between the last onTimer event to avoid looping through all trades whenever a new one is closed all the time?
The solution should also consider the rare case if two or more trades are closed parallely within one second e.g..
int i = OrdersHistoryTotal();
int a = OrdersHistoryTotal() - 10;
int b = OrdersHistoryTotal();
for (i = a;i < b ;i++)
{
if (OrderSelect(i,SELECT_BY_POS, MODE_HISTORY) == true)
{
Alert("orders found"+ OrderTicket() + " " + OrderCloseTime());
}
}
This code works and it's starts from the 10th order from the most previous order in history but if you wanted to check just the previous order you could subsitute 10 for 1 in int a. if you want to check only the last 5 orders change 10 to 5. Simple.
That is not possible in MQL4. Orders are stored and returned by their ids, you cannot apply custom sort. so you have to loop over them all starting from the last to find the one you need. Alternative is to keep all the open orders in CArrayInt or array (add when a new trade is open, delete when found a closed one, read/write when doing init/deinit) and check the live_trades_array elements are still open. That might be much faster if your ea has just several orders and several different ea's on the platform.

Check if number of OrdersHistoryTotal in Metatrader 4 trade history changed

I would like to fire a function as soon as a trade was closed (= the OrdersHistoryTotal increased by at least 1).
Is there any handler in MQL4 for such scenarios?
In my particular setup I have the following function pushSocket which should only push data in case the OrdersHistoryTotal changed.
int i,hstTotal=OrdersHistoryTotal();
string historical_trades = "";
for(i=0;i<hstTotal;i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) continue;
historical_trades = historical_trades +
"historical_trades|" +
version + "|" +
DID + "|" +
AccountNumber() + "|" +
IntegerToString(OrderTicket()) + "," +
TimeToString(OrderOpenTime(), TIME_DATE|TIME_SECONDS) + "," +
TimeToString(OrderCloseTime(), TIME_DATE|TIME_SECONDS) + "," +
IntegerToString(OrderType()) + "," +
DoubleToString(OrderLots(),2) + "," +
OrderSymbol() + "," +
DoubleToString(OrderOpenPrice(),5) + "," +
DoubleToString(OrderClosePrice(),5) + "," +
DoubleToString(OrderStopLoss(),5) + "," +
DoubleToString(OrderTakeProfit(),5) + "," +
DoubleToString(OrderCommission(),2) + "," +
DoubleToString(OrderSwap(),2) + "," +
DoubleToString(OrderProfit(),2) + "," +
"<" + OrderComment() + ">|";
}
pushSocket.send(StringFormat("%s", historical_trades, true));
I tried to insert a counter to compare it but the counter is deleted every time on memory clean-up.. The above function is nested in a onTick function which executes every second.
There is a function OnTradeAction() in MQL5 that is called every time some trading action is done. But unfortunately this function is not available in MQL4. On the other hand, you can implement a function inside OnTick() that will check that HistoryTraderTotal() increased compared to the previously saved value, and do all the steps you like in that case. A bit more work but almost the same.
OnTimer(){
Mt4OnTradeAction();
otherLogic();
}
Mt4OnTradeAction(){
static int historyTradesTotal=0;
if(HistoryTradesTotal()==historyTradesTotal) return;
historyTradesTotal = HistoryTradesTotal();
processingTrade();
}

How to hdf5 (Hdfsl ) file (One Column Read) read (Big Size file)

I am using the HDF5DotNet with C# and I can read only full data as the attached image in the dataset.
The hdf5 file is too big, up to nearly 1.4GB, and if I load the whole array into the memory then it will be out of memory.
I would like to read all data from One columns
double[] values = new double[203572];
string m_Doc_01 = "data/sample/line";
HDFql.Execute("USE DIRECTORY " + "\"" + File_Directory + "\"");
HDFql.Execute("USE FILE " + "\"" + File_Name + "\"");
HDFql.Execute("CREATE CHUNKED(1, 203572) DATASET my_dataset_BS AS DOUBLE(2050, 203572)");
How to "m_Doc_01 ==> my_dataset_BS" Data
???
???
for (int i = 0; i < 2050; i++)
{
HDFql.Execute("SELECT FROM " + "\"" + m_Doc_01 + "\"" + "(1:::1) INTO MEMORY " + HDFql.VariableRegister(values));
}
To read the column that you have highlighted in the screenshot (i.e. column #0), you have to change the hyperslab to (please note the 0):
HDFql.Execute("SELECT FROM " + "\"" + m_Doc_01 + "\"" + "(, 0:::1) INTO MEMORY " + HDFql.VariableRegister(values));
That said, if you want to loop through the dataset and read one column at the time do the following (also better to register variable values before the loop starts and unregister it after the loop is done - this will increase performance):
number = HDFql.VariableRegister(values);
for(int i = 0; i < 2050; i++)
{
HDFql.Execute("SELECT FROM " + "\"" + m_Doc_01 + "\"" + "(, " + i + ":::1) INTO MEMORY " + number);
// do something with variable "values" (which contains the values of column #i)
}
HDFql.VariableUnregister(values);

Twitter API link parser

I am having an issue and tried to do everything regarding this!! even HttpUtility.ParseQueryString won't help!
I am trying to parse twitter links coming from the API in the form of http://t.co/oEVQbihMWu. I need the fully resolved URL.
My code:
richTextBox1.Clear();
richTextBox1.Visible = true;
SearchOptions SO = new SearchOptions();
SO.GeoCode = richTextBox3.Text + "," + richTextBox2.Text + "mi";
TwitterResponse<TwitterSearchResultCollection> TweetSearchResult = TwitterSearch.Search(tokens, "#blogger", SO);
if (TweetSearchResult.Result != RequestResult.Success) richTextBox1.Text = "connection Error";
else
{
string a = null;
foreach (var tweet in TweetSearchResult.ResponseObject)
{
string b = tweet.User.Location.Contains(",") ? tweet.User.Location.Replace(",", "-") : tweet.User.Location;
a += string.Format("{0},{1},{2},{3},{4},{5},{6},{7}", tweet.CreatedDate, b, tweet.User.Id,
tweet.User.ScreenName, tweet.User.Name, tweet.User.NumberOfFollowers, tweet.User.Website, Environment.NewLine);
richTextBox1.AppendText(" " + tweet.CreatedDate + "\n" + tweet.User.Location + "\n" + tweet.User.Id + "\n" + tweet.User.ScreenName + "\n" + tweet.User.Name + "\n" + tweet.User.NumberOfFollowers +
"\n" + tweet.User.Website + "\n" + tweet.Text + "\n\n\n");
}
links being represented by tweet.user.website.
any help? :)
In the API response, there is entities.urls which contains an array of url and expanded_url mappings. Check your library's documentation for equivalent.
Alternatively, if you inspect the response for t.co links, you will find this:
<noscript><META http-equiv="refresh" content="0;URL=http://www.fitnessbydanielle.com"></noscript><title>http://www.fitnessbydanielle.com</title><script>window.opener = null; location.replace("http:\/\/www.fitnessbydanielle.com")</script>
Parse it to get the url.
I managed to crack it.
What I did:
foreach (var tweet in TweetSearchResult.ResponseObject)
{
if(tweet.User.Website != null)
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(tweet.User.Website);
req.AllowAutoRedirect = false;
var resp = req.GetResponse();
string realUrl = resp.Headers["Location"];
string b = tweet.User.Location.Contains(",") ? tweet.User.Location.Replace(",", "-") : tweet.User.Location;
a += string.Format("{0},{1},{2},{3},{4},{5},{6},{7}", tweet.CreatedDate, b, tweet.User.Id,
tweet.User.ScreenName, tweet.User.Name, tweet.User.NumberOfFollowers, realUrl, Environment.NewLine);
richTextBox1.AppendText(" " + tweet.CreatedDate + "\n" + tweet.User.Location + "\n" + tweet.User.Id + "\n" + tweet.User.ScreenName + "\n" + tweet.User.Name + "\n" + tweet.User.NumberOfFollowers +
"\n" + realUrl + "\n" + tweet.Text + "\n\n\n");
}
}
File.AppendAllText(#".\BloggerTable.csv", a, Encoding.UTF8);
}
Wrapped it inside a condition so no users without website will show and used a webrequest to get the link. stored the location inside the httprequest header for each and every tweet.

Fusion table ST_INTERSECTS not work

My App using fusiontable to select records id by ST_INTERSECTS working fine before suddenly not work now!
var queryText = encodeURIComponent("select id from "+ v_TableID +" where ST_INTERSECTS(address, CIRCLE(LATLNG(" + lat + ',' + lng + '),' + 1000 + '))' + "and" + v_select + "and id > 1" );
var query = new google.visualization.Query("http://www.google.com/fusiontables/gvizdata?tq=" + queryText);
If removed ST_INTERSECTS(address, CIRCLE(LATLNG(" + lat + ',' + lng + '),' + 1000 + '))it work fine
var queryText = encodeURIComponent("select id from "+ v_TableID +" where " + v_select + "and id > 1");
var query = new google.visualization.Query("http://www.google.com/fusiontables/gvizdata?tq=" + queryText);
if i modify fusion table address(eg: 22.2202,113.9196 change to 22.22,113.919) it work again but only the first time.
Additional information
var v_select = 'category in ("abc","xyz")';
i try again than find out
var queryText = encodeURIComponent("select id from "+ v_TableID +" where ST_INTERSECTS(address, CIRCLE(LATLNG(" + lat + ',' + lng + '),' + 1000 + '))' + "and" + 'category in ("abc","xyz")' + "and id > 1" );
var query = new google.visualization.Query("http://www.google.com/fusiontables/gvizdata?tq=" + queryText);
if i remove "category in ("abc","xyz")" OR "ST_INTERSECTS(address, CIRCLE(LATLNG(" + lat + ',' + lng + ')" work fine.
Is it not allow to use "in" and "ST_INTERSECTS" together now?
Before 28/10/2012 it work fine i use the same clause already 6 months but now not work.
Please help
I appreciate that this isn't an answer (I don't have enough rep to make a comment) but it might help in solving this problem - I am having a similar problem with an almost identical query which has worked for a while. It seems to be because of the switch from Numeric tableID's to encrypted tableID's - that's the only difference in my two versions of code. Is the poster using encrypted table ID's? Working to try and fix this with no luck so far...

Resources