When using OrderSelect() in mql4, are the orders ordered according to the ticket number by default? My intention is to use OrderModify() on orders starting from the first that was opened to the most recent.
Never assume anything in MQL unless it's explicitly specified in the documentation. That said, you'll need to sort your ticket numbers before iterating them in order.
CArrayInt tickets;
for(int i=0; OrderSelect(i, SELECT_BY_POS); i++)
tickets.Add(OrderTicket());
tickets.Sort();
for(int i=0; i<tickets.Total(); i++)
if(OrderSelect(tickets[i], SELECT_BY_TICKET))
...
`enter code here`
int Magic = 12345;
// This reads the orders LIFO (last in...)
// the index is an integer and is incremented from 0
// as the orders are placed. It is NOT
// the ticket number. No sorting necessary.
for(int i=OrdersTotal()-1;i>=0;i--)
if(_Symbol=OrderSymbol() && Magic = OrderMagicNumber())
if(OrderSelect(i, SELECT_BY_POS) {
Print("Order Index: ",i,", Ticket: ",OrderTicket());
You cannot call OrderSelect() function without parameters. You must specify id and the way the orders are selected. If you know an ID of the order, as it is seen it MT4 terminal window, you can call OrderSelect( order_id, SELECT_BY_TICKET), if you dont know or in case you loop over history trades you have to apply OrderSelect(i,SELECT_BY_POS) or OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) where i is integer between 0 and OrdersTotal() or OrdersHistoryTotal() respectfully.
If you loop over the array of trades with i as an integer, you are strongly advised to loop from the maximum value to zero (and not vice versa), and you can obtain ticket id by calling OrderTicket() function after OrderSelect(*,*[,MODE_HISTORY]) is successful.
Related
I am just writing up the API and implementation spec and I was thinking of using Spring Data JPA to handle the paging of the results. The Page class already contains information I need which is the total number of records for the whole collection but I want to avoid loading the all the records in the page into memory.
You can load all data in smaller chunks.
First of all you need to have count of the whole data.
long count = (your_count_query)
Then make a total page according to the count.
bulkSize is the value you want each page to contain. f.e 10,000
int totalPage = (int) Math.ceil(count * 1.0 / bulkSize);
And finally get result through the loop.
for (int i = 0; i < totalPage; i++) {
Pageable currentPageable = PageRequest.of(i, bulkSize, Sort.by("some_property"));
Page<Object> page= repository.findPage(currentPageable);
}
What is the use of [i] in below program Xcode?
for (unsigned short int i=0; i<100; i++) {
NSLog(#"Top iOS Apps %i in App store is - %# released on - %#",i,appStore100Apps[#"feed"][#"results"][i][#"name"],appStore100Apps[#"feed"][#"results"][i][#"releaseDate"]);
}
The for loop goes through the first 100 elements in the array, and i acts as the counter when iterating through the loop, and accesses the ith result in the app store feed specifically via index subscripting on the array of results
[i] will increase when the loop goes. It will get each record of appStore100Apps until it hits 100.
I have an array of core data objects called samples, each sample has a depthFrom and depthToo. I load each sample into a tableView to show the depthFrom and Too. I need to check for gaps between the values and if there is, insert a new sample.
The samples in the table could look like below with depthFrom and depthToo,
The issue is since there is a gap between the numbers from 100 to 210 new samples should be added to the table. using a gap of 50 as much as possible so it would look like this with the auto generated samples.
What im unsure of is how to compare the values, i would rather do it as the view loads before cellForRowAtIndexPath is called so i would not need to reload the table again. I was thinking of looping through each value and comparing them but there all in the same array so im not sure how i would do this. I have all the data displaying correctly in my app its just the gaps i need to account for and if im able to find a way to compare the values in the array then i can manage adding in the new objects i just need pointing in the right direction as this is new to me.
If theres anything about my question that is confusing then just add a comment and i will update it accordingly, thanks for any help.
To fix the gaps, you must keep track of the last depthTo and check if there's a gap between it and the current sample. If there is, insert samples with a spacing of 50*, until we reach our current sample.
Here's a pseudocode solution:
samples = NSMutableArray
int lastDepthTo = 0;
for (i = 0; i < [samples count]; i++) {
s = samples[i]
// add missing samples (upto current s.depthFrom)
while (s.depthFrom > lastDepthTo) {
genDepthTo = MIN(d.depthFrom, lastDepthTo+50)
generated = new sample(depthFrom: lastDepthTo, depthTo: genDepthTo)
[samples insert:generated atIndex:i]
i++ // increment i to skip inserted sample
lastDepthTo = genDepthTo
}
lastDepthTo = s.depthTo
}
Note: this is untested, maybe off by 1 for the indexing of i.
I'm manipulating entries inside a DoubleLinkedQueue via the DoubleLinkedQueueElement.append/prepend methods. This results in the new elements being inserted into the queue, but fails to update the length, and the toList() method results in an error being thrown.
I understand queues are only supposed to have elements added at the start/end, but it looks like the interface should allow for adding in the middle via the entries. I find it hard to believe such a common/well understood data structure would have a bug at this point - so am I using DoubleLinkedQueues incorrectly? Is there another data structure that I should be using? I'm looking to merge values from another iterable into my own sorted iterable - a SplayTreeSet might get me there in n log n time, but a simple merge should get me there in linear time...
Example of code that acts unexpectedly:
main() {
var q = new DoubleLinkedQueue<int>.from([1]);
q.firstEntry().prepend(0);
print('length: ${q.length}');
int i = 0;
for (var qi in q){
print('${i++}: $qi');
}
}
Output:
length: 1
0: 0
1: 1
It looks like the length getter is only pointing to an internal counter. This is done because counting the elements everytime might take very long for long lists.
The internal counter is only updated if you use the methods that directly operate on the list instead of using the prepend method of an element. In your example you should use q.addFirst(0); which results in the length being updates. The .prepend() method just inserts a new element and changes the pointer. Which results in correct traversation of the elements, but the counter is wrong anyway.
Unfortunately it looks like you cannot insert elements in the middle of the list, nor can you make the list recount the elements. You should consider creating a bug over at www.dartbug.com.
// Update:
toList() throws an error because there are more elements than length.
I know of:
http://lua-users.org/wiki/SimpleLuaApiExample
It shows me how to build up a table (key, value) pair entry by entry.
Suppose instead, I want to build a gigantic table (say something a 1000 entry table, where both key & value are strings), is there a fast way to do this in lua (rather than 4 func calls per entry:
push
key
value
rawset
What you have written is the fast way to solve this problem. Lua tables are brilliantly engineered, and fast enough that there is no need for some kind of bogus "hint" to say "I expect this table to grow to contain 1000 elements."
For string keys, you can use lua_setfield.
Unfortunately, for associative tables (string keys, non-consecutive-integer keys), no, there is not.
For array-type tables (where the regular 1...N integer indexing is being used), there are some performance-optimized functions, lua_rawgeti and lua_rawseti: http://www.lua.org/pil/27.1.html
You can use createtable to create a table that already has the required number of slots. However, after that, there is no way to do it faster other than
for(int i = 0; i < 1000; i++) {
lua_push... // key
lua_push... // value
lua_rawset(L, tableindex);
}