Mql4 I want to plot the data of the previous array - mql4

What I want to do is actually very simple. Create an array and pass any data to that array. Then I want to take the previous data of this array and draw it on the screen, but I cannot access the previous data of the array.
int start()
{
double up[];
int limit;
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for(int i=0; i<limit; i++)
{
up[i] = Close[i]; //I am assigning the closing data to this array as an example.
Line[i] = up[i+1]; //Line array is the name of the array to be displayed on the screen. I want to assign the value of the previous up array to this array but it doesn't work.
}
}

Related

How do I know the content of my 2-D array in MQL4?

I have got an array, s[7][7], I read using a ReadFileString() a CSV file into it, the CSV file contained a set of numbers.
I'm looking for numbers greater than 85, stored in the 2-D array, and the column and row the number/element belongs to.
In order to get content of the array just loop it over:
int value = 85;
for(int i=0; i<ArrayRange(s,0); i++){
for(int j=0; j<ArrayRange(s,1); j++){
if (StrToInteger(s[i][j])>value){
// here you have i and j indexes of array
}
}
}
Of course you can have int array[][] instead of string-s for faster work, use StrToInteger() with ReadFileString() for that.

iOS: Remove NSArray in NSMutableArray in For Loop

This is a pretty simple concept, but I'm not getting the results I'm wanting. I have an NSMutableArray that is populated with NSArrays, I want to loop through that NSMutableArray and remove certain NSArrays based on a key-value pair. My results have many of the NSArrays that I should be removing and I think it has something to do with the count of the NSMutableArray and the int I declare in the For Loop.
Here is my code: (restArray is the NSMutableArray)
for (int i=0; i<restArray.count; i++) {
NSArray *array = restArray[i];
if ([[array valueForKey:#"restaurant_status"] isEqualToString:#"0"]) {
[restArray removeObjectAtIndex:i];
}
}
Does someone know what I am doing wrong here?
It is not recommended to modify an array on what are you currently iterating.
Lets create a tmp array, and reverse your logic.
NSMutableArray * tmpArray = [NSMutableArray array];
for (int i=0; i<restArray.count; i++) {
NSArray *array = restArray[i];
if (![[array valueForKey:#"restaurant_status"] isEqualToString:#"0"] {
[tmpArray addObject:array];
}
}
So at the end of the iteration, you should end up with tmpArray having the arrays you needed.
Use NSPredicate:
NSArray *testArray = #[#{#"restaurant_status" : #"1"}, #{#"restaurant_status" : #"0"}];
NSArray *result = [testArray filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:#"(restaurant_status == %#)", #"1"]];
When you remove an element all the elements past it shift down by one, e.g. If you remove the element at index 3 then the element previously at index 4 moves to index 3.
Every iteration you increase the index by one.
Combine the above two and you see that when you remove an element your code skips examining the following element.
The simple solution is to reverse the order of the iteration:
for (int i = restArray.count - 1; i >= 0; i--)
and then your algorithm will work.
Addendum
You can safely ignore this addendum if your arrays contain < 2^32 elements and you use Clang or GCC (and most other C compilers).
It has been raised in the comments that this answer has a problem if the array has 0 elements in it. Well yes & no...
First note that the code in the question is technically incorrect: count returns an NSUInteger which on a 64-bit machine is a 64-bit unsigned integer, the loop variable i is declared as an int which is 32-bit signed. If the array has more than 2^31-1 elements in it then the loop is incorrect.
Most people don't worry too much about this for some reason ;-) But let's fix it:
for (NSInteger i = restArray.count - 1; i >= 0; i--)
Back to the problem with an empty array: in this case count returns unsigned 0, C standard arithmetic conversions convert the literal 1 to unsigned, the subtraction is done using modular arithmetic, and the result is unsigned 2^64-1.
Now that unsigned value is stored into the signed i. In C converting from signed to unsigned of the same type is defined to be a simple bit-copy. However converting from unsigned to signed is only defined if the value is within range, and implementation defined otherwise.
Now 2^64-1 is greater than the maximum signed integer, 2^32-1, so the result is implementation defined. In practice most compilers, including Clang and GCC, choose to use bit-copy, and the result is signed -1. With this the above code works fine, both the NSInteger and the int (if you've less than 2^32-1 elements in your array) versions.
What the comments raise is how to avoid this implementation-defined behaviour. If this concerns you the following will handle the empty array case correctly with ease:
for (NSUInteger i = restArray.count; i > 0; )
{
i--; // decrement the index
// loop body as before
}
If the array is empty the loop test, i > 0, will fail immediately. If the array is non-empty i, being initialised to the count, will start as one greater than the maximum index and the decrement in the loop will adjust it - effectively in the loop test i contains the number of elements left to process and in the loop body after the decrement contains the index of the next element to process.
Isn't C fun (and mathematically incorrect by definition)!

How to avoid NSMutable array add object values changes before adding object to NSMutable array?

I am new to Objective C. I had used following code.
for (int i = 0; i < [ValueisFound count]; i++)
{
NSString* ObjectName = [NSString stringWithUTF8String:name];
ObjectName = [[NSClassFromString([NSString stringWithUTF8String:samType]) alloc]init];
NSMutableDictionary* jsonDictionary=[TemplateClass SeparateArray:jsonValue_1 key:[arrayofKeys objectAtIndex:j] index:i];
ObjectName = [TemplateClass JsonPharser:str1 jsonObject:jsonDictionary];
NSMutableArray *samArray=[[NSMutableArray alloc]initWithObjects:[TemplateClass JsonPharser:str1 jsonObject:jsonDictionary], nil];
[manoj_Array addObject:samArray];
[samArray release];
[ObjectName release];
}
While executing for loop:
at i=0, Object has value(number=10), now manoj_Array also has (number=10).
at i=1, Object has value(number=12), now manoj_Array has (number=12,number=12).
But i want the result as manoj_Array has (number=10,number=12). I don't know how that array values are changing to last value.
My mind
samArray and manoj_Array is shared the memory Reference Thats why last value is insert to the manoj_Array
i = 0 value is Store by the address of 1000
i = 1 value is Store by the address of 1002
but manoj_Array share the memory so change the Last value is Added to manoj_Array
You can implement KVO in order to know when a value has changed and handle its behaviour.

How to search Equidistant character of a word from a nsmutable array of set of characters

I am new to iOS and need some help.
I am working on a project,
where i need to do a search in a nsmutable array which hold thousands of character which combination of different as well as same characters and i need to do a search of any word and if word found it should be the set equidistant.As a example. Suppose we have set of characters like,
ASDFGFDSRFCGFRDHUJKIHTGRDFESERTGADERWFSGETWGHWGDHWDGWDGOHARHDKHRSGDGHSVDFHDJJDKSKWREFGHUJDMSJDHJGDGAFGREFGSDSGDHHDHAHDJSGAFDHWRODRGKDHDHDGRGFDCVEDDSGDGDHDHNDHJDJSHGD.
and if we search "WORK" from the above set characters. Then it should show the results as darken the area above.
Distance between the word is 2.
Distance between the word is 1.
Rahul,I come upto this,go further developing and compairing.
This may help you:
NSString *characterstring=#"ASDFGFDSRFCGFRDHUJKIHTGRDFESERTGADERWFSGETWGHWGDHWDGWDGOHARHDKHRSGDGHSVDFHDJJDKSKWREFGHUJDMSJDHJGDGAFGREFGSDSGDHHDHAHDJSGAFDHWRODRGKDHDHDGRGFDCVEDDSGDGDHDHNDHJDJSHGD";
NSString *cmpString=#"WORK";
int s;
int p;
for (int j=0; j<cmpString.length; j++) {
for (int i=0; i<characterstring.length; i++) {
char b=[characterstring characterAtIndex:i];
if(b ==[cmpString characterAtIndex:j])
{
s=i;
}
if (j<cmpString.length-1) {
if(b ==[cmpString characterAtIndex:j+1])
{
p=i;
if (i+(p-s)<characterstring.length-1) {
if([characterstring characterAtIndex:i+(p-s)] ==[cmpString characterAtIndex:j])
{
p=i;
NSLog(#"[characterstring characterAtIndex:i+(p-s)]=%c",[characterstring characterAtIndex:i+(p-s)]);
}
}
NSLog(#"====%c",b);
}
}
}
}

iOS, sorting through two arrays with different counts simultaneously

I am getting an NSRangeException error when test an array's contents (arrayTwo) inside another array enumeration (arrayOne), if arrayTwo does not have a count equal or greater to arrayOne. What is the most efficient way to do this? Basically I want to grab the object from arrayTwo if it exists, else if there is no object there, just ignore the operation.
int i = 0;
for (Class *arrayOneObject in arrayOne) {
if (arrayTwo[i]!= NULL) {
NSLog(#"array two object found");
}
i++;
}
Edit: According to Hot Lick's suggestion, I did the following, works fine.
int i = 0;
for (Class *arrayOneObject in arrayOne) {
if (arrayTwo.count > i) {
NSLog(#"array two object found");
}
i++;
}

Resources