How to check which 1 is the oldest object or price? - mql4

On the picture above, blue horizontal line object is the oldest object, how to get it?
something like :
if (blue < yellow) && (blue < pink) && (blue < red)) { printf ("blue is the oldest object"); }
Do I need to use ibarshift? May I have example of code?

string oldestObjectName="", name;
datetime oldestObjectDate=INT_MAX, tmpDate;
for(int i=ObjectsTotal()-1;i>=0;i--)
{
name=ObjectName(i);
tmpDate=ObjectGetInteger(0,name,OBJPROP_TIME1);
if(tmpDate<oldestObjectDate)
{
oldestObjectDate=tmpDate;
oldestObjectName=name;
}
}
printf("oldest object is %s, its time1=%s",oldestObjectName,TimeToString(oldestObjectDate));

Related

Determining context at a position in file using ANTLR4

I'm trying to write a Language Extension for VS Code in JavaScript and I seem to be missing something.
I have a Lexer.g4 and Parser.g4 for my language and can generate a tree using them.
My issue is that the VS Code API gives me a document and a position in that document (line #, character #). From any of the examples I've looked at for ANTLR4 I can't seem to find any functions generated that take a position in the file and give back the nodes of a tree at that position.
I want to know, for example that the cursor is placed on the name of a function.
Am I supposed to be walking the entire tree and checking the position of tokens to see if they enclose the position I'm in in the editor? Or maybe I'm not using the right tool for the job? I feel like I'm probably missing something more fundamental.
Yes, you have to walk the parse tree to find the context at a given position. This is a pretty simple task and you can see it in action in my ANLTR4 exension for vscode. There are multiple functions returning something useful for a given position. For instance this one:
/**
* Returns the parse tree which covers the given position or undefined if none could be found.
*/
function parseTreeFromPosition(root: ParseTree, column: number, row: number): ParseTree | undefined {
// Does the root node actually contain the position? If not we don't need to look further.
if (root instanceof TerminalNode) {
let terminal = (root as TerminalNode);
let token = terminal.symbol;
if (token.line != row)
return undefined;
let tokenStop = token.charPositionInLine + (token.stopIndex - token.startIndex + 1);
if (token.charPositionInLine <= column && tokenStop >= column) {
return terminal;
}
return undefined;
} else {
let context = (root as ParserRuleContext);
if (!context.start || !context.stop) { // Invalid tree?
return undefined;
}
if (context.start.line > row || (context.start.line == row && column < context.start.charPositionInLine)) {
return undefined;
}
let tokenStop = context.stop.charPositionInLine + (context.stop.stopIndex - context.stop.startIndex + 1);
if (context.stop.line < row || (context.stop.line == row && tokenStop < column)) {
return undefined;
}
if (context.children) {
for (let child of context.children) {
let result = parseTreeFromPosition(child, column, row);
if (result) {
return result;
}
}
}
return context;
}
}

how to Recreate boundary from array of junctions in imagej - fiji?

I am detecting and storing the boundary of a sandpile to an array and then save it as a text file for later use. the way i stored the boundary as text file is by using the wand tool, then getting the properties of the selection which gives me a table. Then converting table to array and finally storing it as text file.
after doing so i noticed that the above mentioned table only has the (X,Y) coordinates of the "junctions" on the boundary and not every pixel of the boundary.
Now when i say later use, i want to smooth out the boundary with various methods and redraw it but i am stuck at how to go from junctions to complete boundary. Below is my attempt to do it but i am seeing heavy ram usage just after the output is printed.
Thanks for any help and your time.
X=newArray(1,5,5,10);
Y=newArray(3,3,8,8);
c=newArray("c1","c2");
//answer should be g=(1,2,3,4,5,5,5,5,5,5,6,7,8,9,10, --x part
// 3,3,3,3,3,4,5,6,7,8,8,8,8,8,8) --y part
//f=slide(a,2,c);Array.print(f);
g=cmpltarray(X,Y);Array.print(g);
function cmpltarray(Tx,Ty){
for (i = 0; i < Tx.length-1; i++) {
if(Tx[i]==Tx[i+1] && Ty[i]!=Ty[i+1])
{
l=abs(Ty[i]-Ty[i+1])-1;tempy=newArray(l);tempx=newArray(l);
for (j = 0; j < l; j++) {
tempy[j]=Ty[i]+j+1;tempx[j]=Tx[i];
}
Tx=slide(Tx,(i+1),tempx);Ty=slide(Ty,(i+1),tempy);i=i+l;
}
if(Ty[i]==Ty[i+1] && Tx[i]!=Tx[i+1])
{
l=abs(Tx[i]-Tx[i+1])-1;tempy=newArray(l);tempx=newArray(l);
for (j = 0; j < l; j++) {
tempx[j]=Tx[i]+j+1;tempy[j]=Ty[i];
}
Tx=slide(Tx,(i+1),tempx);Ty=slide(Ty,(i+1),tempy);i=i+l;
}
}
return Array.concat(Tx,Ty);
}
function slide(array,n,data){
array=Array.concat(Array.slice(array,0,n),data,Array.slice(array,n,array.length));
return array;
}

Creating an app that defines a set of data based on several criteria

I'm trying to create an iPhone app that takes the user's response to four criteria and, based on that, shows a specific set of data related to that permutation of answers. For example, in the main view controller:
User selects A or B in a segmented controller (let's say they choose A)
User selects C or D in a segmented controller (they choose D)
User selects E or F in a segmented controller (they choose E)
User inputs an age in a text box (they type in 37)
User touches the "Get Numbers" button
Based on the combination of "A, D, E, 37", the view that appears on the touch of "Get Numbers" shows an image overlaid with seven labels containing the numbers 17.1, 14.2, 30.0, 60.4, 18.1, 19.7 and 80.2. If the user had selected a different set of responses on the main controller, a different set of numbers would appear in those same labels.
I've researched the various elements, but I can't figure out how to combine them to produce the desired outcome. How can I do this? Any advice would be much appreciated--I'm quite new to xCode and completely stuck.
Thanks
I do not actually program in Xcode or Objective-C, but it seems to me that you are looking for a CASE statement. I found the following links, I hope they help:
the best way to implement readable switch case with strings in objective-c?
http://www.techotopia.com/index.php/The_Objective-C_switch_Statement
Based on your question, this is all contained in one viewController so you shouldn't need to pass a bunch of properties. The hard part is knowing how you are attempting to mutate the values and how much branching needs to happen. Also, you have 7 return values and there's no way of knowing how to compute these, like if the output from the first response is calculated with the second and third responses, etc.
EDIT, after reading your comment:
There are 8 possible outcomes, maybe you can create 8 methods to deal with each one. I can't think of any other way, but correct me if I'm wrong:
Possible values:
{
(A,C,E) ;
(B,C,E) ;
(A,D,E) ;
(B,D,E) ;
(A,C,F) ;
(B,C,F) ;
(A,D,F) ;
(B,D,F) ;
}
//Do it with an IF statement:
//first capture state into BOOL values
BOOL a = NO;
BOOL c = NO;
BOOL e = NO;
if (abSegment.selectedSegmentIndex == 0) { a = YES; }
if (cdSegment.selectedSegmentIndex == 0) { c = YES; }
if (efSegment.selectedSegmentIndex == 0) { e = YES; }
//next do some matching with IF statements
if (a && c && e) {
//do something for A,C,E
}
if (!a && c && e) {
//do something for B,C,E
}
if (a && !c && e) {
//do something for A,D,E
}
if (!a && !c && e) {
//do something for B,D,E
}
if (a && c && !e) {
//do something for A,C,F
}
if (!a && c && !e) {
//do something for B,C,F
}
if (a && !c && !e) {
//do something for A,D,F
}
if (!a && !c && !e) {
//do something for B,D,F
}
If you have hardcoded values you can just write the label updating text inside each IF block that matches your requirements. It's hacky but it's all I can think of right now

Google script, manipulate the number value

I have one script behind one spreedsheet and I'm trying to export some cell values to document, and than email the pdv version of temp document..(trash it latter). I have problem with value I get or in the way I'm getting the value from spreedsheet to doc.. I can't manipulate the decimal point..
// fix the price currency display and alignment in GOOGLE DOCUMENT TABLE!
for (var i = 0; i < price.getNumRows(); i++){
for (var j = 0; j < price.getRow(i).getNumCells(); j++){
var temp = price.getCell(i, j);
temp.getChild(0).asParagraph().setSpacingAfter(0);
if((j == 6 || j == 7) && !temp.getText() == "" ) {
(i > 0) ? temp.replaceText(temp.getText(), temp.getText() + " kn") : void false; // skip the first line with header titles...
temp.getChild(0).asParagraph().setAlignment(DocumentApp.HorizontalAlignment.RIGHT);
}
}
}
after (i > 0) there is temp.getText() value.. that sometimes is like: 55,987654 and I would like that to round to two digits.. but can't :(
Thanks for help!
I have found solution..
it's very simple but did take me some time.. hope that can help someone else with similar situation
parseFloat(temp.getText()).toFixed(2) + " kn")
this did the trick and the output is something like: 55,99 kn!

Getting the index of an array element of EDT Dimension

I need to write a job where i could fetch the index of an array element of EDT Dimension
e.g. In my EDT Dimension i have array elements A B C when i click over them for properties I see the index for A as 1, B as 2 and C as 3. Now with a job ui want to fetch the index value. Kindly Assist.
I'm not sure if I did understand the real problem. Some code sample could help.
The Dimensions Table has some useful methods like arrayIdx2Code.
Maybe the following code helps:
static void Job1(Args _args)
{
Counter idx;
Dimension dimension;
DimensionCode dimensionCode;
str name;
;
for (idx = 1; idx <= dimof(dimension); idx++)
{
dimensionCode = Dimensions::arrayIdx2Code(idx);
name = enum2str(dimensionCode);
// if (name == 'B') ...
info(strfmt("%1: %2", idx, name));
}
}
I found a way but still looking if there is any other solution.
static void Job10(Args _args)
{
Dicttype dicttype;
counter i;
str test;
;
test = "Client";
dicttype = new dicttype(132);//132 here is the id of edt dimension
for (i=1;i<=dicttype.arraySize();i++)
{
if ( dicttype.label(i) == test)
{
break;
}
}
print i;
pause;
}
Array elements A B C from your example are nothing else but simple labels - they cannot be used as identifiers. First of all, for user convenience the labels can be modified anytime, then even if they aren't, the labels are different in different languages, and so on and so forth.
Overall your approach (querying DictType) would be correct but I cannot think of any scenario that would actually require such a code.
If you clarified your business requirements someone could come up with a better solution.

Resources