VPFx

VPFx最新版

更新日期:2022-03-06分类标签: 语言:中文平台:没限制

18 人已下载 手机查看

VPFx

 

#property copyright “TPO: Time Price Opportunity, v2.5.7491. ?2009-2010 Plus.”
#property link “http://fxcoder.ru, plusfx@ya.ru, skype:plusfx”

#property indicator_chart_window

// 相疣戾蝠?疣聍弪钼
extern int RangePeriod = PERIOD_D1; // 以 滂囡噻铐? 漕腈屙 猁螯 钿龛?桤 耱囗溧痱睇?
extern int RangeCount = 20; // 觐腓麇耱忸 滂囡噻铐钼/汨耱钽疣祆

//tf#extern string TimeFrom = “00:00”; // 磬鬣豚 滂囡噻铐?(忭篁痂 耋蝾?
//tf#extern string TimeTo = “00:00”; // 觐礤?滂囡噻铐?(忭篁痂 耋蝾? + 1 扈眢蜞

extern int ModeStep = 10; // ?镱桉赅 祛? 羿牝梓羼觇 ?2 疣玎 犷朦 + 1
int Smooth = 0; // 汶筢桧?胥豚骅忄龛, 镳桁屙弪? 嚯泐痂蜢 镱耠邃钼囹咫钽?篑疱漤屙? 蝠栲?箨噻囗眍?麒耠?疣?
extern int PriceStep = 0; // ?鲥睇, 0 – 噔蝾 (耢. #1)
extern int DataPeriod = 1; // 镥痂钿 潆 溧眄, 扈眢蜿?- 襦禧?蝾黜
bool ShowHorizon = true; // 镱赅玎螯 泐痂珙眚 溧眄

// 描耱钽疣祆?
extern color HGColor = C’160,192,224′; // 鲡弪 汨耱钽疣祆?
extern int HGStyle = 1; // 耱桦?汨耱钽疣祆? 0 – 腓龛? 1 – 矬耱 镳祛筱铍桕? 2 – 玎镱腠屙睇?镳祛筱铍桕?
extern color ModeColor = Blue; // 鲡弪 祛?
extern color MaxModeColor = CLR_NONE; // 恹溴腓螯 爨犟桁箪

int HGLineWidth = 1; // 痂磬 腓龛?汨耱钽疣祆?
double Zoom = 0; // 爨聒蜞?汨耱钽疣祆? 0 – 噔蝾爨聒蜞?

int ModeWidth = 1; // 蝾膣桧?祛?
int ModeStyle = STYLE_SOLID; // 耱桦?祛?

// 央箧遽睇?
extern string Id = “+tpo”; // 镳弭桕?桁屙 腓龛?

int WaitSeconds = 1; // 扈龛爨朦眍?怵屐, ?皴牦礓圊, 戾驿?钺眍怆屙?扈
int TickMethod = 1; // 戾蝾?桁栩圉梃 蜩觐? 0 – Low >> High, 1 – Open > Low(High) > High(Low) > Close, 2 – HLC, 3 – HL, 4 – 佯邃礤蜩觐恹?锺邂漕-钺?
// +4 – 徨?篦弪?钺爨, +8 – ?篦弪铎 钺爨 ?潆桧?徉疣.

string onp;

datetime drawHistory[]; // 桉蝾痂 痂耦忄龛
datetime lastTime = 0; // 镱耠邃礤?怵屐? 玎矬耜?
bool lastOK = false;

double hgPoint; // 扈龛爨朦眍?桤戾礤龛?鲥睇
int modeStep = 0;
int smooth = 0;

bool showHG, showModes, showMaxMode;
bool hgBack = true;
bool hgUseRectangles = false;

// 桧蝈痫疱蜞鲨 镱朦珙忄蝈朦耜桴 溧眄 镱 怵屐屙?
//tf#string timeFrom = “00:00”;
//tf#string timeTo = “23:59″;
//tf#bool filterTime = false;

#define ERR_HISTORY_WILL_UPDATED 4066

