I am new to MQL4 and MetaTrader4. I have a CSV file in a following format -
2017.2.1 0:00, 120
2017.2.1 0:05, 123
2017.2.1 0:10, 125
The date format is YYYY.M.D H:MM. I searched other forums, but couldn't get help. I want this to be plotted as an indicator.
about reading data: need to open data, then read its content:
bool ReadFile(const string fileName, string &data){
const int handle=FileOpen(fileName,FILE_READ|FILE_TXT);
if (handle==INVALID_HANDLE) return false;
string collector = "";
int SIZE = (int)FileSize(handle);
int size=StringLen(collector);
while(size < SIZE && !IsStopped()){
collector = StringConcatenate(collector, "\n", FileReadString(handle, SIZE - size));
size = StringLen(collector);
}
FileClose(handle);
if (!FileDelete(fileName))
Print("FileDelete(", fileName, ") FAILED"); // to delete this file after it is read
data = collector;
return true;
}
about parsing each line of the above obtained text:
MqlTime mql;
int st_pos=0,end_pos=0;
int year = 0;
end_pos = StringFind(line, ".", st_pos);
int year = StrToInteger(StringSubStr(line,st_pos+1,end_pos-st_pos-1));
mql.year = year;
// same with month, day, hour and minute
datetime time = StructToTime(mql); - this is your date
after that - find index using iBarShift() that corresponds to your date and Buffer[i] = value that is parsed from the same line
Related
I need to create a function that transmits a parameter as a 'char' and returns the value of that 'char' as a integer at its square value.
For example:
char nr[] = "11";
cout << strToNumber(nr);//will return the value 121;
int strToNumber (char c[]) {
int cifra, rezultat, fin;
cifra = c - '0';
return cifra * cifra;
}
int main () {
char sir[9] = "13";
char c;
int n = strlen(sir);
for (int i = 0; i < n; ++i) {
c = sir[i];
strToNumber(c);
}
return 0;
}
I tried to send the whole 'char' as a parameter one at a time. First I sent sir[0] which is '1' and afterwards I sent sir[1] which is '3'. The problem is that I did not manage to save the parameters in one variable so that I can easily multiply it by itself. In this case each parameter is multiplied by itself one at a time. '1' * '1' and '3' * '3'.
I am new to this 'char' and I do not fully understand it yet. If there is another way to send my parameters and to handle the function I would truly appreciate it... Thanks in advance!
I am trying to upload file using end point buckets/:bucketKey/objects/:objectName/resumable
I am always getting the response code 202 even for the final chunk. As per documentation i should receive response 200 with some urn details for the final upload. How to solve this? For testing i was using 17 MB file. But my main agenda is to upload larger files.
Below are my code:
byte[] bytes = uploadObjectRequest.getInputStream().readAllBytes();
int fileSize = bytes.length;
System.out.println("File size in bytes: "+ fileSize);
int chunkSize = 5 * 1024 * 1024 ;
int nbChunks = (fileSize / chunkSize) + 1;
try(ByteArrayInputStream isReader = new ByteArrayInputStream(bytes)){
for(int i = 0; i < nbChunks; i++){
int start = i * chunkSize;
int end = Math.min(fileSize, (i + 1) * chunkSize) - 1;
String range = "bytes " + start + "-" + end + "/" + fileSize;
// length of this piece
int contentLength = end - start + 1;
byte[] buffer = new byte[contentLength];
int count = isReader.read(buffer, 0, contentLength);
ByteArrayInputStream is = new ByteArrayInputStream(buffer);
uploadObjectRequest.setContentLength(contentLength);
uploadObjectRequest.setContentRange(range);
String sessionId = UUID.randomUUID().toString();
uploadObjectRequest.setSessionId(sessionId);
uploadObjectRequest.setInputStream(is);
System.out.println(String.format("For Chunk %s contentLength %s, contentRange %s, sessionId %s", i, contentLength, range, sessionId));
HttpResponse res = datamanagementAPI.uploadObjsInChunk(uploadObjectRequest, authenticator);
int status = res.getStatusLine().getStatusCode();
}
}
I got an example in Node.js posted here. Back to your code, you need to modify it like this:
string sessionId = UUID.randomUUID().toString()
byte[] bytes = uploadObjectRequest.getInputStream().readAllBytes();
int fileSize = bytes.length;
System.out.println("File size in bytes: "+ fileSize);
int chunkSize = 5 * 1024 * 1024 ;
if ( fileSize < chunkSize ) {
// Do a standard upload since OSS will reject any chunk less than 2Mb
// At the same time, using the chunk approach for small files has a cost.
// So let's say 5Mb is our limit.
...
return;
}
int nbChunks = (int) Math.floor(fileSize / chunkSize);
if ((fileSize % chunkSize) != 0)
nbChunks++;
try(ByteArrayInputStream isReader = new ByteArrayInputStream(bytes)){
for(int i = 0; i < nbChunks; i++){
int start = i * chunkSize;
int end = start + chunkSize - 1;
if (end > fileSize - 1)
end = fileSize - 1;
String range = "bytes " + start + "-" + end + "/" + fileSize;
// length of this piece
int contentLength = end - start + 1;
byte[] buffer = new byte[contentLength];
int count = isReader.read(buffer, 0, contentLength);
ByteArrayInputStream is = new ByteArrayInputStream(buffer);
uploadObjectRequest.setContentLength(contentLength);
uploadObjectRequest.setContentRange(range);
String sessionId = sessionId;
uploadObjectRequest.setSessionId(sessionId);
uploadObjectRequest.setInputStream(is);
System.out.println(String.format("For Chunk %s contentLength %s, contentRange %s, sessionId %s", i, contentLength, range, sessionId));
HttpResponse res = datamanagementAPI.uploadObjsInChunk(uploadObjectRequest, authenticator);
int status = res.getStatusLine().getStatusCode();
}
}
After talking, note that sessionId should be the same for all chunk upload. Otherwise, OSS cannot combine all chunks together.
I have a table that has 45 columns for tax values
| Tax1 | Tax2 | .......... | Tax 44 | Tax45 |
I read in a variable length positional record that can contain zero to 90 values. The record is structured so that the first 3 characters are the tax code (values 001 - 045) and the next 7 characters are the tax value:
Examples:
0010013.990140005.00
0040002.00
0150001.150320002.200410014.250420012.990430000.500440001.750450004.68
What I would like to do is, for each record:
if ISNULL(record) or LEN(record) < 10 (3 characters for the code, 7 characters for the value)
quit
else
determine the amount of 10 character sections
for each 10 character section
taxCode = SUBSTRING(record, 1, 3)
taxValue = SUBSTRING(record, 4, 10)
table.Tax(taxCode).Value = taxValue (ex: using the first example record, column Tax1 will hold a value of 0013.99, Tax14 will be 0005.00)
next section
all other Tax[n] columns will have a value of 0.00
end if
Is there a way to do this without having to create 45 variables, one for each corresponding column?
EDIT:
I apologize for the lack of clarity. I receive a flat file from our VMS database. This file has multiple record types per file (ie: IT01, IT02, IT03, IT04, IT05, IT06, IT07). Each record type is on its own line. I read this file into a staging table, which the record type from the data on the line. For example (this is the record type I am referring to in my question):
IT06404034001005.000031013.000
This gets loaded into my staging table as:
RecordType | RecordData |
------------------------------------------
IT06 | 404034001005.000031013.000
The RecordData field is then able to be broken down further as:
ItemNumber | RecordData |
-------------------------------------
404034 | 001005.000031013.000
With a little bit of up-front work, I was able to create a script task to do exactly as I needed it to.
Step 1: add a script component. set it up as a transformation
Step 2: define all of the output columns necessary (long and tedious task, but it worked)
Step 3: put the following code in the script
public override void Input0_ProcessInputRow(Input0Buffer Row){
int sizeOfDataSegment = 11; // size of single record to be parsed (item number/next price)
string recordDetail = Row.RecordDetail.ToString().Trim();
string itemNumber = recordDetail.Substring(0, 6);
//System.Windows.Forms.MessageBox.Show(String.Format("Record Detail: {0}", recordDetail));
// we need a record for every item number, regardless if there are taxes or not
Row.Company = Variables.strCompanyName;
Row.ItemNumber = itemNumber;
if (recordDetail.Length > 6){
string taxData = recordDetail.Substring(6);
if (string.IsNullOrEmpty(taxData)){
}
else{
if (taxData.Length % sizeOfDataSegment == 0){
int numberOfTaxes = taxData.Length / sizeOfDataSegment;
//System.Windows.Forms.MessageBox.Show(String.Format("Number of taxe codes: {0}", numberOfTaxes.ToString()));
int posTaxCode = 0;
for (int x = 0; x < numberOfTaxes; x++){
string taxCode = taxData.Substring(posTaxCode, 3);
string taxValue = taxData.Substring(posTaxCode + 3, 8);
string outputColumnName = "TaxOut" + Convert.ToInt32(taxCode).ToString();
//System.Windows.Forms.MessageBox.Show(String.Format("TaxCode: {0}" + Environment.NewLine + "TaxValue: {1}", taxCode, taxValue));
//using taxCode value (ie: 001), find and set the value for the corresponding table column (ie: Tax1)
//foreach (System.Reflection.PropertyInfo dataColumn in Row.GetType().GetProperties()){
foreach (System.Reflection.PropertyInfo dataColumn in Row.GetType().GetProperties()){
if (dataColumn.Name == outputColumnName){
if (Convert.ToDecimal(taxValue) < 0){
// taxValue is a negative number, and therefore a percentage value
taxValue = (Convert.ToDecimal(taxValue) * -1).ToString() + "%";
}
else{
// taxValue is a positive number, and therefore a dollar value
taxValue = "$" + Convert.ToDecimal(taxValue).ToString();
}
dataColumn.SetValue(Row, taxValue);
}
}
posTaxCode += sizeOfDataSegment;
}
}
else{
System.Windows.Forms.MessageBox.Show(String.Format("Invalid record length({0}): {1}", taxData.Length, taxData));
}
}
}
}
if I record a series of frequencies beeps into a buffer, for example:
15kHz for 50ms, 17k for 50 ms and goes on, is there any way to "go" along the time plain and to decode this freqs(with goertzel or something)?
Hey, this is an update, I've added a code that shows how I find the first delimiter in the sound buffer that I check. If I record 5 seconds of a buffer(I record into a stream buffer and not a file) The first snippet takes something like 30 seconds to analyze the index where the start delimiter starts at. I thinks it is very newbie...must find a better solution. thanks
(every delimiter is 0.2 seconds duration) and it's like that - Start delimiter = 12KHz, 1's = 13k, 0's = 14k, End delimiter = 15k
double max_power = 0;
int max_power_index = 0;
double DelimiterSamplesCount = SampleRate * DelimiterTime;
float[] samples32array = samples32.ToArray();
//Searching For Delimiter
for (int i = 0; i < (samples32array.Length); i++) //Delimiter Samples Length = SampleRate*DelimiterTimeLength,( i.e: 44100*0.2=8820 samples)
{
if ((i + (int)DelimiterSamplesCount - 1) > samples32array.Length) break;
double power = Goertzel.GoertzelFilter(samples32array, StartDelimiterFreq, i, i + (int)DelimiterSamplesCount - 1);
if(power > max_power)
{
max_power = power;
max_power_index = i;
}
}
My Goertzel is like that:
public static double GoertzelFilter(float[] samples, double freq, int start, int end)
{
double sPrev = 0.0;
double sPrev2 = 0.0;
int i;
double normalizedfreq = freq / 44100;
double coeff = 2 * Math.Cos(2 * Math.PI * normalizedfreq);
for (i = start; i < end; i++)
{
double s = samples[i] + coeff * sPrev - sPrev2;
sPrev2 = sPrev;
sPrev = s;
}
double power = sPrev2 * sPrev2 + sPrev * sPrev - coeff * sPrev * sPrev2;
return power;
}
If you know the set of frequencies and the durations, then a set of sliding Goertzel filters is a good start to building a simple demodulator. Comparing and scanning for for a peak difference between these filters is a better decision criteria than just checking for a certain magnitude output.
i have to handle unique names and save it in db like -
If name already exists, find the smallest number you can append to the name to save it as a unique name.
For example:
If username Scott already exists, save as Scott(1). If Scott(1) already exists, save as Scott(2). Etc.
i am using c# and sql server 2010
any great ideas ?
figured that out - but appreciate improvements
var seprator = "scott";
var list = new List<string>();
list.Add("scott");
list.Add("scott(1)");
list.Add("scott Alex");
list.Add("scott (4)");
list.Add("scott(xxx)");
list.Add("scott(250)");
list.Add("scott(12s)");
list.Add("scott(123)x");
list.Add("Scott caps");
list.Add("Alex Scott caps");
list.Add("xxxscottmmm");
var numberList = new List<int>();
foreach (var v in list)
{
var parts = Regex.Split(v, seprator, RegexOptions.IgnoreCase);
if (parts.Length > 1) //(1) Alex (4) (xxx) (250) (12s) (123)x caps caps
{
var secondPart = parts[1].Trim();
if (secondPart.StartsWith("(") && secondPart.EndsWith(")")) // (1) (4) (xxx) (250) (12s)
{
var valuebetweenbraces = secondPart.Substring(1, secondPart.Length - 2); //1 4 xxx 250 12s
int number;
var isNumber = int.TryParse(valuebetweenbraces, out number);
if (isNumber)
{
numberList.Add(number);
}
}
}
}
int maxValue = 0;
if (numberList.Count > 0)
maxValue = numberList.Max() + 1;
else
maxValue = maxValue + 1;
Response.Write(seprator + "(" + maxValue + ")");