I am trying to get the highest and lowest value from last 20 bar. I have no issue to obtaining highest value, however my code doesn't seem to work properly in order to obtain the lowest value. Just wondering if there is any suggestion about it.
OnEveryNewBar1();
void OnEveryNewBar1()
{ PipValue = 1;
if ( NDigits == 3 || NDigits == 5 ) PipValue = 10;
if ( BarTime1 < Time[0] ) // we have a new bar opened
{ BarTime1 = Time[0]; // keep the new bar open time
TechnicalAnalysis_S();
TechnicalAnalysis_L();
}
}
void TechnicalAnalysis_S()
{
int m = 2;
int n = 3;
l = 1000;
while ( m <= 20 )
{
if ( 1 < 2 )
{ if ( ( Close[2] > Open[2] ) || ( Close[1] > Open[1] ) ) int i = 2;
while ( i > 0 )
{
if ( Low[i] < l ) l = Low[i];
i = i - 1;
}
print ( "Lowest" + l );
l = 1000;
}
m++;
n++;
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void TechnicalAnalysis_L()
{
int m = 2;
int n = 3;
while ( m <= 20 )
{
if ( 2 > 0 )
{
if ( ( Close[2] < Open[2] ) || ( Close[1] < Open[1] ) ) int i=2;
while ( i > 0 )
{
if ( High[i] > h ) h = High[i];
i = i - 1;
}
print ( "Highest" + h );
h = 0;
}
m++;
n++;
}
}
While there are some strange parts in the code, while some variables are missing their declaration, the language has built-in functions for this.
Solution:
double aLowestLOW_InTheLast20BARs,
aHighestHIGH_InTheLast20BARs;
// -----------------------------------------------------------------------------
aLowestLOW_InTheLast20BARs = Low[iLowest( _Symbol, // .self
PERIOD_CURRENT, // .self
MODE_LOW, // LOW
20, // Last 20 BARs
0 // from [0]
)
];
// -----------------------------------------------------------------------------
aHighestHIGH_InTheLast20BARs = High[iHighest( _Symbol, // .self
PERIOD_CURRENT, // .self
MODE_HIGH, // HIGH
20, // Last 20 BARs
0 // from [0]
)
];
Related
I'm trying to write a function that copies all of the values in source1 which are also found in source2 into a destination and then returns the number of elements copied into the destination.
int common_elements(int length, int source1[length], int source2[length], int destination[length])
{
int counter = 0;
int i = 0;
while (i < length) {
int j = 0;
while (j < length) {
if ( source1[i] == source2[j]) {
destination[counter] = source1[i];
counter++;
}
j++;
}
i++;
}
return counter;
}
The problem is e.g. given (common_elements(5, {1,2,3,4,5}, {1,2,3,2,1}, [])), the correct input should be
1,2,3
return value: 3
However, the program is accounting for the duplicates and produces :
1,1,2,2,3
return value: 5
which is incorrect.
How can I remedy this?
In this while loop
int j = 0;
while (j < length) {
if ( source1[i] == source2[j]) {
destination[counter] = source1[i];
counter++;
}
j++;
}
you are counting all elements in the array source2 that are equal to the element source1[i].
I can suggest the following solution provided that the source arrays may not be changed within the function.
#include <stdio.h>
size_t common_elements( int destination[],
const int source1[],
const int source2[],
size_t n )
{
size_t counter = 0;
for ( size_t i = 0; i < n; i++ )
{
size_t number = 1;
for ( size_t j = 0; j < i; j++ )
{
if ( source1[i] == source1[j] ) ++number;
}
for ( size_t j = 0; number && j < n; j++ )
{
if ( source1[i] == source2[j] ) --number;
}
if ( number == 0 ) destination[counter++] = source1[i];
}
return counter;
}
int main(void)
{
enum { N = 5 };
int source1[N] = { 1, 2, 3, 4, 5 };
int source2[N] = { 1, 2, 3, 2, 1 };
int destination[N];
size_t n = common_elements( destination, source1, source2, N );
for ( size_t i = 0; i < n; i++ )
{
printf( "%d ", destination[i] );
}
putchar( '\n' );
return 0;
}
The program output is
1 2 3
Edit by kriegaex: This question is about yaw rotation as opposed to pitch or roll.
So, X = y = z = 0 - mins {105.0, -75.0, 0.0}, maxs {225.0, -15.0, 50.0}
So, that's what im doing (it's wrong, or it's just AABB calculating instead needed stuff).
float fMins[3]; float fMaxs[3];
float yaw = angles2[1] * (3.14 / 180.0);
float xvector[3]; float yvector[3];
xvector[0] = floatcos(yaw);
xvector[1] = floatsin(yaw);
yvector[0] = -floatsin(yaw);
yvector[1] = floatcos(yaw);
float rmin[3] = { 9999.0, 9999.0, 9999.0 };
float rmax[3] = { -9999.0, -9999.0, -9999.0 };
float base[3];
float transformed[3];
for (int i = 0; i <= 1; i++) {
base[0] = i == 0 ? mins[0] : maxs[0];
for (int j = 0; j <= 1; j++) {
base[1] = j == 0 ? mins[1] : maxs[1];
for (int k = 0; k <= 1; k++) {
base[2] = k == 0 ? mins[2] : maxs[2];
transformed[0] = xvector[0]*base[0] + yvector[0]*base[1];
transformed[1] = xvector[1]*base[0] + yvector[1]*base[1];
transformed[2] = base[2];
/*
if (transformed[0] < rmin[0]) rmin[0] = transformed[0];
if (transformed[0] > rmax[0]) rmax[0] = transformed[0];
if (transformed[1] < rmin[1]) rmin[1] = transformed[1];
if (transformed[1] > rmax[1]) rmax[1] = transformed[1];
if (transformed[2] < rmin[2]) rmin[2] = transformed[2];
if (transformed[2] > rmax[2]) rmax[2] = transformed[2];
*/
for (int l = 0; l < 3; l++) {
if (transformed[l] < rmin[l]) rmin[l] = transformed[l];
if (transformed[l] > rmax[l]) rmax[l] = transformed[l];
}
}
}
}
fMins[0] = rmin[0]; fMaxs[0] = rmax[0];
fMins[1] = rmin[1]; fMaxs[1] = rmax[1];
fMins[2] = rmin[2]; fMaxs[2] = rmax[2];
fMins[0] += origin2[0];
fMins[1] += origin2[1];
fMins[2] += origin2[2];
fMaxs[0] += origin2[0];
fMaxs[1] += origin2[1];
fMaxs[2] += origin2[2];
So, on 0 0 0 angle's mins maxs are {105.0, -75.0, 0.0} and {225.0, -15.0, 50.0}.
How i can calculate same sizes on 0 53 0 angles?
I need same sized box, just equalent. Only mins/maxs based solutions.
I'm learning C and currently i'm trying to make a shell. Anyway i made a test program to figure out how multiple pipes work. I changed the program to use a single pipe command and it prints the result fine. Then i changed it back to this code where that runs it for 2 pipes, but i always get output 0. I really have no clue why the output is 0. Can you help me?
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <fcntl.h>
int main(int argc, char * argv[])
{
int j;
pid_t pid;
int pfd[4];
char * ls[] = {"ls","-l",0};
char * sort[] = {"sort","-u",0};
char * wc[] = {"wc","-l",0};
int fd = open("outputfolder.txt", O_WRONLY | O_CREAT | O_APPEND);
for ( int i = 0; i < 4; i++ )
{
if ( pipe(pfd + i*2) < 0 )
{
perror("pipe\n");
exit(EXIT_FAILURE);
}
}
for ( int i = 0; i <= 2; i ++ )
{
if ( i == 2 )
{
pid = fork();
if ( pid == 0 )
{
if ( dup2(pfd[(i-1)*2],0) < 0 )
{
perror("dup2\n");
exit(EXIT_FAILURE);
}
if ( dup2(fd,1) < 0 )
{
perror("dup2\n");
exit(EXIT_FAILURE);
}
for (j = 0; j < 4; j++ )
{
close(pfd[j]);
}
if ( execvp(wc[0],wc) < 0 )
{
perror("execvpwc\n");
exit(EXIT_FAILURE);
}
}
else if ( pid == -1 )
{
perror("fork\n");
exit(EXIT_FAILURE);
}
}
else if ( i != 2 )
{
pid = fork();
if ( pid == 0 )
{
if ( i != 0 )
{
if ( dup2(pfd[(i-1)*2],0) < 0 )
{
perror("dup2\n");
exit(EXIT_FAILURE);
}
}
if ( dup2(pfd[i*2+1],1) < 0 )
{
perror("dup2\n");
exit(EXIT_FAILURE);
}
for ( j = 0; j < 4; j++ )
{
close(pfd[j]);
}
if (i == 0)
{
if ( execvp(ls[0],ls) < 0 )
{
perror("execvpls\n");
exit(EXIT_FAILURE);
}
}
else if ( i == 1 )
{
if ( execvp(sort[0],sort) < 0 )
{
perror("execvpsort\n");
exit(EXIT_FAILURE);
}
}
}
else if ( pid == -1 )
{
perror("fork\n");
exit(EXIT_FAILURE);
}
}
}
for ( j = 0; j < 4; j++ )
{
close(pfd[j]);
}
while(waitpid(0,0,0)>=0);
return 0;
}
EDIT: The number that it should print should be 19 for my directory
I'm trying to write a function that restores the heap property . But all the time I come out bad results .
void fixHeap(int heapSize, struct Edge* edgeArray, int i){//edgeArray is our heap-array.
int leftSon = leftSonIndex(i);
int rightSon = rightSonIndex(i);
int change;
if((leftSon <= heapSize) && (edgeArray[i].cost < edgeArray[leftSon].cost)){
change = leftSon;
}else{
change = i;
if((rightSon <= heapSize) && (edgeArray[change].cost < edgeArray[rightSon].cost)){
change = rightSon;
}
}
if(change != i){
swap(edgeArray, i, change);
i = change;
fixHeap(heapSize, edgeArray, i);
}
}
The problem is that if you choose the leftSon as the change in the first if block, then you don't compare it with rightSon to check if rightSon > leftSon.
Hence your example would fail in cases like this -:
5
/ \
6 7
This is how it should be -:
void fixHeap( int heapSize, struct Edge* edgeArray, int i ) //edgeArray is our heap-array.
{
int leftSon = leftSonIndex( i );
int rightSon = rightSonIndex( i );
int change = i;
if ( ( leftSon <= heapSize ) && ( edgeArray[change].cost < edgeArray[leftSon].cost ) )
{
change = leftSon;
}
if ( ( rightSon <= heapSize ) && ( edgeArray[change].cost < edgeArray[rightSon].cost ) )
{
change = rightSon;
}
if ( change != i )
{
swap( edgeArray, i, change );
fixHeap( heapSize, edgeArray, change );
}
}
struct node* tempA;
struct node* tempB;
n = 501;
m = 501;
tempA = A;
tempB = B;
while ( tempA != NULL && tempB != NULL )
{
if ( tempA->data == tempB->data )
{
int common = tempA->data;
if (fastintersect(common+n,block,closed_area)||fastintersect(common-n,block,closed_area)||(fastintersect(common-1,block,closed_area) && common%n != 1)||(fastintersect(common+1,block,closed_area) && common%n != 0 ))
{
AppendNode(&C,common);
tempA = tempA->next;
tempB = tempB->next;
if( search(A,common) != length(A) )
{
DeleteNode(&A,common);
}
else
{
DeleteEndNode(A);
}
if( search(B,common) != length(B) )
{
DeleteNode(&B,common);
}
else
{
DeleteEndNode(B);
}
}
else
{
tempA = tempA->next ;
tempB = tempB->next ;
}
}
else if ( tempA->data > tempB->data )
tempB = tempB->next;
else
tempA = tempA->next;
}
// The fastintersect function
int fastintersect(int x,int arr[],int sizearr)
{
int found = 0;
int lower = 0;
int upper = sizearr - 1 ;int i=0;
if( (x == arr[lower]) || (x == arr[upper]) )
{
found = 1;
}
else if ( x > arr[lower] && x < arr[upper])
{
while ( lower <= upper )
{
int middle = ( lower + upper ) / 2;
if ( x > arr[middle])
{ lower = middle +1 ;}
else if (x < arr[middle])
{upper = middle - 1;}
else
{ found = 1;break;}
}
}
return found;
}
This is a function to delete the common elements of 2 sorted linked lists A and B . When there are common elements the fastintersect criterion is checked and corresponding elements are deleted and new linked list C is generated whose elements are the ones which satisfy the common elements criteria as well as the fastintersect check .Block is just a matrix which has some values against which the common is checked and if present will return a value 1 else 0. Am I doing the deleting correctly ? Is this a valid code ?