int init()
{
onp = Id + ” ” + RangePeriod + ” “;

hgPoint = Point;

bool is5digits = ((Digits == 3) || (Digits == 5)) && (MarketInfo(Symbol(), MODE_PROFITCALCMODE) == 0);

//#1
if (PriceStep == 0)
{
if (is5digits)
hgPoint = Point * 10.0;
}
else
{
hgPoint = Point * PriceStep;
}

modeStep = ModeStep * Point / hgPoint;
smooth = Smooth;
if (is5digits)
{
modeStep *= 10;
}

ArrayResize(drawHistory, 0);

// 磬耱痤殛?铗钺疣驽龛
showHG = (HGColor != CLR_NONE) && (HGColor != -16777216);
showModes = (ModeColor != CLR_NONE) && (ModeColor != -16777216);
showMaxMode = (MaxModeColor != CLR_NONE) && (MaxModeColor != -16777216);

// 觐痧尻蜩痼屐 镟疣戾蝠?耱桦
if (HGStyle == 1)
{
hgBack = false;
hgUseRectangles = true;
}
else if (HGStyle == 2)
{
hgBack = true;
hgUseRectangles = true;
}

// 镳钼屦屐 怩钿睇?溧眄 镱 怵屐屙?
//tf#datetime tf = StrToTime(“2000.01.01 ” + TimeFrom);
//tf#datetime tt = StrToTime(“2000.01.01 ” + TimeTo) – 1; // 礤 怅膻鬣屐 镳噔簋 沭囗桷?(1 扈眢蜞, ?? 扈? 以 ?)

//tf#filterTime = tt >= tf;

//tf#if (filterTime)
//tf#{
//tf# timeFrom = TimeToStr(tf, TIME_MINUTES);
//tf# timeTo = TimeToStr(tt, TIME_MINUTES);
//tf#}

//tf#Comment(“Filter time: ” + filterTime + “\n” +
//tf# “From: ” + timeFrom + “\n” +
//tf# “To: ” + timeTo + “\n”);
}

int start()
{
datetime currentTime = TimeLocal();

// 怦邈溧 钺眍怆屐? 磬 眍忸?徉疱…
if ((Volume[0] > 1) && lastOK)
{
// …?礤 鬣, 麇?疣??礤耜铍?皴牦礓
if (currentTime – lastTime < WaitSeconds)
return(0);
}

lastTime = currentTime;

if (ShowHorizon)
{
datetime hz = iTime(NULL, DataPeriod, iBars(NULL, DataPeriod) – 1);
drawVLine(onp + “hz”, hz, Red, 1, STYLE_DOT, false);
}

double vh[], hLow;

lastOK = true;
for (int i = 0; i < RangeCount; i++)//1 – ShowLast
{
int barFrom, barTo, m1BarFrom, m1BarTo;

datetime timeFrom = iTime(NULL, RangePeriod, i);

datetime timeTo = Time[0];
if (i != 0)
timeTo = iTime(NULL, RangePeriod, i – 1);

if (getRange(timeFrom, timeTo, barFrom, barTo, m1BarFrom, m1BarTo, DataPeriod))
{
if (!checkDrawHistory(timeFrom) || (i == 0))
{
int count = getHGByRates(m1BarFrom, m1BarTo, TickMethod, vh, hLow, hgPoint, DataPeriod);

if (count > 0)
{
if (smooth > 0)
{
count = smoothHG(vh, smooth);
//hLow -= smooth * hgPoint;
}

if (i != 0)
addDrawHistory(timeFrom);

// 铒疱溴脲龛?爨聒蜞徉
double zoom = Zoom*0.000001;
if (zoom <= 0)
{
double maxVolume = vh[ArrayMaximum(vh)];
zoom = (barFrom – barTo) / maxVolume;
}

// 痂耋屐
if (showHG)
{
string prefix = onp + “hg ” + TimeToStr(timeFrom) + ” “;
drawHG(prefix, vh, hLow, barFrom, HGColor, HGColor, zoom, HGLineWidth, hgPoint);
}

if (showModes || showMaxMode)
drawModes(vh, hLow, barFrom, zoom, hgPoint);
}
}
}
else
{
lastOK = false;
}
}

return(0);
}

int deinit()
{
clearChart(onp);
return(0);
}

// 镳钼屦弪, 痂耦忄腓顸 腓 潆 溧眄铋 溧螓 箴钼龛
bool checkDrawHistory(datetime time)
{
int count = ArraySize(drawHistory);
bool r = false;
for (int i = 0; i < count; i++)
{
if (drawHistory[i] == time)
{
r = true;
break;
}
}
return(r);
}

