<solved>Can't successfully call a function which has a structure as input

 

Hi,

I have recently started learning coding and can't seem to figure the right way to call the function listed below (the code below is not completed).

Using this code, the function at the bottom lists no errors. However, when calling it in the OnTick block, many many errors start coming up.

Ideally, after calling the function we should have all the values for each fib level.

I'm sure I've made a stupid mistake, which should be easy to spot by experienced coders.


Alternatively, i plan to do the calculations manually (without a function), and have them stored as global variables instead.

Would appreciate any help/ feedback!


//variables
int pX = 1; //bar locations
int pA = 1;
int pB = 1;
int pC = 1;
int pD = 1;

double highX, highA, highB, highC, highD;
double lowX, lowA, lowB, lowC, lowD;

datetime currentBarTime; //for updates
bool update;


void OnTick()
{
   //current time
   if(currentBarTime != iTime(NULL,0,1))
   {
      currentBarTime = iTime(NULL,0,1);
      update = True;
   }
   else update = False;
   
   //identifying peaks and troughs
   //pX
   if(iLow(NULL,0,pX) > iLow(NULL,0,1))
   {
      pX = 1;
      highX = iHigh(NULL,0,pX);
      lowX = iLow(NULL,0,pX);
   }
   else if(update = True)
      pX += 1;
   
   //pA
   if(iHigh(NULL,0,1) > iHigh(NULL,0,pX) && iHigh(NULL,0,1) > iHigh(NULL,0,pA))
   {
      pA = 1;
      highA = iHigh(NULL,0,pA);
      lowA = iLow(NULL,0,pA);
   }
   else if(update = True)
      pA += 1;
   
   //pB
   if(iLow(NULL,0,pB) > iLow(NULL,0,1) && iLow(NULL,0,1) < iLow(NULL,0,pA))
   {
      pB = 1;
      highB = iHigh(NULL,0,pB);
      lowB = iLow(NULL,0,pB);

      if(iClose(NULL,0,pX)>iClose(NULL,0,pA)) //PROBLEM IS HERE
         FibLevel(highX, lowA, fibLevels);
      else
         FibLevel(lowX, highA, fiblevel);
   }
}

//structure
struct fibLevels
{
   double retrace382;
   double retrace500;
   double retrace618;
   double retrace786;
   double retrace886;
   double extension618;
   double extension1000;
   double extension1272;
   double extension1618;
};

//fib function
void FibLevel(double price1, double price2, fibLevels &fiblevel)
{
   double range = MathAbs(price1 - price2);
   fiblevel.retrace382=(price1<price2)?price2-range*0.382:price2+range*0.382;
   fiblevel.retrace500=(price1<price2)?price2-range*0.500:price2+range*0.500;
   fiblevel.retrace618=(price1<price2)?price2-range*0.618:price2+range*0.618;
   fiblevel.retrace786=(price1<price2)?price2-range*0.786:price2+range*0.786;
   fiblevel.retrace886=(price1<price2)?price2-range*0.886:price2+range*0.886;
   fiblevel.extension618=(price1<price2)?price2+range*0.618:price2-range*0.618;
   fiblevel.extension1000=(price1<price2)?price2+range*1.00:price2-range*1.00;
   fiblevel.extension1272=(price1<price2)?price2+range*1.272:price2-range*1.272;
   fiblevel.extension1618=(price1<price2)?price2+range*1.618:price2-range*1.618;
}
 

An object has to be passed as parameter.

//structure
struct fibLevels
{
   double retrace382;
   double retrace500;
   double retrace618;
   double retrace786;
   double retrace886;
   double extension618;
   double extension1000;
   double extension1272;
   double extension1618;
}fiblvls;

      if(iClose(NULL,0,pX)>iClose(NULL,0,pA)) //PROBLEM IS HERE
         FibLevel(highX, lowA, fiblvls);
      else
         FibLevel(lowX, highA, fiblvls);
 
Ernst Van Der Merwe:

An object has to be passed as parameter.

Thank you!! your edit works like a charm
 
         FibLevel(highX, lowA, fibLevels);
⋮
//structure
struct fibLevels{…};

Struct fibLevels is a definition — think of it as double. FibLevel(highX, lowA, double) makes no sense.

Create a variable of that type and you can pass that. struct fibLevels fiblvls; FibLevel(highX, lowA, fiblvls)

 
William Roeder:

Struct fibLevels is a definition — think of it as double. FibLevel(highX, lowA, double) makes no sense.

Create a variable of that type and you can pass that. struct fibLevels fiblvls; FibLevel(highX, lowA, fiblvls)


wow, thank you! Your explanation is really helpful for a beginner like me (:

Much appreciated sir
Reason: