mql5/Experts/Motivated/Utils/TimePrice.mqh
younglubah-gmail 2c46d7c354
2026-06-09 08:13:24 +02:00

120 lines
3.3 KiB
MQL5

//+------------------------------------------------------------------+
//| TimePrice.mqh |
//+------------------------------------------------------------------+
#property strict
#ifndef __TIME_PRICE_MQH__
#define __TIME_PRICE_MQH__
struct TimePrice
{
int i;
datetime x;
double y;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Reset()
{
x = 0;
y = 0.0;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Set(datetime timeValue, double priceValue)
{
x = timeValue;
y = priceValue;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Set(int index, datetime timeValue, double priceValue)
{
i = index;
x = timeValue;
y = priceValue;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Set(TimePrice &tp)
{
Set(tp.i, tp.x, tp.y);
}
bool Ok()
{
return x > 0 && y > 0.0;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
TimePrice CenterCoord(TimePrice &p2)
{
if(!Ok() && !p2.Ok())
{
TimePrice tp;
return tp;
}
if(!Ok())
return p2;
if(!p2.Ok())
return *this;
TimePrice tp;
datetime tx = x + (p2.x - x) / 2;
double py = (y + p2.y) / 2.0;
tp.Set(tx, py);
return tp;
}
string ToString()
{
return "Time: " + TimeToString(x) + " | Price: " + DoubleToString(y);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
TimePrice Min(TimePrice &p2)
{
TimePrice tp;
if(y <= p2.y)
tp.Set(i, x, y);
else
tp.Set(p2.i, p2.x, p2.y);
return tp;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
TimePrice Max(TimePrice &p2)
{
TimePrice tp;
if(y >= p2.y)
tp.Set(i, x, y);
else
tp.Set(p2.i, p2.x, p2.y);
return tp;
}
};
#endif
//+------------------------------------------------------------------+