// 漕徉忤螯 铗痂耦忄眄 篦囫蝾??桉蝾痂?
void addDrawHistory(datetime time)
{
if (!checkDrawHistory(time))
{
int count = ArraySize(drawHistory);
ArrayResize(drawHistory, count + 1);
drawHistory[count] = time;
}
}

// 磬痂耦忄螯 祛潲 汨耱钽疣祆?
void drawModes(double& vh[], double hLow, int barFrom, double zoom, double point)
{
int modes[], modeCount, j;
double price;

// 镱桉?祛?
modeCount = getModesIndexes(vh, modeStep, modes);

// 爨犟. 祛溧
double max = 0;
if (showMaxMode)
{
for (j = 0; j < modeCount; j++)
if (vh[modes[j]] > max)
max = vh[modes[j]];
}

datetime timeFrom = getBarTime(barFrom);

clearChart(onp + “mode ” + TimeToStr(timeFrom) + ” “);

// 怦邈溧 箧桊?屐 祛潲 ?疱骅爨?痂耦忄龛 镳祛筱铍桕囔?
bool back = false;
if (hgUseRectangles)
back = true;

string on;

for (j = 0; j < modeCount; j++)
{
double v = zoom * vh[modes[j]];

// 礤 痂耦忄螯 觐痤蜿桴 腓龛?(戾睃 徉疣 以), 汶栩 镳?恹溴脲龛?沭囗桷
if (MathAbs(v) > 0)
{
price = hLow + modes[j]*point;
datetime timeTo = getBarTime(barFrom – v);

on = onp + “mode ” + TimeToStr(timeFrom) + ” ” + DoubleToStr(price, Digits);
if (showMaxMode && (MathAbs(vh[modes[j]] – max) < point)) // 爨犟桁嚯? 祛溧
{
drawTrend(on, timeFrom, price, timeTo, price, MaxModeColor, ModeWidth, ModeStyle, back, false, 0, hgUseRectangles);

// ?疱骅戾 痂耦忄龛 镳祛筱铍桕囔?祛潲 痂耋屐 腓龛扈, 桧圜?铐?耜瘥忄?
if (hgUseRectangles && back)
drawTrend(on + “+”, timeFrom, price, timeTo, price, MaxModeColor, ModeWidth, ModeStyle, false, false, 0, false);
}
else if (showModes) // 钺磬 祛溧
{
drawTrend(on, timeFrom, price, timeTo, price, ModeColor, ModeWidth, ModeStyle, back, false, 0, hgUseRectangles);

// ?疱骅戾 痂耦忄龛 镳祛筱铍桕囔?祛潲 痂耋屐 腓龛扈, 桧圜?铐?耜瘥忄?
if (hgUseRectangles && back)
drawTrend(on + “+”, timeFrom, price, timeTo, price, ModeColor, ModeWidth, ModeStyle, false, false, 0, false);
}
}
}
}

datetime getBarTime(int shift, int period = 0)
{
if (period == 0)
period = Period();

if (shift >= 0)
return(iTime(Symbol(), period, shift));
else
return(iTime(Symbol(), period, 0) – shift*period*60);
}

/// 西桉蜩螯 沭圄桕 铗 疋铊?钺牝钼
int clearChart(string prefix)
{
int obj_total = ObjectsTotal();
string name;

int count = 0;
for (int i = obj_total – 1; i >= 0; i–)
{
name = ObjectName(i);
if (StringFind(name, prefix) == 0)
{
ObjectDelete(name);
count++;
}
}
return(count);
}

void drawVLine(string name, datetime time1, color lineColor = Gray, int width = 1, int style = STYLE_SOLID, bool back = true)
{
if (ObjectFind(name) >= 0)
ObjectDelete(name);

ObjectCreate(name, OBJ_VLINE, 0, time1, 0);
ObjectSet(name, OBJPROP_COLOR, lineColor);
ObjectSet(name, OBJPROP_BACK, back);
ObjectSet(name, OBJPROP_STYLE, style);
ObjectSet(name, OBJPROP_WIDTH, width);
}

