// comp.comp() returns true if the first argument is less than the second.// If failure, returns UINT_MAX.template<typename A, typename T, typename Comp>
uint alg_lower_bound(const A &ar[], uint minindex, uint maxindex,
const T &value, Comp &comp, bool rev=false)
{
uint count = maxindex - minindex + 1;
uint first = minindex;
if(rev)
first = maxindex;
while(count != 0)
{
uint it = first;
uint step = count / 2;
if(rev)
it -= step;
else
it += step;
if(comp.comp(ar[it], value))
{
if(rev)
first = --it;
else
first = ++it;
count -= step + 1;
}
else
count = step;
}
if(first < minindex || first > maxindex)
first = UINT_MAX;
return first;
}
class Chart
{
struct Bar_trend
{
double p1;
double p2;
datetime time;
};
Bar_trend bar_trend[];
upindex_t sz;
upindex_t curtain;
bool reverse_f;
void refresh_base(datetime min = 0, datetime max = 0);
public:
// Empty chart will be created.
Chart(): sz(0), curtain(UPINDEXT_MAX), reverse_f(false) {}
// Chart with points whose time is in interval min:max will be created.
Chart(datetime min, datetime max): sz(0), curtain(UPINDEXT_MAX), reverse_f(false) { refresh_base(min, max); }
// Reverse flag is not changed. For whole chart min and max are 0.void init(datetime min, datetime max);
My_point operator[](upindex_t i)const;
// If exact is true then time of point with returned index is equal to time.// If point is not found then function returns UPINDEXT_MAX.
upindex_t bar_shift(datetime time, bool exact=true)const;
upindex_t size()const {returnthis.curtain == UPINDEXT_MAX ? this.sz * 2 : this.curtain;}
// pos can not be greater than the size(). UPINDEXT_MAX for deletion of curtain.// It will be reset when refresh(). Returns true in case of success.bool set_curtainpos(upindex_t pos);
upindex_t get_curtainpos()const {returnthis.curtain;}
bool reverse_mode()const {returnthis.reverse_f;}
// Returns true in case of success.bool reverse_mode(bool mode);
// if chart size == 0 then lowest = highest == UPINDEXT_MAX.void extremums(upindex_t &lowest, upindex_t &highest)const;
// if chart is reverse then indexes will be invalidated.void refresh() { refresh_base(); }
};
upindex_t Chart::bar_shift(datetime time, bool exact)const
{
class Comp
{
public:
bool comp(const Bar_trend &bt, datetime time) {return bt.time > time;}
}comp;
uint res = alg_lower_bound(this.bar_trend, 0, this.sz-1, time, comp, true);
if(res != UINT_MAX)
{
uchar shift = this.bar_trend[res].time!=time ? 1 : 0;
if(exact && this.bar_trend[res].time+shift != time)
res = UINT_MAX;
else
res = this.reverse_f ?
((this.sz - 1 - res) * 2 + !shift) :
(res * 2 + shift);
}
return res == UINT_MAX ? UPINDEXT_MAX : res;
}
还有一个简单的使用例子。
Chart chart();
chart.refresh();
for(int i = 0; i < chart.size(); ++i)
Print(chart[i].price, chart[i].time);
一般来说,我是斜着读的,而且只读第一页(也许中间是某人的光明正大的头? :) ),一些东西都试图在可怕的不方便的终端界面上添加拐杖来访问历史,在终端和自己的东西之间写一个垫子更容易(一般来说,它应该在std库中)。 此外,作为一个结果,你不需要为4/5写不同的脚本。我已经做了这样的事情。
还有一个简单的使用例子。
refresh()通过为4/5定义自己的。该图表只有一个周期(M1或其他通过定义定义的周期,为什么对他们的丰富性有这种困扰?)
此外,我还实现了一些有用的功能--从任何一边进行反向_mode()索引(如果从左到右,展开图表时索引仍然有效)。能够设置和移动图表边缘set_curtainpos(),类似于测试器--测试、移动边界、测试、移动。在结构My_point处重载了比较运算符(对于这种情况下的有效行为:0.0000000009 == 1.0000000000)。
如果有人苦恼,我推荐这种方法,我个人并不后悔。
Zy: 我放弃了经典的开盘/收盘/高点/低点的蜡烛图,而把点 放在基础上--一个蜡烛图给出两个点,看跌的高点>低点,看涨的低点-高点,这真的非常方便。
我将等待最终形式的更正,谢谢你的回答。
祝你考试顺利!
结果是非常微妙的。
如果我知道会有多复杂,我就不会参与了))))。
这个选项应该能正确工作。
如果有人发现它的工作方式不正确,如果他们能报告这个问题,我将非常感激。
你的iBars()与标准Bars()在性能上有多大差别?
这取决于你如何使用它。
如果每次对iBar的调用都能改变TF或符号,那么我的iBar就会慢一半左右。
但从实际的角度来看,这绝对不是一个现实的情况。
如果你这样使用,比如说。
那么我的iBars 比普通Bars的优势将是大约10倍或更多。
但最主要的是,没有挂机的毛病。
在上面的代码中修正了它。添加了一行。
这取决于你如何使用它。
如果每次对iBar的调用都会改变TF或符号,那么我的iBar工作起来就会慢两倍。
但从实际情况来看,这是一个完全不现实的情况。
如果你这样使用,比如说。
那么我的iBars比标准Bars的优势将是10倍或更多。
但最主要的是,没有挂机的毛病。
r-r-r-r-respect!
这取决于你如何使用它。
如果每次对iBar的调用都会改变TF或符号,那么我的iBar工作起来就会慢两倍。
但从实际情况来看,这是一个完全不现实的情况。
如果你这样使用,比如说。
那么我的iBars比标准Bars的优势将是10倍或更多。
但最主要的是,没有冻结的错误。
来吧!
你的10秒钟在哪里?
2018.05.05 17:45:36.860 ind EURUSD,M5: 2
2018.05.05 17:45:36.860 ind EURUSD,M5: 0
2018.05.05 17:45:36.860 ind EURUSD,M5: 1
来吧!
你的10秒钟在哪里?
2018.05.05 17:45:36.860 ind EURUSD,M5: 2
2018.05.05 17:45:36.860 ind EURUSD,M5: 0
2018.05.05 17:45:36.860 ind EURUSD,M5: 1
是MT5吗?
MT4
在MT5上试试,会有惊喜。
这个错误的发现完全是由于@Aleksey Vyazmikin的 帖子,对此我必须非常感谢他。
我以前一直在观察这些中断,但无法解释其来源。谁会想到...