Skip to content

Commit

Permalink
WIP. Next part of fixes. Still some Trade class fixes needed.
Browse files Browse the repository at this point in the history
  • Loading branch information
nseam committed Jul 8, 2022
1 parent 54d0f24 commit 8a8d672
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 137 deletions.
2 changes: 1 addition & 1 deletion Log.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class Log : public Object {
}
*/

virtual const string ToString() {
string ToString() override {
string result;

unsigned int lid;
Expand Down
2 changes: 1 addition & 1 deletion Market.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class Market : public SymbolInfo {
/**
* Returns Market data in textual representation.
*/
string const ToString() {
string ToString() override {
return StringFormat(string("Pip digits/value: %d/%g, Spread: %d pts (%g pips; %.4f%%), Pts/pip: %d, ") +
"Volume digits: %d, " + "Delta: %g, Last change: %g pips",
GetPipDigits(), GetPipValue(), GetSpreadInPts(), GetSpreadInPips(), GetSpreadInPct(),
Expand Down
4 changes: 2 additions & 2 deletions Object.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ class Object : public Dynamic {
/**
* Returns text representation of the object.
*/
virtual const string ToString() { return StringFormat("[Object #%04x]", GetPointer(this)); }
virtual string ToString() { return StringFormat("[Object #%04x]", GetPointer(this)); }

/**
* Returns text representation of the object.
*/
virtual const string ToJSON() { return StringFormat("{ \"type\": \"%s\" }", typename(this)); }
virtual string ToJSON() { return StringFormat("{ \"type\": \"%s\" }", typename(this)); }

/**
* Safely delete the object.
Expand Down
2 changes: 1 addition & 1 deletion Order.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -2792,7 +2792,7 @@ class Order : public SymbolInfo {
/**
* Returns order details in text.
*/
string const ToString() {
string ToString() override {
SerializerConverter stub(SerializerConverter::MakeStubObject<Order>(SERIALIZER_FLAG_SKIP_HIDDEN));
return SerializerConverter::FromObject(THIS_REF, SERIALIZER_FLAG_SKIP_HIDDEN)
.ToString<SerializerJson>(SERIALIZER_FLAG_SKIP_HIDDEN, &stub);
Expand Down
2 changes: 2 additions & 0 deletions Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ class Platform {
props.vol_digits = SymbolInfoStatic::GetVolumeDigits(_symbol);
props.vol_min = SymbolInfoStatic::GetVolumeMin(_symbol);
props.vol_max = SymbolInfoStatic::GetVolumeMax(_symbol);
props.vol_step = SymbolInfoStatic::GetVolumeStep(_symbol);
props.point_size = SymbolInfoStatic::GetPointSize(_symbol);
#endif
return props;
}
Expand Down
2 changes: 1 addition & 1 deletion SymbolInfo.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ class SymbolInfo : public Object {
/**
* Returns symbol information in string format.
*/
const string ToString() {
string ToString() override {
return StringFormat(
string("Symbol: %s, Last Ask/Bid: %g/%g, Last Price/Session Volume: %d/%g, Point size: %g, Pip size: %g, ") +
"Tick size: %g (%g pts), Tick value: %g (%g/%g), " + "Digits: %d, Spread: %d pts, Trade stops level: %d, " +
Expand Down
30 changes: 30 additions & 0 deletions SymbolInfo.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ struct SymbolInfoProp {
unsigned int vol_digits; // Volume digits.
double vol_min; // Minimum volume for a deal.
double vol_max; // Maximum volume for a deal.
double vol_step; // Volume step.
double point_size; // Point size.
double tick_size; // Minimal price change.

// Constructors.
SymbolInfoProp() : initialized(false) {}
SymbolInfoProp(const SymbolInfoProp& _sip) {
Expand All @@ -90,6 +94,9 @@ struct SymbolInfoProp {
vol_digits = _sip.vol_digits;
vol_min = _sip.vol_min;
vol_max = _sip.vol_max;
vol_step = _sip.vol_step;
point_size = _sip.point_size;
tick_size = _sip.tick_size;
}
// Getters.
double GetPipValue() { return pip_value; }
Expand All @@ -99,6 +106,26 @@ struct SymbolInfoProp {
unsigned int GetVolumeDigits() { return vol_digits; }
double GetVolumeMin() { return vol_min; }
double GetVolumeMax() { return vol_max; }
double GetVolumeStep() { return vol_step; }
double GetPointSize() { return point_size; }
double GetTickSize() { return tick_size; }

/**
* Normalize price value.
*
* Make sure that the price is a multiple of ticksize.
*/
double NormalizePrice(double p) {
// See: http://forum.mql4.com/47988
// http://forum.mql4.com/43064#515262 zzuegg reports for non-currency DE30:
// - MarketInfo(chart.symbol,MODE_TICKSIZE) returns 0.5
// - MarketInfo(chart.symbol,MODE_DIGITS) return 1
// - Point = 0.1
// Rare fix when a change in tick size leads to a change in tick value.
double _result = round(p / GetPointSize()) * GetTickSize();
_result = NormalizeDouble(_result, GetDigits());
return _result;
}

// Serializers.
void SerializeStub(int _n1 = 1, int _n2 = 1, int _n3 = 1, int _n4 = 1, int _n5 = 1) {}
Expand All @@ -123,5 +150,8 @@ SerializerNodeType SymbolInfoProp::Serialize(Serializer& _s) {
_s.Pass(THIS_REF, "vol_digits", vol_digits);
_s.Pass(THIS_REF, "vol_min", vol_min);
_s.Pass(THIS_REF, "vol_max", vol_max);
_s.Pass(THIS_REF, "vol_step", vol_step);
_s.Pass(THIS_REF, "point_size", point_size);
_s.Pass(THIS_REF, "tick_size", tick_size);
return SerializerNodeObject;
}
2 changes: 1 addition & 1 deletion Timer.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class Timer : public Object {
/**
* Print timer times.
*/
virtual const string ToString() {
string ToString() override {
return StringFormat("%s(%d)=%d-%dms,med=%dms,sum=%dms", GetName(), ArraySize(this PTR_DEREF data), GetMin(),
GetMax(), GetMedian(), GetSum());
}
Expand Down
Loading

0 comments on commit 8a8d672

Please sign in to comment.