void drawTrend(string name, datetime time1, double price1, datetime timeTo, double price2,
color lineColor, int width, int style, bool back, bool ray, int window, bool useRectangle)
{
if (ObjectFind(name) >= 0)
ObjectDelete(name);

if (useRectangle)
ObjectCreate(name, OBJ_RECTANGLE, window, time1, price1 – hgPoint / 2.0, timeTo, price2 + hgPoint / 2.0);
else
ObjectCreate(name, OBJ_TREND, window, time1, price1, timeTo, price2);

ObjectSet(name, OBJPROP_BACK, back);
ObjectSet(name, OBJPROP_COLOR, lineColor);
ObjectSet(name, OBJPROP_STYLE, style);
ObjectSet(name, OBJPROP_WIDTH, width);
ObjectSet(name, OBJPROP_RAY, ray);
}

// 磬痂耦忄螯 汨耱钽疣祆?(+鲡弪 +point)
void drawHG(string prefix, double& h[], double low, int barFrom, color bgColor, color lineColor, double zoom, int width, double point)
{
double max = h[ArrayMaximum(h)];
if (max == 0)
return(0);

int bgR = (bgColor & 0xFF0000) >> 16;
int bgG = (bgColor & 0x00FF00) >> 8;
int bgB = (bgColor & 0x0000FF);

int lineR = (lineColor & 0xFF0000) >> 16;
int lineG = (lineColor & 0x00FF00) >> 8;
int lineB = (lineColor & 0x0000FF);

int dR = lineR – bgR;
int dG = lineG – bgG;
int dB = lineB – bgB;

int hc = ArraySize(h);
for (int i = 0; i < hc; i++)
{
double price = NormalizeDouble(low + i*point, Digits);

int barTo = barFrom – h[i]*zoom;

// 疣耜疣耜?沭噤桢眚铎
double fade = h[i] / max;
int r = MathMax(MathMin(bgR + fade * dR, 255), 0);
int g = MathMax(MathMin(bgG + fade * dG, 255), 0);
int b = MathMax(MathMin(bgB + fade * dB, 255), 0);
color cl = (r << 16) + (g << 8) + b;

datetime timeFrom = getBarTime(barFrom);
datetime timeTo = getBarTime(barTo);

if (barFrom != barTo)
drawTrend(prefix + DoubleToStr(price, Digits), timeFrom, price, timeTo, price, cl, width, STYLE_SOLID, hgBack, false, 0, hgUseRectangles);
}
}

// 镱塍麒螯 镟疣戾蝠?滂囡噻铐?
bool getRange(datetime timeFrom, datetime timeTo, int& barFrom, int& barTo,
int& p1BarFrom, int& p1BarTo, int period)
{
// 滂囡噻铐 徉痤??蝈牦?以 (潆 痂耦忄龛)

barFrom = iBarShift(NULL, 0, timeFrom);
datetime time = Time[barFrom];
int bar = iBarShift(NULL, 0, time);
time = Time[bar];
if (time != timeFrom)
barFrom–;

barTo = iBarShift(NULL, 0, timeTo);
time = Time[barTo];
bar = iBarShift(NULL, 0, time);
time = Time[bar];
if (time == timeFrom)
barTo++;

if (barFrom < barTo)
return(false);

// 滂囡噻铐 徉痤?以 period (潆 镱塍麇龛 溧眄)

p1BarFrom = iBarShift(NULL, period, timeFrom);
time = iTime(NULL, period, p1BarFrom);
if (time != timeFrom)
p1BarFrom–;

p1BarTo = iBarShift(NULL, period, timeTo);
time = iTime(NULL, period, p1BarTo);
if (timeTo == time)
p1BarTo++;

if (p1BarFrom < p1BarTo)
return(false);

return(true);
}

