Mathematical Functions

Back to topics list To post a new topic, please log in or register
avatar
86
fly7680 2016.09.15 11:21
 
Hello, I performed a series of calculations to arrive at a final percentage. The code has no errors but the calculation does not work.

example:

Total excursion Body candle = 36 tenths
Total
excursion shadows      = 11 tenths
mathematical expression (100 * 11) / 36 = 30.55%

Can you help me?

Thank you


bool c1 = Open[1+i] < Close[1+i] && MathAbs(Close[1+i]-Open[1+i]) > 2  * myPoint;
bool c2 = MathAbs (High [1+i] - Close[1+i]); //shadow up                          
bool c3 = MathAbs (Open [1+i] - Low  [1+i]); //shadow donw                          
bool c4 = MathAbs (High [1+i] - Low  [1+i]); //total escursion                    
bool c5 = MathAbs (c2+c3); //sum shadow                                                
bool c6 = (100*c5)/ c4;  //result as a percentage                                                                
bool c7 = c6 < 3.9;                                                               
 
avatar
735
honest_knave 2016.09.15 11:25 #
 

You're working exclusively with bool variables... true / false (yes / no). Their values can only be 1 or 0. You need to be using some doubles.

Data Types 

avatar
86
fly7680 2016.09.15 15:03 #
 
I modified the code and no errors but still does not work.

Help please?

      bool   c1 =  Open[1+i] < Close [1+i] && MathAbs(Close[1+i]-Open[1+i]) > 2  * myPoint; //Candela Verde
      double c2 = MathAbs (High [1+i] - Close[1+i]); //shadow up                          
      double c3 = MathAbs (Open [1+i] - Low  [1+i]); //shadow donw                          
      double c4 = MathAbs (High [1+i] - Low  [1+i]); //total escursion
      double c5 = MathAbs (c2+c3);        //sum shadow                    
      double c6 = MathAbs (100*c5)/c4;  //result as a percentage                                                                
      bool   c7 = c6 < 3.9; 
avatar
12985
WHRoeder 2016.09.15 16:10 #
 
  1. "Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. There are no mind readers here.
  2. Print out your variables, and find out why.
  3. Drop the c1 as you don't use it. Rename your variables to meaningful names. Your code should be able to be read out loud and make sense.
  4. Drop your MathAbs as those are unnecessary (except c1 lline.)
  5. Your indicator for loop computes the value of bar "i," drop those "1+".
avatar
1202
FMIC 2016.09.15 16:10 #
 

You are assuming that all candles have Close > Open. Also, use variable names that are more meaningful and self documenting.

// Attention - uncompiled/untested!
int
   BarShift       = i + 1; // Depends on what you are doing (as "WHRoeder" pointed out)
double
   CandleOpen     = Open[  BarShift ],
   CandleClose    = Close[ BarShift ],
   CandleHigh     = High[  BarShift ],
   CandleLow      = Low[   BarShift ],
   CandleRange    = CandleHigh - CandleLow,
   BodyHigh       = fmax( CandleOpen, CandleClose ),
   BodyLow        = fmin( CandleOpen, CandleClose ),
   WickUpperRange = CandleHigh - BodyHigh,
   WickLowerRange = BodyLow - CandleLow,
   WickRange      = WickUpperRange + WickLowerRange,
   WickRatio      = ( CandleRange != 0.0  ) ? WickRange / CandleRange : 0.0, // Prevent "divide by zero" error
   WickPercentage = WickRatio * 100.0;
avatar
86
fly7680 2016.09.15 21:36 #
 
Thanks to everyone for the great suggestions and lines of code that occasionally posted for us beginners!
I was able to integrate your code to mine, it all works.

Thanks again
Back to topics list  

To add comments, please log in or register