Skip to content

Commit

Permalink
ToIndicator: fix and example
Browse files Browse the repository at this point in the history
  • Loading branch information
Roffild committed May 28, 2018
1 parent b6bd0f5 commit c08fb46
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 17 deletions.
74 changes: 74 additions & 0 deletions Experts/Roffild/Examples/ToIndicator_Example.mq5
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* https://github.com/Roffild/RoffildLibrary
*/
#property copyright "Roffild"
#property link "https://github.com/Roffild/RoffildLibrary"

#include <Roffild/ToIndicator.mqh>

CToIndicator indicBars, indicMedian;

int OnInit()
{
if (indicBars.init("indicBars", true) == INVALID_HANDLE) {
Print("ERROR: indicBars.init");
return INIT_FAILED;
}
indicBars.indicatorSetString(INDICATOR_SHORTNAME, "Bars");
indicBars.addPlot(DRAW_BARS, "Bar");
indicBars.plotIndexSetInteger(0, PLOT_LINE_COLOR, clrSkyBlue);
indicBars.addPlot(DRAW_COLOR_LINE, "Median");
indicBars.plotIndexSetInteger(1, PLOT_LINE_WIDTH, 2);
indicBars.plotIndexSetInteger(1, PLOT_COLOR_INDEXES, 2);
indicBars.plotIndexSetInteger(1, PLOT_LINE_COLOR, 0, clrKhaki);
indicBars.plotIndexSetInteger(1, PLOT_LINE_COLOR, 1, clrGreen);

if (indicMedian.init("indicMedian") == INVALID_HANDLE) {
Print("ERROR: indicMedian.init");
return INIT_FAILED;
}
indicMedian.addPlot(DRAW_COLOR_LINE, "Median");
indicMedian.plotIndexSetInteger(0, PLOT_LINE_WIDTH, 5);
indicMedian.plotIndexSetInteger(0, PLOT_COLOR_INDEXES, 2);
indicMedian.plotIndexSetInteger(0, PLOT_LINE_COLOR, 0, clrAquamarine);
indicMedian.plotIndexSetInteger(0, PLOT_LINE_COLOR, 1, clrPink);

indicBars.show();
indicMedian.show();
return INIT_SUCCEEDED;
}

void OnTick()
{
MqlRates rt[];
CopyRates(Symbol(), Period(), 0, 2, rt);
ArraySetAsSeries(rt, true);
const double median = (rt[0].high + rt[0].low) / 2.0;
const double median1 = (rt[1].high + rt[1].low) / 2.0;

indicBars.buffer(rt[0].close, 0);
// or
/*indicBars.buffer(rt[0].open, 0, 0, 0);
indicBars.buffer(rt[0].high, 0, 0, 1);
indicBars.buffer(rt[0].low, 0, 0, 2);
indicBars.buffer(rt[0].close, 0, 0, 3);*/

indicBars.buffer(median, 1, (uchar)(median > median1));

indicMedian.buffer(median, 0, (uchar)(median > median1));

indicBars.flush();
indicMedian.flush();
}
5 changes: 3 additions & 2 deletions Include/Roffild/ToIndicator.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public:
string id;
bool window;
int handleFile, handleIndicator;

CToIndicator() : handleFile(INVALID_HANDLE), handleIndicator(INVALID_HANDLE)
{}