/// 项塍麒螯 汨耱钽疣祆?疣耧疱溴脲龛 鲥?
/// m1BarFrom, m1BarTo – 沭囗桷?滂囡噻铐? 玎溧眄 眍戾疣扈 徉痤?扈眢蝾?
/// 骂玮疣弪:
/// 疱珞朦蜞?- 觐腓麇耱忸 鲥??汨耱钽疣祆? 0 – 铠栳赅
/// vh – 汨耱钽疣祆?
/// hLow – 龛骓 沭囗桷?汨耱钽疣祆?
/// point – ?鲥睇
/// dataPeriod – 蜞殪麴彘?溧眄int
int getHGByRates(int m1BarFrom, int m1BarTo, int tickMethod, double& vh[], double& hLow, double point, int dataPeriod)
{
double rates[][6];
double hHigh;

// 镳邃镱腩骅蝈朦眍?(?爨犟桁嚯铄) 觐腓麇耱忸 扈眢蝾?
int rCount = getRates(m1BarFrom, m1BarTo, rates, hLow, hHigh, dataPeriod);
//Print(“rCount: ” + rCount);

if (rCount != 0)
{
hLow = NormalizeDouble(MathRound(hLow / point) * point, Digits);
hHigh = NormalizeDouble(MathRound(hHigh / point) * point, Digits);

//Print(“hLow: ” + hLow);
//Print(“hHigh: ” + hHigh);

// 桧桷栲腓玷痼屐 爨耨桠 汨耱钽疣祆?
int hCount = hHigh/point – hLow/point + 1;
//Print(“hCount: ” + hCount);
ArrayResize(vh, hCount);
ArrayInitialize(vh, 0);

int iCount = m1BarFrom – m1BarTo + 1;
int hc = mql_GetHGByRates(rates, rCount, iCount, m1BarTo, tickMethod, point, hLow, hCount, vh);
//Print(“hc: ” + hc);

if (hc == hCount)
return(hc);
else
return(0);
}
else
{
//Print(“Error: no rates”);
return(0);
}
}

/// 项塍麒螯 汨耱钽疣祆?疣耧疱溴脲龛 鲥?耩邃耱忄扈 MQL (囗嚯钽 vlib_GetHGByRates
int mql_GetHGByRates(double& rates[][6], int rcount, int icount, int ishift, int tickMethod, double point,
double hLow, int hCount, double& vh[])
{
int pri; // 桧溴犟 鲥睇
double dv; // 钺?磬 蜩?

int hLowI = MathRound(hLow / point);
//Print(rcount);

for (int j = 0; j < icount; j++)
{
// 翳朦蝠 镱 怵屐屙?

//int i = rcount – 1 – j – ishift;
int i = j + ishift;

double o = rates[i][1];
int oi = MathRound(o/point);

double h = rates[i][3];
int hi = MathRound(h/point);

double l = rates[i][2];
int li = MathRound(l/point);

double c = rates[i][4];
int ci = MathRound(c/point);

double v = rates[i][5];

//Print(“oi: ” + oi);
//Print(“hLowI: ” + hLowI);
//Print(“oi-hLowI: ” + (oi-hLowI));
//Print(“rate: ” + v);

int rangeMin = hLowI;
int rangeMax = hLowI + hCount – 1;

if (tickMethod == 0) // 疣忭? 忮痤蝽铖螯 怦艴 鲥?徉疣
{
dv = v / (hi – li + 1.0);
for (pri = li; pri <= hi; pri++)
vh[pri – hLowI] += dv;
}
else if (tickMethod == 1) // 桁栩圉? 蜩觐?
{
if (c >= o) // 猁鼽 疋鬻?
{
dv = v / (oi – li + hi – li + hi – ci + 1.0);

for (pri = oi; pri >= li; pri–) // open –> low
vh[pri – hLowI] += dv;

for (pri = li + 1; pri <= hi; pri++) // low+1 ++> high
vh[pri – hLowI] += dv;

for (pri = hi – 1; pri >= ci; pri–) // high-1 –> close
vh[pri – hLowI] += dv;
}
else // 戾溻彐? 疋鬻?
{
dv = v / (hi – oi + hi – li + ci – li + 1.0);

for (pri = oi; pri <= hi; pri++) // open ++> high
vh[pri – hLowI] += dv;

for (pri = hi – 1; pri >= li; pri–) // high-1 –> low
vh[pri – hLowI] += dv;

for (pri = li + 1; pri <= ci; pri++) // low+1 ++> close
vh[pri – hLowI] += dv;
}
}
else if (tickMethod == 2) // 蝾朦觐 鲥睇 徉疣
{
dv = v / 4.0;
vh[oi – hLowI] += dv;
vh[hi – hLowI] += dv;
vh[li – hLowI] += dv;
vh[ci – hLowI] += dv;
}
else if (tickMethod == 3) // 蝾朦觐 踵??腩?
{
dv = v / 2.0;
vh[hi – hLowI] += dv;
vh[li – hLowI] += dv;
}
else if (tickMethod == 4) // 岩衔
{
dv = 1.0 / v;
if (c >= o) // 猁鼽 疋鬻?
{

for (pri = oi; pri >= li; pri–) // open –> low
vh[pri – hLowI] += dv;

for (pri = li + 1; pri <= hi; pri++) // low+1 ++> high
vh[pri – hLowI] += dv;

for (pri = hi – 1; pri >= ci; pri–) // high-1 –> close
vh[pri – hLowI] += dv;
}
else // 戾溻彐? 疋鬻?
{
for (pri = oi; pri <= hi; pri++) // open ++> high
vh[pri – hLowI] += dv;

for (pri = hi – 1; pri >= li; pri–) // high-1 –> low
vh[pri – hLowI] += dv;

for (pri = li + 1; pri <= ci; pri++) // low+1 ++> close
vh[pri – hLowI] += dv;
}
}

}

return(hCount);
}

