This script is designed to perform a specific mathematical calculation to determine the value of Pi ($\pi$) with high precision. Rather than simply using a pre-defined number already stored in the software, the program generates this constant from scratch using a mathematical formula.
How it works:
- The Mathematical Foundation: The logic utilizes a specific series expansion (a mathematical sequence) to approximate the value of Pi. By adding together a series of fractions that get progressively smaller and more precise, the script builds the number piece by piece.
- Iterative Calculation: The program runs a loop that repeats a set of calculations 11 times. In each step, it calculates a specific fraction based on the current position in the sequence and adds it to a running total.
- Increasing Precision: With every iteration of the loop, the formula targets a deeper decimal place, ensuring that the final result is accurate enough for professional use.
- Final Output: Once the loop finishes, the script captures the final sum and displays it in the system logs (the "Print" function), showing the calculated value of Pi rounded to eight decimal places.
In essence, this is a demonstration of mathematical logic where the software "calculates" its own constants rather than relying on external data.
//+------------------------------------------------------------------+
//| Pi.mq4 |
//| Ïðèâàëîâ Ñ.Â. |
//| Skype -> privalov-sv |
//+------------------------------------------------------------------+
#property copyright "Ïðèâàëîâ Ñ.Â."
#property link "Skype -> privalov-sv"
//+------------------------------------------------------------------+
//| script program start function |
//+------------------------------------------------------------------+
int start()
{
//----
// ÷åì áîëüøå öèêëîâ - òåì áîëüøå òî÷íîñòü
// â äàííîì âàðèàíòå ñîâïàäàåò ñî âëîæåííîé â MathCad êîíñòàíòîé ïè
double Pi=0.0;
for(double i=0; i<11; i++) Pi+= 1/MathPow(16,i)*(4/(8*i+1)-2/(8*i+4)-1/(8*i+5)-1/(8*i+6));
Print("Pi=",DoubleToStr(Pi,8));
//----
return(0);
}
//+------------------------------------------------------------------+
Comments