Expand All @@ -68,8 +69,8 @@ public:
int init(const string _id, const bool _window = false, const bool ignore_visual = false)
{
id = _id;
if (ignore_visual || MQLInfoInteger(MQL_VISUAL_MODE)) {
handleFile = FileOpen(id, FILE_BIN|FILE_WRITE|FILE_SHARE_READ|FILE_SHARE_WRITE |FILE_COMMON);
if (MQLInfoInteger(MQL_TESTER) == 0 || (ignore_visual || MQLInfoInteger(MQL_VISUAL_MODE))) {
handleFile = FileOpen("ToIndicator/" + id, FILE_BIN|FILE_WRITE|FILE_SHARE_READ|FILE_SHARE_WRITE);
window = _window;
return handleFile;
}
Expand Down
30 changes: 15 additions & 15 deletions Indicators/Roffild/ToIndicator.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ int OnCalculate(const int rates_total,
const int& spread[])
{
if (hfile == INVALID_HANDLE) {
hfile = FileOpen(FilePath, FILE_BIN|FILE_READ|FILE_SHARE_READ|FILE_SHARE_WRITE |FILE_COMMON);
htell = FileOpen(FilePath, FILE_BIN|FILE_READ|FILE_SHARE_READ|FILE_SHARE_WRITE |FILE_COMMON);
hfile = FileOpen("ToIndicator/" + FilePath, FILE_BIN|FILE_READ|FILE_SHARE_READ|FILE_SHARE_WRITE);
htell = FileOpen("ToIndicator/" + FilePath, FILE_BIN|FILE_READ|FILE_SHARE_READ|FILE_SHARE_WRITE);
}
if (FileReadInteger(htell) == 0) {
return rates_total;
Expand Down Expand Up @@ -233,7 +233,7 @@ int OnCalculate(const int rates_total,
for (int x = 0; x < index; x++) {
count += plots[x].getBuffersCount();
}
const ENUM_DRAW_TYPE draw_type = ENUM_DRAW_TYPE(param.property);
const ENUM_DRAW_TYPE draw_type = (ENUM_DRAW_TYPE)(param.property);
switch (draw_type) {
case DRAW_NONE: plots[index] = new CToIndicator_Buffers_1(); break;
case DRAW_LINE: plots[index] = new CToIndicator_Buffers_1(); break;
Expand Down Expand Up @@ -263,43 +263,43 @@ int OnCalculate(const int rates_total,
plots[index] = new CToIndicator_Color<CToIndicator_Buffers_4>(); break;
default: Print(EnumToString(draw_type), " is not support"); break;
}
plots[index].setBuffers(draw_type, ushort(index), count,
plots[index].setBuffers(draw_type, (ushort)(index), count,
ShortArrayToString(param.text), param.double_value);
setbuffer = true;
} else if (type == TOINDICATOR_PLOT_INTEGER_MOD) {
PlotIndexSetInteger(param.index, ENUM_PLOT_PROPERTY_INTEGER(param.property),
PlotIndexSetInteger(param.index, (ENUM_PLOT_PROPERTY_INTEGER)(param.property),
param.modifier, param.int_value);
} else if (type == TOINDICATOR_PLOT_INTEGER) {
PlotIndexSetInteger(param.index, ENUM_PLOT_PROPERTY_INTEGER(param.property),
PlotIndexSetInteger(param.index, (ENUM_PLOT_PROPERTY_INTEGER)(param.property),
param.int_value);
} else if (type == TOINDICATOR_PLOT_DOUBLE) {
PlotIndexSetDouble(param.index, ENUM_PLOT_PROPERTY_DOUBLE(param.property),
PlotIndexSetDouble(param.index, (ENUM_PLOT_PROPERTY_DOUBLE)(param.property),
param.double_value);
} else if (type == TOINDICATOR_PLOT_STRING) {
PlotIndexSetString(param.index, ENUM_PLOT_PROPERTY_STRING(param.property),
PlotIndexSetString(param.index, (ENUM_PLOT_PROPERTY_STRING)(param.property),
ShortArrayToString(param.text));
} else if (type == TOINDICATOR_INDIC_INTEGER_MOD) {
IndicatorSetInteger(ENUM_CUSTOMIND_PROPERTY_INTEGER(param.property),
IndicatorSetInteger((ENUM_CUSTOMIND_PROPERTY_INTEGER)(param.property),
param.modifier, param.int_value);
} else if (type == TOINDICATOR_INDIC_INTEGER) {
IndicatorSetInteger(ENUM_CUSTOMIND_PROPERTY_INTEGER(param.property),
IndicatorSetInteger((ENUM_CUSTOMIND_PROPERTY_INTEGER)(param.property),
param.int_value);
} else if (type == TOINDICATOR_INDIC_DOUBLE_MOD) {
IndicatorSetDouble(ENUM_CUSTOMIND_PROPERTY_DOUBLE(param.property),
IndicatorSetDouble((ENUM_CUSTOMIND_PROPERTY_DOUBLE)(param.property),
param.modifier, param.double_value);
} else if (type == TOINDICATOR_INDIC_DOUBLE) {
IndicatorSetDouble(ENUM_CUSTOMIND_PROPERTY_DOUBLE(param.property),
IndicatorSetDouble((ENUM_CUSTOMIND_PROPERTY_DOUBLE)(param.property),
param.double_value);
} else if (type == TOINDICATOR_INDIC_STRING_MOD) {
IndicatorSetString(ENUM_CUSTOMIND_PROPERTY_STRING(param.property),
IndicatorSetString((ENUM_CUSTOMIND_PROPERTY_STRING)(param.property),
param.modifier, ShortArrayToString(param.text));
} else if (type == TOINDICATOR_INDIC_STRING) {
IndicatorSetString(ENUM_CUSTOMIND_PROPERTY_STRING(param.property),
IndicatorSetString((ENUM_CUSTOMIND_PROPERTY_STRING)(param.property),
ShortArrayToString(param.text));
}
const int error = GetLastError();
if (error != 0) {
Print("ToIndicator ERROR = ", error, " in ", EnumToString(ENUM_TOINDICATOR(type)));
Print("ToIndicator ERROR = ", error, " in ", EnumToString((ENUM_TOINDICATOR)(type)));
}
continue;
}
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* [AmazonUtils](Experts/Roffild/AmazonUtils) - can be used as an example of developing a project in Java
* [Alglib_MultilayerPerceptron.mq5](Experts/Roffild/Alglib_MultilayerPerceptron.mq5)
* [Alglib_RandomForest.mq5](Experts/Roffild/Alglib_RandomForest.mq5)
* [Examples/](Experts/Roffild/Examples/)
* [ToIndicator_Example.mq5](Experts/Roffild/Examples/ToIndicator_Example.mq5)
* Include/Roffild/
* [MLPDataFile.mqh](Include/Roffild/MLPDataFile.mqh) - data format for Alglib_MultilayerPerceptron and Alglib_RandomForest
* [ArrayList_macros.mqh](Include/Roffild/ArrayList_macros.mqh) - this variant is still used because of poor template support by the code editor
Expand Down
2 changes: 2 additions & 0 deletions README_ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* [AmazonUtils](Experts/Roffild/AmazonUtils) - можно использовать как пример разработки проекта на Java
* [Alglib_MultilayerPerceptron.mq5](Experts/Roffild/Alglib_MultilayerPerceptron.mq5)
* [Alglib_RandomForest.mq5](Experts/Roffild/Alglib_RandomForest.mq5)
* [Examples/](Experts/Roffild/Examples/)
* [ToIndicator_Example.mq5](Experts/Roffild/Examples/ToIndicator_Example.mq5)
* Include/Roffild/
* [MLPDataFile.mqh](Include/Roffild/MLPDataFile.mqh) - формат данных для Alglib_MultilayerPerceptron и Alglib_RandomForest
* [ArrayList_macros.mqh](Include/Roffild/ArrayList_macros.mqh) - этот вариант еще используется из-за плохой поддержки шаблонов редактором кода
Expand Down

0 comments on commit c08fb46

Please sign in to comment.