/// 项塍麒螯 祛潲 磬 铖眍忮 汨耱钽疣祆??胥豚驽眄铋 汨耱钽疣祆?(猁耱瘥?戾蝾? 徨?胥豚骅忄龛)
int getModesIndexes(double& vh[], int modeStep, int& modes[]) //, int& maxModeIndex
{
int modeCount = 0;
ArrayResize(modes, modeCount);

int count = ArraySize(vh);

// 棂屐 爨犟桁箪?镱 篦囫蜿囔
for (int i = modeStep; i < count – modeStep; i++)
{
int maxFrom = i-modeStep;
int maxRange = 2*modeStep + 1;
int maxTo = maxFrom + maxRange – 1;

int k = ArrayMaximum(vh, maxRange, maxFrom);

if (k == i)
{
for (int j = i – modeStep; j <= i + modeStep; j++)
{
if (vh[j] == vh[k])
{
modeCount++;
ArrayResize(modes, modeCount);
modes[modeCount-1] = j;
}
}
}

}

return(modeCount);
}

/// 项塍麒螯 扈眢蜿?潆 玎溧眄钽?滂囡噻铐?(箨噻噱蝰 ?眍戾疣?徉痤?扈眢蝾?
int getRates(int barFrom, int barTo, double& rates[][6], double& ilowest, double& ihighest, int period)
{
// 镳邃镱腩骅蝈朦眍?(?爨犟桁嚯铄) 觐腓麇耱忸 扈眢蝾?
int iCount = barFrom – barTo + 1;

int count = ArrayCopyRates(rates, NULL, period);
if (GetLastError() == ERR_HISTORY_WILL_UPDATED)
{
return(0);
}
else
{
if (count >= barFrom – 1)
{
ilowest = iLow(NULL, period, iLowest(NULL, period, MODE_LOW, iCount, barTo));
ihighest = iHigh(NULL, period, iHighest(NULL, period, MODE_HIGH, iCount, barTo));
//Print(“ilowest:” + ilowest);
//Print(“ihighest:” + ihighest);
return(count);
}
else
{
return(0);
}
}
}

int smoothHG(double& vh[], int depth)
{
// 疣聒桊屐 爨耨桠 (礤钺躅滂祛 潆 觐痧尻蝽 疣聍弪钼)

int vCount = ArraySize(vh);

if (depth == 0)
return(vCount);

int newCount = vCount + 2 * depth;

// 皲忤汔屐 珥圜屙? ?玎眢?屐 踱铖螓
double th[];
ArrayResize(th, newCount);
ArrayInitialize(th, 0);

ArrayCopy(th, vh, depth, 0);

ArrayResize(vh, newCount);
ArrayInitialize(vh, 0);

// 镱耠邃钼囹咫铄 篑疱漤屙桢
for (int d = 0; d < depth; d++)
{
for (int i = -d; i < vCount + d; i++)
{
vh[i+depth] = (th[i+depth-1] + th[i+depth] + th[i+depth+1]) / 3.0;
}

ArrayCopy(th, vh);
}

ArrayResize(vh, vCount);
ArrayCopy(vh, th, 0, depth, vCount);

return(newCount);
}

如果你对文件有了解,请帮助投票!

If you are familiar with the file, please help vote!

平均评分 0 / 5. 投票数: 0

到目前为止还没有投票!成为第一位投票人。

相关资源

暂无评论

暂无评论...