EA_Cleopatra_v5_4

EA_Cleopatra_v5_4

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

43 人已下载 手机查看

EA_Cleopatra_v5_4 EA_Cleopatra_v5_4

//+骀骀骀骀骀骀骀骀骀骀骀骀骀骀骀骀骀骀骀骀骀骀骀骀骀骀骀骀骀骀骀骀骀骀+
//| === EA_Cleopatra v 4.9 === |*
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#property description “务钺? 犭嚆钿囵眍耱?玎 桎彖, 镱祛??耦玟囗梃 耦忮蝽桕?纛痼祗 MartinForex.ru”
#property description “橡钽疣祆桉蜞?Pyyx, Zaartu, SVG, Kordan”
#property description “杨忮蝽桕 蝠囗耵铕戾?溻篚 嚯泐痂蜢钼”
#property description “朽犷蜞 镱 镳桧鲨矬 祓蜩磴彘豚 || 朽犷蜞 镱 镳桧鲨矬 镨疣扈潲”
#property description “朽犷蜞 鬣耱梓睇??镱腠 腩觐?|| 朽犷蜞 溻篚 嚯泐痂蜢钼 钿眍怵屐屙眍”
#property description “玛?蔓? 钿眍泐 桤 嚯泐痂蜢钼 忸 怵屐 蝾疸钼”
#property description “如戾礤龛?蝾疸钼 镟疣戾蝠钼 忸 怵屐 蝾疸钼”
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//# property strict
#property copyright “Copyright ?EA_Cleopatra, SNAIKE”
#property link “http://ea-signal.com/proekt-cleopatra/”
//#property strict
//+——————————————————————+
//| #import |
//+——————————————————————+
#import “user32.dll”
int GetDC(int hWnd);
int ReleaseDC(int hWnd, int hDC);
#import “Gdi32.dll”
bool GetTextExtentPoint32A(int hdc, string lpString, int size, int& lpSize[]);
int CreateFontA(int nHeight,int nWidth,int nEscapement,int nOrientation,int fnWeight,int fdwItalic,int fdwUnderline,
int fdwStrikeOut,int fdwCharSet,int fdwOutputPrecision,int fdwClipPrecision,int fdwQuality,
int fdwPitchAndFamily,string lpszFace);
int SelectObject(int hdc,int hgdiobj);
bool DeleteObject(int hObject);
int GetDeviceCaps(int hdc,int nIndex);
#import

//+——————————————————————+
//| #define |
//+——————————————————————+
#define DEFAULT_CHARSET 1
#define OUT_DEFAULT_PRECIS 0
#define CLIP_DEFAULT_PRECIS 0
#define DEFAULT_QUALITY 0
#define DEFAULT_PITCH 0
#define FF_MODERN 48
#define LOGPIXELSX 88

//+——————————————————————+
//| extern variables |
//+——————————————————————+
extern bool Info = true; // 玛?桧滂赅鲨? 玮箨钼钽?耦镳钼铈溴龛 铗牮? 觐脲??镱漯钺眍泐 镳铗铌铍桊钼囗?
extern bool AutoDigits = false;// 逾咫梓桠囹?怦?镟疣戾蝠?玎溧忄屐 ?矬黻蜞??溴?螯 疣?(镟疣戾蝠 潆 闹 ?5-?珥嚓囔?觐蜩痤忸?
extern bool NewCycle_ON = true; // 橡?玎镳弪?- 鲨觌 漕疣徉螓忄弪? 漕 觐眦? 眍恹?鲨觌 礤 磬麒磬弪?
extern string I = “-=-^-=-^-=-^-=-^-=-^-=-^-=-^-=-^-=-^-=-^-=-^-=-“;
//+——————————————————————-
extern string T0 = “吾?蚁 阉”;
extern double DefaultProfit = 10; // 义殛 镳铘栩 朽聍栩噱蝰 ?矬黻蜞?铗 腓龛?徨?筢赅.
// 殃铍?眢骓?镳铋蜩 矬黻蝾?铗 腓龛?徨?筢赅 潆 玎牮? 铕溴痤?
extern double StopLoss = 100; // 橡?漕耱桄屙梃 赅觐泐 % 筢赅 ?忄膻蝈 溴镱玷蜞 玎牮?怦?铕溴疣.

//—————————————
extern string T1 = “吾?茵彘腓磴”;
extern bool Trall_on = true; // 玛?蔓觌. 妈痱筻朦眍泐 蝠彘腓磴 耱铒?
extern double Tral_Start = 5; // 朽耨蝾龛?磬鬣豚 蝠嚯?铗 腓龛?Profit ?矬黻蜞?(觌囫耔麇耜栝 蚁 ?矬黻蜞?.
extern double Tral_Size = 5; // 洛腓麒磬 蝠嚯?镱耠?Tral_Start ?矬黻蜞?
// 项塍鬣弪?, 镳铠咫 蝠嚯 ?矬黻蜞? 磬 5 矬黻蝾?腓龛 蚁
// 镱漕溻桧箅囫?蜞赕?磬 ?螯 矬黻蝾??蝈牦驽?鲥礤,
// 铗赅蜩豚顸 鲥磬 ?腓龛?蚁, 玎牮?怦?铕溴疣.
//—————————————
extern string T2 = “玉蜞眍怅?MM”;
extern double Risk = 0.1; // 襄疴? 皲咫赅 疣珈屦铎 ?% 铗 疋钺钿睇?耩邃耱?
// 羼腓 Risk=0 蝾 镥疴? 皲咫赅 铗牮噱蝰 疣珈屦铎 DefaultLot
extern double DefaultLot = 0.1; // 澡犟桊钼囗睇?腩? 羼腓 磬耱痤殛?Risk = 0
extern double MaxLot = 10; // 锑犟桁嚯?忸珈铈睇?腩?潆 蝾疸钼腓
extern bool FixLot = false;// 篷腓 TRUE, 蝾 翳犟桊钼囗睇?腩? 羼腓 FALSE ?滂磬扈麇耜栝 滂磬扈麇耜栝 腩?疣犷蜞弪 蝾朦觐
// 羼腓 镟痨弪?CCI_On = True, PiramidOn = false, ?蝾朦觐 潆 磬镳噔脲龛 爨痱桧沐殡
//—————————————
extern string T2_1 = “蔓犷?戾蝾溧 蝾疸钼腓”;
extern int Metod = 1; // 1 – 迈钿 ?瘥眍?玎礻铎 腩蝾?耦汶囫眍 篑蜞眍忸?烫.
// ?溧朦 疣犷蜞屐 ?玎忤耔祛耱?铗 磬耱痤尻 MartinOn PiramidOn. 枢赅 桤 龛?怅膻麇磬.
// 2 ?迈钿 ?瘥眍?玎礻铎 腩蝾?耦汶囫眍 篑蜞眍忸?烫.
// 泥脲?疣犷蜞屐 铗腩驽眄?铕溴疣扈. 翌驽 襦祛?黩??镥疴 忄痂囗?
// 蝾朦觐 镱 镳铛钿?镨锺蜩?铕溴疣 礤 铗牮噱?赅??镥疴铎 忄痂囗蝈,
// ?恹耱噔?弪 铗腩驽眄 铕溴疣 磬 疣耱?龛?箨噻囗眍??磬耱痤殛?
// Dist 铗 蝈牦?鲥睇.
//—————————————
extern string T3 = “相疣戾蝠?铗腩驽眄 铕溴痤?”;
extern double Dist = 3; // 疣耨蝾龛? 磬 觐蝾痤?恹耱噔?? 铗腩驽眄 铕溴疣
// 耦汶囫眍 镳铋溴眄钽?Pipstep. ??镳邃咫圊 觐蝾痤泐
// 铐?溴疰囹? 铗 鲥睇. 项塍鬣弪? 羼腓 禧 疣犷蜞屐 镱 戾蝾潴
// 蝾疸钼腓 ? 镱 镳铛钿?疣耱?龛 镨锺蜩?箨噻囗眍泐 ?磬耱痤殛圊
// MartinStep ?PiramidStep (?玎忤耔祛耱?黩?怅膻麇眍 锑痱桧 翔疣扈溧 桦?铐?钺?
// 恹耱噔?弪? 铗腩驽眄 铕溴?磬 疣耨蝾龛?3 矬黻蜞 铗 蝈牦?鲥睇.
extern double Step = 3; // ?镳铛钿?鲥睇 – 潆 镳铗骊?铕溴疣 玎 鲥眍? 蒡?黩?蝾 蜩镟 蝠嚯?铗腩骊?玎 鲥眍?
//—————————————
extern string T4 = “= 屠岩形墒?汤幸韧?=”;
extern bool MartinOn = true; // 玛? 恹觌. 疣犷螓 镱 戾蝾潴 锑痱桧沐殡?
extern double MartinStep = 20; // 剜??矬黻蜞?潆 铗牮? 耠邃簋泐 铕溴疣 镱 爨痱桧沐殡?
extern double MartinLotExponent = 1.4; // 添铈栩咫?腩蜞 潆 锑痱桧? 屿眍驽龛?镱耠邃簋?铕溴痤?桎簌桴 镳铗桠 瘥黻?
extern int Martin_TP = 0; // 义殛 镳铘栩 镨疣扈漤 铕溴痤? 羼腓 眍朦 蝾 蝈殛 镳铘栩 礤 桉镱朦珞弪?.
extern int MartinStopLoss = 0; // 朽珈屦 翳犟桊钼囗眍泐 耱铒?潆 赅驿钽?镨疣扈漤钽?铕溴疣. // 羼腓 0 蝾 蝾 耱铒 腩?礤 恹耱噔?弪?.
extern int Close_M_orders = 200; // 暑腓麇耱?铕溴痤?皴痂?镳?觐蝾痤?怦 皴痂 溧眄钽?磬镳噔脲龛 玎牮噱蝰
//———————————————————————
extern string t9=”袜耱痤殛?桧滂赅蝾疣 铗牮? ?耦镳钼铈溴龛”;
extern bool Vxod_M = false; // 怩钿 镱 桧滂赅蝾痼,0-铗觌
extern int TF_M = 2; // 以 桧滂赅蝾疣 0-蝈牦?以 沭圄桕? 1=?,2=?,3=?5,4=?0,5=?,6=?,7=D1,8=W1,9=MN1)
extern int Sensitivity_M = 40; // 磬耱痤殛?镥痂钿?桧滂赅蝾疣 (戾潆屙睇?

extern string t10=”~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~”;
extern bool Vxod_M2 = false; // 怩钿 镱 桧滂赅蝾痼,0-铗觌
extern int TF_M2 = 2; // 以 桧滂赅蝾疣 0-蝈牦?以 沭圄桕? 1=?,2=?,3=?5,4=?0,5=?,6=?,7=D1,8=W1,9=MN1)
extern int Sensitivity_M2 = 20; // 磬耱痤殛?镥痂钿?桧滂赅蝾疣 (戾潆屙睇?
//—————————————
extern string T5_9 = “铃珞猁蝾?潆 锑痱桧?”;
extern bool M_WL = false; // 玛膻麇龛? 铗觌屙桢 徨珞猁蜿?铕溴痤?
extern int M_BU_Start = 1; // ?赅觐忄 铕溴疣 龛麒磬螯 恹耱噔?螯 徨?筢铌
extern int M_WLstart = 30; // 悟牦溧 镥疱忸滂?(矬黻螓 镳铘栩?
extern int M_WLlevel = 1; // 鼠溧 镥疱忸滂?(矬黻螓 镳铘栩?
//—————————————
extern string T5_8 = “Trailing 徨珞猁蜿?锑痱桧?”;
extern bool M_Trailing = false; // 玛? 蝠彖腓磴?
extern int M_Trailing_Start = 1; // ?赅觐忄 铕溴疣 龛麒磬螯 蝠嚯栩?耱铒 腩?徨?筢赅.
extern int M_TrailingStop = 30; // 朽珈屦 蝠嚯??矬黻蜞?
extern int M_TrailingStep = 30; // 剜?蝠嚯??矬黻蜞?
//—————————————-
extern string T4_1 = “如戾礤龛?篑蜞眍忸?镱耠?N-泐 觐脲磬 锑痱桧?”;
extern bool MartinOnNew = false;// 锐镱朦珙忄螯 腓 怅膻麇龛?疣犷螓 磬镳噔脲龛 锑痱桧?镱耠?N-泐 觐脲磬.
extern int LotNoM = 20; // 项耠?漕耱桄屙? 钽?觐脲磬 磬镳噔脲龛?锑痱桧?镳尻疣弪 疋铪
// 疣犷蝮 羼腓 MartinOnNew =true
extern int LotN_M = 3; // ?赅觐泐 觐脲磬 眢骓?桤戾龛螯 磬耱痤殛?锑痱桧?
extern double MartinLotExponenNew=1.5;// 暑翳鲨屙?筲咫梓屙? 腩蜞
extern double MartinStepNew = 20; // 剜?铗牮? 觐脲??矬黻蜞?
extern double MartinK_Step = 1.2; // 觐翳鲨屙?疣聒桊屙? 汔 戾驿?铗牮桢?镱耠邃簋?铕溴痤? 0 铗觌屙?
//—————————————
extern string l = “-=-^-=-^-=-^-=-^-=-^-=-^-=-^-=-^-=-^-=-^-=-^-=-“;
extern string T5 = “= 屠岩形墒?先欣倘嫩 =”;
extern bool PiramidOn = false;// 玛?恹觌. 镱 戾蝾潴 翔疣扈潲.
extern double PiramidStart = 2; // 橡?漕耱桄屙梃 赅觐?镳铖噤觇 ?% 镳铞屙蜞? 怅膻麒螯 磬镳噔脲龛?镨疣扈潲.
extern double Persen_open = 30; // 枢觇?镳铞屙蝾?铗 铖眍忭铋 皴痂?爨痱桧?铗牮?耠邃簋?铕溴?镨疣扈潲 镳?甯 怅膻麇龛?
extern double PiramidStep = 20; // 剜??矬黻蜞?潆 铗牮? 耠邃簋泐 铕溴疣 镨疣扈潲.
extern double PiramidLotExponent = 1.4;// 添铈栩咫?腩蜞 潆 镨疣扈潲.
extern int Piramid_TP = 0; // 义殛 镳铘栩 镨疣扈漤 铕溴痤? 羼腓 眍朦 蝾 蝈殛 镳铘栩 礤 桉镱朦珞弪?.
extern int PiramidStopLoss = 0; // 朽珈屦 翳犟桊钼囗眍泐 耱铒?潆 赅驿钽?镨疣扈漤钽?铕溴疣.羼腓 0 蝾 蝾 耱铒 腩?礤 恹耱噔?弪?
extern bool UseRevers = false; // 玛膻麇龛?疱忮瘃?
extern double PiramidRevers = 10; // 橡铞屙?镳铖噤觇 磬镳噔脲龛 潆 耩噌囹囗? 疱忮瘃?
extern int Close_P_orders= 200; // 暑腓麇耱?铕溴痤?皴痂?镳?觐蝾痤?怦 皴痂 溧眄钽?磬镳噔脲龛 玎牮噱蝰.

extern string t91=”袜耱痤殛?桧滂赅蝾疣 铗牮? ?耦镳钼铈溴龛”;
extern bool Vxod_P = false; // 怩钿 镱 桧滂赅蝾痼,0-铗觌
extern int TF_P = 2; // 以 桧滂赅蝾疣 0-蝈牦?以 沭圄桕? 1=?,2=?,3=?5,4=?0,5=?,6=?,7=D1,8=W1,9=MN1)
extern int Sensitivity_P = 40; // 磬耱痤殛?镥痂钿?桧滂赅蝾疣 (戾潆屙睇?
//—————————————
extern string t99=”~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~”;
extern bool Vxod_P2 = false; // 怩钿 镱 桧滂赅蝾痼,0-铗觌
extern int TF_P2 = 2; // 以 桧滂赅蝾疣 0-蝈牦?以 沭圄桕? 1=?,2=?,3=?5,4=?0,5=?,6=?,7=D1,8=W1,9=MN1)
extern int Sensitivity_P2 = 20; // 磬耱痤殛?镥痂钿?桧滂赅蝾疣 (戾潆屙睇?
//—————————————
//—————————————
extern string T6 = “铃珞猁蝾?潆 翔疣扈潲”;
extern bool P_WL = true; // 玛膻麇龛? 铗觌屙桢 徨珞猁蜿?铕溴痤?
extern int P_BU_Start = 1; // ?赅觐忄 铕溴疣 龛麒磬螯 恹耱噔?螯 徨?筢铌
extern int P_WLstart = 30; // 悟牦溧 镥疱忸滂?(矬黻螓 镳铘栩?
extern int P_WLlevel = 1; // 鼠溧 镥疱忸滂?(矬黻螓 镳铘栩?
//—————————————
extern string T7 = “Trailing 徨珞猁蜿?翔疣扈潲”;
extern bool P_Trailing = true; // 玛? 蝠彖腓磴?
extern int P_Trailing_Start= 1; // ?赅觐忄 铕溴疣 龛麒磬螯 蝠嚯栩?耱铒 腩?徨?筢赅.
extern int P_TrailingStop = 30; // 朽珈屦 蝠嚯??矬黻蜞?
extern int P_TrailingStep = 30; // 剜?蝠嚯??矬黻蜞?
//—————————————
extern string T8 = “如戾礤龛?篑蜞眍忸?镱耠?N-泐 觐脲磬 翔疣扈潲”;
extern bool PiramidOnNew = false;// 锐镱朦珙忄螯 腓 怅膻麇龛?疣犷螓 磬镳噔脲龛 镨疣扈潲 镱耠?N-泐 觐脲磬
extern int LotNoP = 20; // 项耠?漕耱桄屙? 钽?觐脲磬 磬镳噔脲龛?镨疣扈潲
// 镳尻疣弪 疋铪 疣犷蝮 羼腓 PiramidOnNew =true
extern int LotN_P = 3; // ?赅觐泐 觐脲磬 眢骓?桤戾龛螯 磬耱痤殛?
extern double PiramidLotExponenNew = 1.5;// 暑翳鲨屙?筲咫梓屙? 腩蜞
extern double PiramidStepNew= 20; // 剜?铗牮? 觐脲??矬黻蜞?
// 溧眄钽?磬镳噔脲龛 耦汶囫眍 镥疱戾眄铋 PiramidStart = 5
//—————————————
string T8_1 = “青牮桢 埋蝠鬻睇?”;
bool CloseBy = false;// 篷腓 TRUE, 蝾 青牮桢 埋蝠鬻睇?铕溴痤? 羼腓 FALSE ?玎牮桢 钺眍;
//—————————————
extern string T9 = “袜耱痤殛?桧滂赅鲨?”;
extern int PositionX = 10; // 项腩驽龛?桧滂赅蜩忭钽?犭铌?镱 铖??铗 镳噔铋 耱铕铐?沭圄桕?
extern int PositionY = 15; // 项腩驽龛?桧滂赅蜩忭钽?犭铌?镱 铖?Y 铗 忮瘐礤?耱铕铐?沭圄桕?
extern int FontSize = 9; // 朽珈屦 梏蜞 ?桧滂赅蜩忭铎 犭铌?
extern color BULineColor = clrYellow; // 肘弪 腓龛?徨珞猁蜿?
extern color TPLineColor = clrGray; // 肘弪 腓龛?蚁
extern color TralLineColor = clrDarkOrange; // 肘弪 腓龛?茵嚯?
extern color BuyStopColor = clrDeepSkyBlue; // 肘弪 铗腩骊?磬 镱牦镪?
extern color SellStopColor = clrRed; // 肘弪 铗腩骊?磬 镳钿噫?
extern color StartBPriceColor = clrHotPink;
extern color StartSPriceColor = clrPink;
//—————————————
extern string T10 = “吾?磬耱痤殛?”;
extern int MagicMartin = 777; // 禹桕嚯 眍戾?爨痱桧?
extern int MagicPiramid = 888; // 禹桕嚯 眍戾?翔疣扈潲
int MagicRuchnik = 000005555; // 禹桕嚯 眍戾?畜黜钽?铕溴疣
extern int PauseTrade = 6; // 吗屐 铈桎囗? 戾驿?蝾疸钼?觐爨礓囔??皴?
extern int PauseTrade2 = 1; // 吗屐 铈桎囗? 镱耠?恹躅溧 ?瘥黻? 漕 眍忸泐 怩钿??瘥眍??扈眢蜞?
extern int Slippege = 2; // 念矬耱桁铄 镳铖赅朦琨忄龛?鲥睇 ?矬黻蜞?镳?铗牮梃 铕溴疣
extern double Test_com_in_pip = 0.5; // 相疣戾蝠 潆 篦弪?觐扈耨梃 ?蝈耱屦?耱疣蝈汨?(?铐豚轫 疱骅戾 疣聍弪?噔蝾爨蜩麇耜桢)
//—————————————
extern string T11 = “玉蜞眍怅?CCI”;
extern bool CCI_On = false;// 篷腓 – true ?镟疣戾蝠 PiramidOn = false 蝾 镱耠?怩钿??瘥眍?耠邃簋?觐脲龛 爨痱桧?
// 恹耱噔?? 镱 耔沩嚯?CCI, 羼腓 false 蝾 镱耠?镳铛钿?MartinStep
extern int CCI_TimeFrame = 2; // 以 CCI(0-蝈牦?以 沭圄桕? 1=?,2=?,3=?5, 4=?0,5=?, 6=?,7=D1,8=W1,9=MN1)
extern double Level = 100; // 羽钼屙?CCI
extern int Period_CCI = 14; // 襄痂钿 CCI
//—————————————
extern string T12 = “吗屐 疣犷螓 耦忮蝽桕?”;
extern string StartHour = “00:00”; // 吗屐 磬鬣腩 蝾疸钼腓
extern string EndHour = “23:59”; // 吗屐 铌铐鬣龛 蝾疸钼腓
//—————————————
extern string T13 = “捻?礤溴腓 疣犷螓 耦忮蝽桕?”;
extern bool Trade_in_Monday =true; //翌疸钼囹??项礤溴朦龛?
extern bool Trade_in_Tuesday =true; //翌疸钼囹??买铕龛?
extern bool Trade_in_Wednesday=true;//翌疸钼囹??佯邃?
extern bool Trade_in_Thursday=true; //翌疸钼囹??族蜮屦?
extern bool Trade_in_Friday =true; //翌疸钼囹???蝽桷?

 

//+——————————————————————+
//| global variables |
//+——————————————————————+

string sPref = “Cleopatra_”; // 橡弭桕?沭圄梓羼觇?钺牝钼
string sPrefIndPan = “CleoInfoPan_”; // 橡弭桕?沭圄梓羼觇?钺牝钼 ?桧纛痨圉桀眄铋 镟礤腓
int iDigitLot = 0; // 暑?忸 珥嚓钼 镱耠?玎?蝾??珥圜屙梃 腩蜞
bool isWorking = true; // 噪嚆 箨噻噱?磬 忸珈铈眍耱?镳钿铍驽龛 蝾疸钼腓
int iTicket = -1; // 诣赍?铕溴疣 镱耠?铠栳觇
bool PiramidAutoStart = false; // 雨噻噱?磬 怅膻麇龛?镨疣扈潲 镳?漕耱桄屙梃 玎溧眄铋 镳铖噤觇
double PiramidStartLot = 0.0;

double MBuyStop = 0.0; // 皱磬 铗牮? 铕溴疣 martin BuyStop
double MBuyStopLot = 0.0;// 祟?铕溴疣 martin BuyStop
int MBuyStopNumb = 0.0; // 皖戾?铕溴疣 martin BuyStop

double MSellStop = 0.0; // 皱磬 铗牮桢 铕溴疣 martin SellStop
double MSellStopLot = 0.0;// 祟?铕溴疣 martin BuyStop
int MSellStopNumb = 0.0; // 皖戾?铕溴疣 martin BuyStop

double PBuyStop = 0.0; // 皱磬 铗牮? 铕溴疣 piramid BuyStop
double PBuyStopLot = 0.0;// 祟?铕溴疣 piramid BuyStop
int PBuyStopNumb = 0.0; // 皖戾?铕溴疣 piramid BuyStop
double PBuyStopStopLoss = 0.0; // 朽珈屦 耱铒腩耨 piramid BuyStop
double PBuyStopTakeProfit = 0.0; // 朽珈屦 蝈殛镳铘栩 piramid BuyStop
double MBuyStopStopLoss = 0.0; // 朽珈屦 耱铒腩耨 martin BuyStop
double MBuyStopTakeProfit = 0.0; // 朽珈屦 蝈殛镳铘栩 martin BuyStop

double PSellStop = 0.0; // 皱磬 铗牮桢 铕溴疣 piramid SellStop
double PSellStopLot = 0.0;// 祟?铕溴疣 piramid SellStop
int PSellStopNumb = 0.0; // 皖戾?铕溴疣 piramid SellStop
double PSellStopStopLoss = 0.0; // 朽珈屦 耱铒腩耨 piramid SellStop
double PSellStopTakeProfit = 0.0; // 朽珈屦 蝈殛镳铘栩 piramid SellStop
double MSellStopStopLoss = 0.0; // 朽珈屦 耱铒腩耨 martin SellStop
double MSellStopTakeProfit = 0.0; // 朽珈屦 蝈殛镳铘栩 martin SellStop

double TralStartPrice = 0.0; // 皱磬 ?觐蝾痤?磬黜弪? 蝠彘腓磴 铕溴痤?
double TralPrice = 0.0; // 义牦?箴钼屙?腓龛?蝠彘腓磴?
int TralType = 0; // 诣?铕溴痤?玎牮噱禧?镱 蝠嚯?

string FontName = “Arial”; // 袜玮囗桢 梏蜞 ?桧滂赅蜩忭铎 犭铌?犭铌?
color BaseColor = clrWhite;

int DC_hWnd = 0;
int DC_hFont = 0;
int DC_hnd = 0;

bool StopMartin = false;
bool StopPiramid = false;
double AveregeLine = 0.0;
double TPLine = 0.0;
bool CommentSet = false;
double OpenLot = 0.0;
bool InitDC = false;

double dMartinStopLoss = 0.0;
double dMartinTP = 0.0;
//———————————-
double dPiramidStopLoss = 0.0;
double dPiramidTP = 0.0;
double dP_WLstart = 0.0;
double dP_WLlevel = 0.0;
double dP_TrailingStop = 0.0;
double dP_TrailingStep = 0.0;
//——————————–
double dM_WLstart = 0.0;
double dM_WLlevel = 0.0;
double dM_TrailingStop = 0.0;
double dM_TrailingStep = 0.0;

//— 铒疱溴脲龛?綦嚆钼
int Buy_flag = 0;
int Sell_flag = 0;
int martin_flag=1, piramid_flag=2;
int Magic_martin = 0;
int Magic_piramid = 0;

//—

bool err;
double Lot2,LotR,StartSPrice,StartBPrice,Martin_On;
int shiftGraph=4,Sl_tp_close_flag,ordTotal,hwnd,M_buybtn,P_buybtn,lottxt,P_sellbtn,M_sellbtn,closesellbtn,closebtn,closebuybtn,totalord,totalbuy,totalsell,tick2;
string Symb,comment;

//+——————————————————————+
//| expert initialization function |
//+——————————————————————+
int OnInit()

{
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// 视盐?饰睦 乃?蚊欣腿着腿?盐屡彝仁?欣廖役 衔 滦盘磐?屠 信浪芡翁 炎乓?
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

if(!IsTesting() && !IsOptimization())
{
if(IsDemo()==false)// 耦忮蝽桕 疣犷蜞弪 蝾朦觐 磬 溴祛 聍弪?
{
if(TimeCurrent()>StrToTime(“2065.01.01 00:00”))// 钽疣龛麇龛?痤犷螓 耦忮蝽桕?镱 怵屐屙?
{
Alert(“佯铌 痤犷螓 耦忮蝽桕?磬 疱嚯 聍弪? 桉蝈”,
“耦忮蝽桕 祛驽?疣犷蜞螯 蝾朦觐 ?疱骅戾 蝈耱?桦?磬 溴祛 聍弪”);
return(0);
}
}
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// 青蜞 铗 镥疱桁屙钼囗? 耦忮蝽桕?
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
string name = WindowExpertName();
if(name != “EA_Cleopatra_v5_4”){
Alert(“浪咝?!! 杨忮蝽桕 镥疱桁屙钼囗! – 埋?嚯泐痂蜢?玎犭铌桊钼囗?!!”);
Sleep(10000);
Alert(“-洛痦?桉躅漤铄 磬玮囗桢 耦忮蝽桕?!!-“);

return(0);
}

if(AutoDigits && (Digits == 5 || Digits == 3)){
DefaultProfit *= 10;
Tral_Start *= 10;
Tral_Size *= 10;
Dist *= 10;
Step *= 10;
MartinStep *= 10;
M_WLstart *= 10;
M_WLlevel *= 10;
M_TrailingStop *= 10;
M_TrailingStep *= 10;
MartinStepNew *= 10;
PiramidStep *= 10;
PiramidStopLoss *= 10;
Piramid_TP *= 10;
MartinStopLoss *= 10;
Martin_TP *= 10;
P_WLstart *= 10;
P_WLlevel *= 10;
P_TrailingStop *= 10;
P_TrailingStep *= 10;
PiramidStepNew *= 10;
Test_com_in_pip *= 10;
shiftGraph *= 10;
}
//— 汶钺嚯 镥疱戾眄 铗耠彐桠囗? 爨滏桕钼
if (GlobalVariableCheck(“M_piramid”) && GlobalVariableCheck(“M_martin”)) {
Magic_martin = GlobalVariableGet(“M_martin”);
Magic_piramid = GlobalVariableGet(“M_piramid”);
} else {
GlobalVariableSet(“M_martin”, MagicMartin);
GlobalVariableSet(“M_piramid”, MagicPiramid);
Magic_martin = MagicMartin;
Magic_piramid = MagicPiramid;
}
if (GlobalVariableGet(“Buy_flag”) && GlobalVariableGet(“Sell_flag”)) {
Buy_flag = GlobalVariableGet(“Buy_flag”);
Sell_flag = GlobalVariableGet(“Sell_flag”);
}

//—
iDigitLot = InfoGetLotDigit(_Symbol);
DeleteObject();
Symb = Symbol();

//—- 镳钼屦赅 忖邃屙睇?镱朦珙忄蝈脲?溧眄
if(DefaultProfit < 0.0) DefaultProfit = 0.0;
if(StopLoss < 0.0) StopLoss = 0.0;
//if(StopLoss > AccountEquity()) Alert(“羽钼屙?StopLoss 镳邂噱?疣珈屦 疋钺钿睇?耩邃耱?磬 聍弪?”);
if(Tral_Start < 0.0) Tral_Start = 0.0;
if(Tral_Size < 0.0) Tral_Size = 0.0;
if(Risk < 0.0) Risk = 0.0;
if(Metod < 1){ Alert(“湾镳噔桦?箨噻囗 戾蝾? 桤戾礤眍 磬 戾蝾??1”);Metod = 1; }else if(Metod > 2){ Alert(“湾镳噔桦?箨噻囗 戾蝾? 桤戾礤眍 磬 戾蝾??2”);Metod = 2; }
if(Dist < 1.0) Dist = 1.0;
if(Step < 1.0) Step = 1.0;
if(MartinStep < 1.0) MartinStep = 1.0;
if(MartinLotExponent < 0.0) MartinLotExponent = 1.0;
if(Slippege < 0) Slippege = 0;
if(MaxLot > MarketInfo(_Symbol,MODE_MAXLOT)) MaxLot = MarketInfo(_Symbol,MODE_MAXLOT);
if(Close_M_orders < 0) Close_M_orders = 0;
if(PiramidStopLoss < 0) PiramidStopLoss = 0;
if(Piramid_TP < 0) Piramid_TP = 0;

if(M_BU_Start< 0) M_BU_Start= 0.0;
if(M_WLlevel < 0) M_WLlevel = 0.0;
if(M_WLstart < 0) M_WLstart = 0.0;
if(M_Trailing_Start< 0) M_Trailing_Start= 0.0;
if(M_TrailingStop < 0) M_TrailingStop = 0.0;
if(M_TrailingStep < 0) M_TrailingStep = 0.0;
//————————————-

if(P_BU_Start< 0) P_BU_Start= 0.0;
if(P_WLlevel < 0) P_WLlevel = 0.0;
if(P_WLstart < 0) P_WLstart = 0.0;
if(P_Trailing_Start< 0) P_Trailing_Start= 0.0;
if(P_TrailingStop < 0) P_TrailingStop = 0.0;
if(P_TrailingStep < 0) P_TrailingStep = 0.0;

switch(CCI_TimeFrame){
case 1: CCI_TimeFrame = PERIOD_M1; break;
case 2: CCI_TimeFrame = PERIOD_M5; break;
case 3: CCI_TimeFrame = PERIOD_M15; break;
case 4: CCI_TimeFrame = PERIOD_M30; break;
case 5: CCI_TimeFrame = PERIOD_H1; break;
case 6: CCI_TimeFrame = PERIOD_H4; break;
case 7: CCI_TimeFrame = PERIOD_D1; break;
case 8: CCI_TimeFrame = PERIOD_W1; break;
case 9: CCI_TimeFrame = PERIOD_MN1; break;
default: CCI_TimeFrame = 0;
}

if(MartinOn && PiramidOn) CCI_On = false;

//—- 觐礅屦蜞鲨 溧眄睇?
InfoChangeToDigit(_Symbol, DefaultProfit);
InfoChangeToDigit(_Symbol, Tral_Start);
InfoChangeToDigit(_Symbol, Tral_Size);
DefaultLot = InfoNormalizeVolume(_Symbol, DefaultLot);
InfoChangeToDigit(_Symbol, Dist);
InfoChangeToDigit(_Symbol, Step);
InfoChangeToDigit(_Symbol, MartinStep);
InfoChangeToDigit(_Symbol, MartinStepNew);
InfoChangeToDigit(_Symbol, PiramidStep);
InfoChangeToDigit(_Symbol, PiramidStepNew);
PiramidAutoStart = PiramidOn;

dPiramidStopLoss = PiramidStopLoss;
InfoChangeToDigit(_Symbol, dPiramidStopLoss);
dPiramidTP = Piramid_TP;
InfoChangeToDigit(_Symbol, dPiramidTP);

dMartinStopLoss = MartinStopLoss;
InfoChangeToDigit(_Symbol, dMartinStopLoss);
dMartinTP = Martin_TP;
InfoChangeToDigit(_Symbol, dMartinTP);

//dM_BU_Start = M_BU_Start;
//InfoChangeToDigit(_Symbol, dM_BU_Start);
//—————————————–
dM_WLstart = M_WLstart;
InfoChangeToDigit(_Symbol, dM_WLstart);
//—————————————–
dM_WLlevel = M_WLlevel;
InfoChangeToDigit(_Symbol, dM_WLlevel);
//—————————————–
dM_TrailingStop = M_TrailingStop;
InfoChangeToDigit(_Symbol, dM_TrailingStop);
//—————————————-
dM_TrailingStep = M_TrailingStep;
InfoChangeToDigit(_Symbol, dM_TrailingStep);
//–++++++++++++++++++++++++++++++++++++++++++—————————————
//dP_BU_Start = P_BU_Start;
//InfoChangeToDigit(_Symbol, dP_BU_Start);
//———–
dP_WLstart = P_WLstart;
InfoChangeToDigit(_Symbol, dP_WLstart);
dP_WLlevel = P_WLlevel;
InfoChangeToDigit(_Symbol, dP_WLlevel);
dP_TrailingStop = P_TrailingStop;
InfoChangeToDigit(_Symbol, dP_TrailingStop);
dP_TrailingStep = P_TrailingStep;
InfoChangeToDigit(_Symbol, dP_TrailingStep);

//—- 吾眢腓?溧眄 钺 铕溴疣?觐蝾瘥?眢骓?铗牮?铗腩驽眄 铕溴痤?
MBuyStop = 0.0;
MBuyStopLot = 0.0;
MBuyStopNumb= 0.0;

MSellStop = 0.0;
MSellStopLot = 0.0;
MSellStopNumb= 0.0;

PBuyStop = 0.0;
PBuyStopLot = 0.0;
PBuyStopNumb= 0.0;
PBuyStopStopLoss = 0.0;
PBuyStopTakeProfit = 0.0;
MBuyStopStopLoss = 0.0;
MBuyStopTakeProfit = 0.0;

PSellStop = 0.0;
PSellStopLot = 0.0;
PSellStopNumb= 0.0;
PSellStopStopLoss = 0.0;
PSellStopTakeProfit = 0.0;
MSellStopStopLoss = 0.0;
MSellStopTakeProfit = 0.0;
Martin_On = MartinOn;
//—- 橡钼屦赅 铗觌屙?桦?礤?
if(IsExpertEnabled()){
//—- 羼腓 箧?羼螯 玎矬眄? 皴痂 – 镳钿铍驽龛螯 祛龛蝾痂磴 桦?玎矬耱栩?眍怏?皴痂?
int _martin_cnt = OrdersGetCount(_Symbol, 99, Magic_martin, “”, 0, 0);
int _piramid_cnt = OrdersGetCount(_Symbol, 99, Magic_piramid, “”, 0, 0);
if(_martin_cnt+_piramid_cnt == 0){
// 橡钼屦桁 疣琊屮屙?腓 蝾疸钼? 皴轺囫
if (TimeFilter())

{
// 项漕驿屐 玎溧眄铌 觐?忸 皴牦礓
/*Comment(“杨忮蝽桕 玎矬? 念 铗牮? 铖蜞腩顸 “+DoubleToStr(PauseTrade,0)+” 皴?”);
Sleep(PauseTrade*1000);
Comment(“”);
//
SendOrder(OP_BUY, GetLot(), Ask, Magic_martin, “0:start”);
Comment(“念 铗牮? 怛铕钽?铕溴疣 铖蜞腩顸 “+DoubleToStr(PauseTradezamok,0)+” 扈?”);
Sleep(PauseTradezamok*60000);
Comment(“”);
SendOrder(OP_SELL, GetLot(), Bid, Magic_martin, “0:start”);*/

//— 钺眢脲龛?镥疱戾眄 镥疱?磬鬣腩?疣犷螓
GlobalVariableSet(“M_martin”, MagicMartin);
GlobalVariableSet(“M_piramid”, MagicPiramid);
Magic_martin = MagicMartin;
Magic_piramid = MagicPiramid;
Buy_flag = 0;
Sell_flag = 0;
GlobalVariableSet(“Buy_flag”,Buy_flag);
GlobalVariableSet(“Sell_flag”,Sell_flag);
//—
StartSPrice = Bid;
StartBPrice = Ask;
GlobalVariableSet(“StartSPrice”,StartSPrice);
GlobalVariableSet(“StartBPrice”,StartBPrice);
//—
}else{
Comment(“杨忮蝽桕 玎矬? 翌疸钼? ?蝈牦?怵屐 玎镳妁屙?”);
CommentSet = true;
}
} else {
StartSPrice = GlobalVariableGet(“StartSPrice”);
StartBPrice = GlobalVariableGet(“StartBPrice”);
}

}
//—-
GetDCWithFontNameAndSize(FontName, FontSize);
//—-

return(INIT_SUCCEEDED);
}

//+——————————————————————+
//| expert deinitialization function |
//+——————————————————————+
void OnDeinit(const int reason)
{
//—-
GraphDelete(sPref);
GraphDelete(sPrefIndPan);
if(CommentSet){ Comment(“”); CommentSet = false; }
//—-

DCRelease();
InitDC = false;
//—-

}

//+——————————————————————+
//| expert start function |
//+——————————————————————+
void OnTick()
{

//===============================================================================================
int _order_number=0;
// 橡钼屦赅 綦嚆?疣犷螓 镱耠?镱耠邃礤泐 玎牮? 皴痂?- 玎忤耔?铗 镟疣戾蝠?NewCycle_ON
if(isWorking){
// 橡钼屦赅 觐?忄 铗牮 铕溴痤?
int _martin_cnt = OrdersGetCount(_Symbol, 99, Magic_martin, “”, 0, 0);
int _piramid_cnt = OrdersGetCount(_Symbol, 99, Magic_piramid, “”, 0, 0);
ordTotal = _martin_cnt+_piramid_cnt;
if(ordTotal == 0 && ((StartSPrice <= 0 && StartBPrice <= 0) || (Sl_tp_close_flag && isCloseLastPos()))){

// 橡钼屦桁 疣琊屮屙?腓 蝾疸钼? 皴轺囫
if(TimeFilter()){
if(IsExpertEnabled()){
if(CommentSet){ Comment(“”); CommentSet = false; }
// 篷腓 铗牮 铕溴痤?礤?- 玎矬耱桁 镥疴铐圜嚯 玎祛?
/*SendOrder(OP_BUY, GetLot(), Ask, Magic_martin, “0:start”);
Comment(“念 铗牮? 怛铕钽?铕溴疣 铖蜞腩顸 “+DoubleToStr(PauseTradezamok,0)+” 扈?”);
Sleep(PauseTradezamok*60000);
Comment(“”);
SendOrder(OP_SELL, GetLot(), Bid, Magic_martin, “0:start”);*/

//— 钺眢脲龛?镥疱戾眄 镱耠?玎牮? 怦艴 铕溴痤?
GlobalVariableSet(“M_martin”, MagicMartin);
GlobalVariableSet(“M_piramid”, MagicPiramid);
Magic_martin = MagicMartin;
Magic_piramid = MagicPiramid;
Buy_flag = 0;
Sell_flag = 0;
GlobalVariableSet(“Buy_flag”,Buy_flag);
GlobalVariableSet(“Sell_flag”,Sell_flag);
//—
Sleep(PauseTrade*1000);
StartSPrice = Bid;
StartBPrice = Ask;
GlobalVariableSet(“StartSPrice”,StartSPrice);
GlobalVariableSet(“StartBPrice”,StartBPrice);
//StartPrice = Bid;
Martin_On = MartinOn;
Sl_tp_close_flag = false;
}
}else{
if(AveregeLine > 0.0) AveregeLine = 0.0;
}
// 谚眭痤龛玷痼屐 桉镱朦珙忄龛?镨疣扈潲 ?镱腩驽龛屐 觐蝾痤?玎溧眍 镱朦珙忄蝈脲?
PiramidAutoStart = PiramidOn;
PiramidStartLot = 0.0;
StopMartin = false;
StopPiramid = false;
}else{
if (ordTotal > 0) Sl_tp_close_flag = true;
//———————————-
// 橡钼屦赅 磬 礤钺躅滂祛耱?玎牮? 皲咫铌 镳?漕耱桄屙梃 玎溧眄钽?StopLoss ?忄膻蝈 溴镱玷蜞
if(!CloseByStopLoss()){
//———————————-
// 橡钼屦赅 磬 玎牮桢 镱 蚁 桦?镱 茵彘腓磴?
if(!CloseByTPAndTral()){
//———————————-
// 橡钼屦赅 磬 忸珈铈眍耱?怅膻麇龛 镨疣扈潲 镳?漕耱桄屙梃 玎溧眄铋 镳铖噤觇 ?镳铞屙蜞?
EnablePiramid();
//———————————-
// 项?蜩汨忄龛?忤痱筻朦眍泐 铗腩驽眄钽?铕溴疣
TrailVirtPendOrd();
// 悟牮桢 忤痱筻朦睇?铗腩驽眄 铕溴痤?
OpenVirtPendOrd();
//———————————-
// 项塍麒?桧纛痨圉棹 ?镱耠邃礤?铗牮铎 Sell 铕溴疱
double dSellInfo[]; string sSellInfo[];
bool _sell_opened = OrdersGetLastOpenInfo(_Symbol, OP_SELL, 99, “”, dSellInfo, sSellInfo);
//项塍麒?桧纛痨圉棹 ?镱耠邃礤?铗牮铎 Buy 铕溴疱
double dBuyInfo[]; string sBuyInfo[];
bool _buy_opened = OrdersGetLastOpenInfo(_Symbol, OP_BUY, 99, “”, dBuyInfo, sBuyInfo);
//———————————-
// 橡钼屦赅 磬 礤钺躅滂祛耱?疱忮瘃?
if (UseRevers) ReversPiramid(dSellInfo[7], dBuyInfo[7]);
//———————————-
if(_sell_opened || StartSPrice > 0){
// 玉蜞眍怅?徨珞猁蜿?铕溴痤?镨疣扈潲
PiramidBE(OP_SELL);
// 玉蜞眍怅?徨珞猁蜿?铕溴痤?爨痱桧?
MartinBE(OP_SELL);
// 茵彘腓磴 铕溴痤?爨痱桧?
MartinTrailing(OP_SELL);
// 茵彘腓磴 铕溴痤?镨疣扈潲
PiramidTrailing(OP_SELL);
// 项塍麇龛 眍戾疣 镳邃簌邈?铕溴疣
_order_number = StrToInteger(StringSubstr(sSellInfo[1],0,StringFind(sSellInfo[1],”:”)));
// 橡钼屦赅 – 祛骓?腓 铗牮囹?爨痱桧 铕溴疣

if(Martin_On && (Sell_flag == martin_flag || (StartSPrice > 0 && _order_number == 0 && Bid – StartSPrice >= MartinStep)/*StringFind(sSellInfo[1],”:start”)>-1*/)
/*((StringFind(sSellInfo[1],”:start”)>-1 || StringFind(sSellInfo[1],”:martin”)>-1) &&
(!_buy_opened || StringFind(sBuyInfo[1],”:martin”)==-1))*/)
{
// 橡钼屦赅 磬 铗觌屙桢 疣犷螓 爨痱桧?镱耠?漕耱桄屙? 玎溧眄钽?觐?忸 觐脲?
if(!fStopMartin(_order_number)){
// 橡钼屦赅 – 漕耱桡眢蝾 腓 玎溧眄铄 觐?忸 矬黻蝾?潆 铗牮? 爨痱桧 铕溴疣
//if(NormalizeDouble(Bid-dSellInfo[3],Digits) >= GetMartinStepPip(_order_number)){
if(GetSignal(OP_SELL, dSellInfo[3], _order_number) || _order_number == 0){
// 橡钼屦赅 磬 玎牮桢 铕溴痤?觐沅?漕耱桡眢蝾 铗牮桢 玎溧眄钽?觐?忸 铕溴痤?
if(Close_M_orders==0 || !CheckOpenOrdCnt(OP_SELL,_order_number)){
// 疣聍弪?腩蜞 觐蝾瘥?眢骓?铗牮?
OpenLot = GetLot(2, dSellInfo[6], _order_number, Bid-dSellInfo[3], GetMartinStepPip(_order_number));
// 悟牮桢 爨痱桧 铕溴疣 ?玎忤耔祛耱?铗 戾蝾溧
if(((M()==-1 && Vxod_M==1) || Vxod_M==0) && ((M2()==-1 && Vxod_M2==1) || Vxod_M2==0)) {//我市垡扰 涡呐欣 衔 韧娜世椅杏 膛娜犹
switch(Metod){
case 1:
SendOrder(OP_SELL, OpenLot, Bid, Magic_martin, DoubleToStr((_order_number+1),0)+”:martin”,0, 0);
MModifyOrders(OP_SELL);
Sleep(PauseTrade*1000);

break;
case 2:
// 橡钼屦桁 黩?猁 珥圜屙桢 猁腩 矬耱铄 – 耔沩嚯 ?蝾?黩?镳邃簌栝 铕溴?桉镱腠桦?
if(MSellStop == 0.0){
MSellStop = NormalizeDouble(Bid-Dist,Digits);
MSellStopLot = OpenLot;
MSellStopNumb= _order_number+1;
//MSellStopStopLoss = dMartinStopLoss;
//MSellStopTakeProfit = dMartinTP;
}
break;
}
Sell_flag = martin_flag;
GlobalVariableSet(“Sell_flag”,Sell_flag);
//StartSPrice = -1;
}
}
}
}
}
// 橡钼屦赅 祛骓?腓 铗牮桠囹?铕溴疣 镨疣扈潲
if((PiramidOn || PiramidAutoStart) && (Sell_flag == piramid_flag || (StartSPrice > 0 && _order_number == 0 && StartSPrice – Bid >= PiramidStep)/*StringFind(sSellInfo[1],”:start”)>-1*/)
/*(StringFind(sSellInfo[1],”:start”)>-1 || StringFind(sSellInfo[1],”:piramid”)>-1) &&
(!_buy_opened || StringFind(sBuyInfo[1],”:piramid”)==-1)*/)
{
//Print(” !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Sell Orders:”, _order_number);
// 橡钼屦赅 磬 铗觌屙桢 疣犷螓 镨疣扈潲 镱耠?漕耱桄屙? 玎溧眄钽?觐?忸 觐脲?
if(!fStopPiramid(_order_number)){
// 橡钼屦赅 – 漕耱桡眢蝾 腓 玎溧眄铄 觐?忸 矬黻蝾?潆 铗牮? 铕溴疣 镨疣扈潲
if(NormalizeDouble(dSellInfo[3]-Bid,Digits) >= GetPiramidStepPip(_order_number) || _order_number == 0){
// 橡钼屦赅 磬 玎牮桢 铕溴痤?觐沅?漕耱桡眢蝾 铗牮桢 玎溧眄钽?觐?忸 铕溴痤?
if(Close_P_orders==0 || !CheckOpenOrdCntP(OP_SELL,_order_number)){
OpenLot = dSellInfo[6];
if(PiramidAutoStart && !PiramidOn && _order_number==0) OpenLot = PiramidStartLot; else if (_order_number==0) OpenLot = GetLot(); // 羼腓 镱潢膻麇龛?镱 % 铗 爨痱桧?恹觌屙??铕溴痤?镨疣扈潲 礤?- 铗牮噱?腩?镱 痂耜?铗 溴镱 (忸珈铈眍 塍鼬?铗牮囹?腩?= 镥疴铎?铕溴痼 爨痱桧?
// 悟牮桢 铕溴疣 镨疣扈潲 ?玎忤耔祛耱?铗 戾蝾溧
if(((P()==-1 && Vxod_P==1) || Vxod_P==0) && ((P2()==-1 && Vxod_P2==1) || Vxod_P2==0)) {//我市垡扰 涡呐欣 衔 韧娜世椅杏 膛娜犹
switch(Metod){
case 1:
SendOrder(OP_SELL, GetLot(3,OpenLot,_order_number), Bid, Magic_piramid, DoubleToStr((_order_number+1),0)+”:piramid”, 0, 0);
PModifyOrders (OP_SELL);
//
Sleep(PauseTrade*1000);
break;
case 2:
if(PSellStop == 0.0){
PSellStop = NormalizeDouble(Bid-Dist,Digits);
PSellStopLot = GetLot(3,OpenLot, _order_number);
PSellStopNumb= _order_number+1;
//PSellStopStopLoss = dPiramidStopLoss;
//PSellStopTakeProfit = dPiramidTP;
}
break;
}
Sell_flag = piramid_flag;
GlobalVariableSet(“Sell_flag”,Sell_flag);
//StartSPrice = -1;
}
}
}
}
}
}
//———————————-
if(_buy_opened || StartBPrice > 0){
// 玉蜞眍怅?徨珞猁蜿?铕溴痤?镨疣扈潲
PiramidBE(OP_BUY);
// 玉蜞眍怅?徨珞猁蜿?铕溴痤?爨痱桧?
MartinBE(OP_BUY);
// 茵彘腓磴 铕溴痤?爨痱桧?
MartinTrailing(OP_BUY);
// 茵彘腓磴 铕溴痤?镨疣扈潲
PiramidTrailing(OP_BUY);
// 项塍麇龛 眍戾疣 镳邃簌邈?铕溴疣
_order_number = StrToInteger(StringSubstr(sBuyInfo[1],0,StringFind(sBuyInfo[1],”:”)));
// 橡钼屦赅 – 祛骓?腓 铗牮囹?爨痱桧 铕溴疣
if(Martin_On && (Buy_flag == martin_flag || (StartBPrice > 0 && _order_number == 0 && StartBPrice – Ask >= MartinStep)/*StringFind(sBuyInfo[1],”:start”)>-1*/)
/*(StringFind(sBuyInfo[1],”:start”)>-1 || StringFind(sBuyInfo[1],”:martin”)>-1) &&
(!_sell_opened || StringFind(sSellInfo[1],”:martin”)==-1)*/)
{
// 橡钼屦赅 磬 铗觌屙桢 疣犷螓 爨痱桧?镱耠?漕耱桄屙? 玎溧眄钽?觐?忸 觐脲?
if(!fStopMartin(_order_number)){
// 橡钼屦赅 – 漕耱桡眢蝾 腓 玎溧眄铄 觐?忸 矬黻蝾?潆 铗牮? 爨痱桧 铕溴疣
//if(NormalizeDouble(dBuyInfo[3]-Ask,Digits) >= GetMartinStepPip(_order_number)){
if(GetSignal(OP_BUY, dBuyInfo[3], _order_number) || _order_number == 0){
// 橡钼屦赅 磬 玎牮桢 铕溴痤?觐沅?漕耱桡眢蝾 铗牮桢 玎溧眄钽?觐?忸 铕溴痤?
if(Close_M_orders==0 || !CheckOpenOrdCnt(OP_BUY,_order_number)){
// 朽聍弪 耠邃簋泐 腩蜞
OpenLot = GetLot(2, dBuyInfo[6], _order_number, dBuyInfo[3]-Ask, GetMartinStepPip(_order_number));
// 悟牮桢 爨痱桧 铕溴疣 ?玎忤耔祛耱?铗 戾蝾溧
if(((M()==1 && Vxod_M==1) || Vxod_M==0) && ((M2()==1 && Vxod_M2==1) || Vxod_M2==0)) {//我市垡扰 涡呐欣 衔 韧娜世椅杏 膛娜犹
switch(Metod){
case 1:
SendOrder(OP_BUY, OpenLot, Ask, Magic_martin, DoubleToStr((_order_number+1),0)+”:martin”,0, 0);
MModifyOrders(OP_BUY);
//
Sleep(PauseTrade*1000);
break;
case 2:
// 橡钼屦桁 黩?猁 珥圜屙桢 猁腩 矬耱铄 – 耔沩嚯 ?蝾?黩?镳邃簌栝 铕溴?桉镱腠桦?
if(MBuyStop == 0.0){
MBuyStop = NormalizeDouble(Ask+Dist,Digits);
MBuyStopLot = OpenLot;
MBuyStopNumb= _order_number+1;
//MBuyStopStopLoss = dMartinStopLoss;
//MBuyStopTakeProfit = dMartinTP;
}
break;
}
Buy_flag = martin_flag;
GlobalVariableSet(“Buy_flag”,Buy_flag);
//StartBPrice = -1;
}
}
}
}
}
// 橡钼屦赅 祛骓?腓 铗牮桠囹?铕溴疣 镨疣扈潲
if((PiramidOn || PiramidAutoStart) && (Buy_flag == piramid_flag || (StartBPrice > 0 && _order_number == 0 && Ask – StartBPrice >= PiramidStep)/*StringFind(sBuyInfo[1],”:start”)>-1*/)
/*(StringFind(sBuyInfo[1],”:start”)>-1 || StringFind(sBuyInfo[1],”:piramid”)>-1) &&
(!_sell_opened || StringFind(sSellInfo[1],”:piramid”)==-1)*/)
{
// 橡钼屦赅 磬 铗觌屙桢 疣犷螓 镨疣扈潲 镱耠?漕耱桄屙? 玎溧眄钽?觐?忸 觐脲?
if(!fStopPiramid(_order_number)){
// 橡钼屦赅 – 漕耱桡眢蝾 腓 玎溧眄铄 觐?忸 矬黻蝾?潆 铗牮? 铕溴疣 镨疣扈潲
if(NormalizeDouble(Ask-dBuyInfo[3],Digits) >= GetPiramidStepPip(_order_number) || _order_number == 0){
// 橡钼屦赅 磬 玎牮桢 铕溴痤?觐沅?漕耱桡眢蝾 铗牮桢 玎溧眄钽?觐?忸 铕溴痤?
if(Close_P_orders==0 || !CheckOpenOrdCntP(OP_BUY,_order_number)){
OpenLot = dBuyInfo[6];
if(PiramidAutoStart && !PiramidOn && _order_number==0) OpenLot = PiramidStartLot; else if (_order_number==0) OpenLot = GetLot();
// 悟牮桢 铕溴疣 镨疣扈潲 ?玎忤耔祛耱?铗 戾蝾溧
if(((P()==1 && Vxod_P==1) || Vxod_P==0) && ((P2()==1 && Vxod_P2==1) || Vxod_P2==0)) { //我市垡扰 涡呐欣 衔 韧娜世椅杏 膛娜犹
switch(Metod){
case 1:
SendOrder(OP_BUY, GetLot(3, OpenLot, _order_number), Ask, Magic_piramid, DoubleToStr((_order_number+1),0)+”:piramid”, 0, 0);
PModifyOrders(OP_BUY);
//
Sleep(PauseTrade*1000);
break;
case 2:
// 橡钼屦桁 黩?猁 珥圜屙桢 猁腩 矬耱铄 – 耔沩嚯 ?蝾?黩?镳邃簌栝 铕溴?桉镱腠桦?
if(PBuyStop == 0.0){
PBuyStop = NormalizeDouble(Ask+Dist,Digits);
PBuyStopLot = GetLot(3, OpenLot, _order_number);
PBuyStopNumb= _order_number+1;
// PBuyStopStopLoss = dPiramidStopLoss;
// PBuyStopTakeProfit = dPiramidTP;
}
break;
}
Buy_flag = piramid_flag;
GlobalVariableSet(“Buy_flag”,Buy_flag);
//StartBPrice = -1;
}
}
}
}
}
}
}
}
}

//———————————-
// 软纛痨噼痤忄龛?镱朦珙忄蝈?
if(!InitDC){
GetDCWithFontNameAndSize(FontName, FontSize);
InitDC = true;
}
DrawInfo();
}
//—-
}
//+——————————————————————+
// 茵彘腓磴 羊铒 铕溴痤?锑痱桧? +
//+——————————————————————+
void MartinTrailing(int type){
if(M_Trailing && M_TrailingStop > 0.0){
// 杨耱噔桁 耧桉铌 铕溴痤?潆 镳桁屙屙? 徨珞猁蜿?
int _tickets[][2];
int _orders_cnt = 0,i;
ArrayResize(_tickets,OrdersTotal());
for(i=OrdersTotal()-1;i>=0;i–){
if(OrderSelect(i,SELECT_BY_POS)){
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic_martin && OrderType()==type){
_tickets[_orders_cnt][0] = OrderTicket();
_tickets[_orders_cnt][1] = OrderOpenTime();
_orders_cnt++;
}
}
}
// 橡钼屦桁 黩?猁 觐?忸 铕溴痤??耧桉赍 猁腩 犷朦 桦?疣忭?M_BU_Start
if(M_Trailing_Start > 0 && _orders_cnt >= M_Trailing_Start){
ArrayResize(_tickets,_orders_cnt);
// 悟耦痱桊箦?耧桉铌 镱 怵屐屙?铗牮? 铕溴痤?
// 亦觇?钺疣珙??磬鬣脲 耧桉赅 狍溴?铕溴? 觐蝾瘥?铗牮 疣睃 铖蜞朦睇?
// ?觐眦?耧桉赅 狍溴?铕溴?觐蝾瘥?铗牮?襦禧?镱耠邃龛?耩邃?铖蜞朦睇?
ArrayTwoSortInt(_tickets, 1);
// 玉蜞眍忤?徨珞猁蝾?潆 蝈?铕溴痤? 觐蝾瘥?犷朦 腓犷 疣忭?M_BU_Start
for(i=_orders_cnt-1;i>=M_Trailing_Start-1;i–){
if(OrderSelect(_tickets[i][0],SELECT_BY_TICKET)){
if(StringFind(OrderComment(),”:start”)==-1){
double _price,_new_sl;
bool t=false;
switch(OrderType()){
case OP_BUY:

_price = OrderStopLoss();
if(_price == 0.0 || _price < OrderOpenPrice()) _price = OrderOpenPrice();
//
if(Bid >= NormalizeDouble(_price+dM_TrailingStop,Digits)){
_new_sl = NormalizeDouble(Bid-dM_TrailingStep,Digits);
if(NormalizeDouble(OrderStopLoss()-_new_sl,Digits)!=0.0 && _new_sl > _price){
t=OrderModify(OrderTicket(),OrderOpenPrice(),_new_sl,OrderTakeProfit(),OrderExpiration());
}
}
break;
case OP_SELL:
//bool t=false;
_price = OrderStopLoss();
if(_price == 0.0 || _price > OrderOpenPrice()) _price = OrderOpenPrice();
//
if(Ask <= NormalizeDouble(_price-dM_TrailingStop,Digits)){
_new_sl = NormalizeDouble(Ask+dM_TrailingStep,Digits);
if(NormalizeDouble(OrderStopLoss()-_new_sl,Digits)!=0.0 && _new_sl < _price){
t=OrderModify(OrderTicket(),OrderOpenPrice(),_new_sl,OrderTakeProfit(),OrderExpiration());
}
}
break;
}
}
}
}
}
}
}
//+——————————————————————+
// 茵彘腓磴 羊铒 铕溴痤?翔疣扈潲 +
//+——————————————————————+
void PiramidTrailing(int type){
if(P_Trailing && P_TrailingStop > 0.0){
// 杨耱噔桁 耧桉铌 铕溴痤?潆 镳桁屙屙? 徨珞猁蜿?
int _tickets[][2];
int _orders_cnt = 0,i;
ArrayResize(_tickets,OrdersTotal());
for(i=OrdersTotal()-1;i>=0;i–){
if(OrderSelect(i,SELECT_BY_POS)){
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic_piramid && OrderType()==type){
_tickets[_orders_cnt][0] = OrderTicket();
_tickets[_orders_cnt][1] = OrderOpenTime();
_orders_cnt++;
}
}
}
// 橡钼屦桁 黩?猁 觐?忸 铕溴痤??耧桉赍 猁腩 犷朦 桦?疣忭?M_BU_Start
if(P_Trailing_Start > 0 && _orders_cnt >= P_Trailing_Start){
ArrayResize(_tickets,_orders_cnt);
// 悟耦痱桊箦?耧桉铌 镱 怵屐屙?铗牮? 铕溴痤?
// 亦觇?钺疣珙??磬鬣脲 耧桉赅 狍溴?铕溴? 觐蝾瘥?铗牮 疣睃 铖蜞朦睇?
// ?觐眦?耧桉赅 狍溴?铕溴?觐蝾瘥?铗牮?襦禧?镱耠邃龛?耩邃?铖蜞朦睇?
ArrayTwoSortInt(_tickets, 1);
// 玉蜞眍忤?徨珞猁蝾?潆 蝈?铕溴痤? 觐蝾瘥?犷朦 腓犷 疣忭?M_BU_Start
for(i=_orders_cnt-1;i>=P_Trailing_Start-1;i–){
if(OrderSelect(_tickets[i][0],SELECT_BY_TICKET)){
if(StringFind(OrderComment(),”:start”)==-1){
double _price,_new_sl;
bool t=false;
switch(OrderType()){
case OP_BUY:

_price = OrderStopLoss();
if(_price == 0.0 || _price < OrderOpenPrice()) _price = OrderOpenPrice();
//
if(Bid >= NormalizeDouble(_price+dP_TrailingStop,Digits)){
_new_sl = NormalizeDouble(Bid-dP_TrailingStep,Digits);
if(NormalizeDouble(OrderStopLoss()-_new_sl,Digits)!=0.0 && _new_sl > _price){
t= OrderModify(OrderTicket(),OrderOpenPrice(),_new_sl,OrderTakeProfit(),OrderExpiration());
}
}
break;
case OP_SELL:
_price = OrderStopLoss();
if(_price == 0.0 || _price > OrderOpenPrice()) _price = OrderOpenPrice();
//
if(Ask <= NormalizeDouble(_price-dP_TrailingStop,Digits)){
_new_sl = NormalizeDouble(Ask+dP_TrailingStep,Digits);
if(NormalizeDouble(OrderStopLoss()-_new_sl,Digits)!=0.0 && _new_sl < _price){
t=OrderModify(OrderTicket(),OrderOpenPrice(),_new_sl,OrderTakeProfit(),OrderExpiration());
}
}
break;
}
}
}
}
}
}
}
//+——————————————————————+
// 玉蜞眍怅?徨珞猁蜿?潆 铕溴痤?爨痱桧? +
//+——————————————————————+
void MartinBE(int type){
if(M_WL && M_WLstart > 0){
// 杨耱噔桁 耧桉铌 铕溴痤?潆 镳桁屙屙? 徨珞猁蜿?
int _tickets[][2];
int _orders_cnt = 0,i;
ArrayResize(_tickets,OrdersTotal());
for(i=OrdersTotal()-1;i>=0;i–){
if(OrderSelect(i,SELECT_BY_POS)){
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic_martin && OrderType()==type){
_tickets[_orders_cnt][0] = OrderTicket();
_tickets[_orders_cnt][1] = OrderOpenTime();
_orders_cnt++;
}
}
}
// 橡钼屦桁 黩?猁 觐?忸 铕溴痤??耧桉赍 猁腩 犷朦 桦?疣忭?M_BU_Start
if(M_BU_Start > 0 && _orders_cnt >= M_BU_Start){
ArrayResize(_tickets,_orders_cnt);
// 悟耦痱桊箦?耧桉铌 镱 怵屐屙?铗牮? 铕溴痤?
// 亦觇?钺疣珙??磬鬣脲 耧桉赅 狍溴?铕溴? 觐蝾瘥?铗牮 疣睃 铖蜞朦睇?
// ?觐眦?耧桉赅 狍溴?铕溴?觐蝾瘥?铗牮?襦禧?镱耠邃龛?耩邃?铖蜞朦睇?
ArrayTwoSortInt(_tickets, 1);
// 玉蜞眍忤?徨珞猁蝾?潆 蝈?铕溴痤? 觐蝾瘥?犷朦 腓犷 疣忭?M_BU_Start
for(i=_orders_cnt-1;i>=M_BU_Start-1;i–){
if(OrderSelect(_tickets[i][0],SELECT_BY_TICKET)){
if(StringFind(OrderComment(),”:start”)==-1){
double _new_sl;
//— 篦弪 觐扈耨梃 ?疋铒?
double com_swap = (OrderSwap()+OrderCommission())/OrderLots()*Point;
if (IsTesting()) com_swap = (OrderSwap()/OrderLots()*Point)+(-1*(Test_com_in_pip*Point));
//—
bool t=false;
switch(OrderType()){
case OP_BUY:

if(OrderStopLoss()==0.0 || OrderStopLoss() < NormalizeDouble(OrderOpenPrice()+dM_WLlevel-com_swap,Digits)){
if(Bid >= NormalizeDouble(OrderOpenPrice()+dM_WLstart-com_swap,Digits)){
_new_sl = NormalizeDouble(OrderOpenPrice()+dM_WLlevel-com_swap,Digits);
if(NormalizeDouble(OrderStopLoss()-_new_sl,Digits)!=0.0){
t= OrderModify(OrderTicket(),OrderOpenPrice(),_new_sl,OrderTakeProfit(),OrderExpiration());
}
}
}
break;
case OP_SELL:
if(OrderStopLoss()==0.0 || OrderStopLoss() > NormalizeDouble(OrderOpenPrice()-dM_WLlevel+com_swap,Digits)){
if(Ask <= NormalizeDouble(OrderOpenPrice()-dM_WLstart+com_swap,Digits)){
_new_sl = NormalizeDouble(OrderOpenPrice()-dM_WLlevel+com_swap,Digits);
if(NormalizeDouble(OrderStopLoss()-_new_sl,Digits)!=0.0){
t=OrderModify(OrderTicket(),OrderOpenPrice(),_new_sl,OrderTakeProfit(),OrderExpiration());
}
}
}
break;
}
}
}
}
}
}
}
//+——————————————————————++
// 蔓镱腠弪 耦痱桊钼牦 溻箪屦眍泐 爨耨桠?int 镱 玎溧眄铎?桤戾疱龛?戾蝾漕?矬琨瘘赅 ?玎溧眄铎 磬镳噔脲龛?耦痱桊钼觇
// array – 耦痱桊箦禧?溻箪屦睇?爨耨桠 int
// mode – 磬镳噔脲龛?耦痱桊钼觇 (MODE_ASCEND – 镱 忸琊囫蜞龛? MODE_DESCEND – 镱 筢囗棹)
//-// 礤?忸琊帙噱祛泐 珥圜屙?
void ArrayTwoSortInt(int &array[][], int key, int mode=MODE_ASCEND){ int dt_temp = 0,q,i,j; int line = ArrayRange(array,0); int line2 = ArrayRange(array,1); if(key >= 0 && key < line2){ for(i=line-1;i>=0;i–){ for (j=0; j<i; j++){ if (mode==MODE_ASCEND){ if(array[j][key]>array[j+1][key]){ for(q=0;q<line2;q++){ dt_temp = array[j][q]; array[j][q] = array[j+1][q]; array[j+1][q] = dt_temp; } } }else{ if(array[j][key]<array[j+1][key]){ for(q=0;q<line2;q++){ dt_temp = array[j][q]; array[j][q] = array[j+1][q]; array[j+1][q] = dt_temp; } } } } } } }
//+——————————————————————++
//=========================================================================================================
// 玉蜞眍怅?徨珞猁蜿?潆 铕溴痤?镨疣扈潲 =
//=========================================================================================================
void PiramidBE(int type){
if(P_WL && P_WLstart > 0){
// 杨耱噔桁 耧桉铌 铕溴痤?潆 镳桁屙屙? 徨珞猁蜿?
int _tickets[][2];
int _orders_cnt = 0,i;
ArrayResize(_tickets,OrdersTotal());
for(i=OrdersTotal()-1;i>=0;i–){
if(OrderSelect(i,SELECT_BY_POS)){
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic_piramid && OrderType()==type){
_tickets[_orders_cnt][0] = OrderTicket();
_tickets[_orders_cnt][1] = OrderOpenTime();
_orders_cnt++;
}
}
}
// 橡钼屦桁 黩?猁 觐?忸 铕溴痤??耧桉赍 猁腩 犷朦 桦?疣忭?M_BU_Start
if(P_BU_Start > 0 && _orders_cnt >= P_BU_Start){
ArrayResize(_tickets,_orders_cnt);
// 悟耦痱桊箦?耧桉铌 镱 怵屐屙?铗牮? 铕溴痤?
// 亦觇?钺疣珙??磬鬣脲 耧桉赅 狍溴?铕溴? 觐蝾瘥?铗牮 疣睃 铖蜞朦睇?
// ?觐眦?耧桉赅 狍溴?铕溴?觐蝾瘥?铗牮?襦禧?镱耠邃龛?耩邃?铖蜞朦睇?
ArrayTwoSortInt(_tickets, 1);
// 玉蜞眍忤?徨珞猁蝾?潆 蝈?铕溴痤? 觐蝾瘥?犷朦 腓犷 疣忭?M_BU_Start
for(i=_orders_cnt-1;i>=P_BU_Start-1;i–){
if(OrderSelect(_tickets[i][0],SELECT_BY_TICKET)){
if(StringFind(OrderComment(),”:start”)==-1){
double _new_sl;
//— 篦弪 觐扈耨梃 ?疋铒?
double com_swap = (OrderSwap()+OrderCommission())/OrderLots()*Point;
if (IsTesting()) com_swap = (OrderSwap()/OrderLots()*Point)+(-1*(Test_com_in_pip*Point));
//—
bool t=false;
switch(OrderType()){
case OP_BUY:

if(OrderStopLoss()==0.0 || OrderStopLoss() < NormalizeDouble(OrderOpenPrice()+dP_WLlevel-com_swap,Digits)){
if(Bid >= NormalizeDouble(OrderOpenPrice()+dP_WLstart-com_swap,Digits)){
_new_sl = NormalizeDouble(OrderOpenPrice()+dP_WLlevel-com_swap,Digits);
if(NormalizeDouble(OrderStopLoss()-_new_sl,Digits)!=0.0){
t= OrderModify(OrderTicket(),OrderOpenPrice(),_new_sl,OrderTakeProfit(),OrderExpiration());
}
}
}
break;
case OP_SELL:
if(OrderStopLoss()==0.0 || OrderStopLoss() > NormalizeDouble(OrderOpenPrice()-dP_WLlevel+com_swap,Digits)){
if(Ask <= NormalizeDouble(OrderOpenPrice()-dP_WLstart+com_swap,Digits)){
_new_sl = NormalizeDouble(OrderOpenPrice()-dP_WLlevel+com_swap,Digits);
if(NormalizeDouble(OrderStopLoss()-_new_sl,Digits)!=0.0){
t= OrderModify(OrderTicket(),OrderOpenPrice(),_new_sl,OrderTakeProfit(),OrderExpiration());
}
}
}
break;
}
}
}
}
}
}
}
//+——————————————————————+
// 橡钼屦弪 耠铈桦桉?腓 篑脞钼? 潆 铗牮? 铕溴疣
bool GetSignal(int _type, double _price_open, int _order_number){
bool _res = false;
double _cci = 0.0;
double _cci1 = 0.0;
//
switch(_type){
case OP_SELL:
// 橡钼屦赅 – 漕耱桡眢蝾 腓 玎溧眄铄 觐?忸 矬黻蝾?潆 铗牮? 爨痱桧 铕溴疣
if(NormalizeDouble(Bid-_price_open,Digits) >= GetMartinStepPip(_order_number)){
if(CCI_On){
_cci = CCI(0);
_cci1 = CCI(1);
if(_cci <= Level && _cci1 > Level) _res = true;
}else _res = true;
}
break;
case OP_BUY:
// 橡钼屦赅 – 漕耱桡眢蝾 腓 玎溧眄铄 觐?忸 矬黻蝾?潆 铗牮? 爨痱桧 铕溴疣
if(NormalizeDouble(_price_open-Ask,Digits) >= GetMartinStepPip(_order_number)){
if(CCI_On){
_cci = CCI(0);
_cci1 = CCI(1);
if(_cci >= -Level && _cci1 < -Level) _res = true;
}else _res = true;
}
break;
}
return(_res);
}
//+——————————————————————+
// 骂玮疣弪 珥圜屙桢 桧滂赅蝾疣 蜒I ?玎溧眄?磬耱痤殛囔?
double CCI(int _bar){ return(NormalizeDouble(iCCI(NULL,CCI_TimeFrame,Period_CCI,PRICE_CLOSE,_bar),4)); }
//+——————————————————————+
// 橡钼屦弪 漕耱桡眢蝾 腓 铗牮桢 玎溧眄钽?铕溴疣
// 羼腓 溧 – 玎牮噱?怦?皴痂?铕溴痤??忸玮疣弪 true
bool CheckOpenOrdCnt(int _type, int _current_cnt){
bool _res = false;

if(Close_M_orders > 0 && _current_cnt >= Close_M_orders-1){
// 青牮铄?怦?铕溴疣
for(int i=OrdersTotal()-1;i>=0;i–){
if(OrderSelect(i,SELECT_BY_POS)){
if(OrderSymbol()==_Symbol && OrderMagicNumber()==Magic_martin && OrderType()==_type)
{
OrdersClose(33, OrderTicket(), false, _Symbol, “”);
}
}
}
_res = true;
}
return(_res);
}
//+——————————————————————+
// 橡钼屦弪 漕耱桡眢蝾 腓 铗牮桢 玎溧眄钽?铕溴疣
// 羼腓 溧 – 玎牮噱?怦?皴痂?铕溴痤??忸玮疣弪 true
bool CheckOpenOrdCntP(int _type, int _current_cnt){
bool _res = false;
if(Close_P_orders > 0 && _current_cnt >= Close_P_orders-1){
// 青牮铄?怦?铕溴疣
for(int i=OrdersTotal()-1;i>=0;i–){
if(OrderSelect(i,SELECT_BY_POS)){
if(OrderSymbol()==_Symbol &&
(OrderMagicNumber()==Magic_piramid || StringFind(OrderComment(),”:start”)>-1) &&
OrderType()==_type)
{
OrdersClose(33, OrderTicket(), false, _Symbol, “”);
}
}
}
_res = true;
}
return(_res);
}
//+——————————————————————+
// 骂玮瘗噱?true 羼腓 疣琊屮屙?蝾疸钼? ?蝈牦?怵屐

bool TimeFilter(){

bool _res = false;
datetime _time_curent = TimeCurrent();
datetime _time_start = StrToTime(DoubleToStr(Year(),0)+”.”+DoubleToStr(Month(),0)+”.”+DoubleToStr(Day(),0)+” “+StartHour);
datetime _time_stop = StrToTime(DoubleToStr(Year(),0)+”.”+DoubleToStr(Month(),0)+”.”+DoubleToStr(Day(),0)+” “+EndHour);
if(((Trade_in_Monday==true) && (TimeDayOfWeek(Time[0]) == 1)) ||
((Trade_in_Tuesday==true) && (TimeDayOfWeek(Time[0]) == 2)) ||
((Trade_in_Wednesday==true) && (TimeDayOfWeek(Time[0]) == 3)) ||
((Trade_in_Thursday==true) && (TimeDayOfWeek(Time[0]) == 4)) ||
((Trade_in_Friday==true) && (TimeDayOfWeek(Time[0]) == 5)))

if(_time_start > _time_stop){
if(_time_curent >= _time_start || _time_curent <= _time_stop) _res = true;
}else
if(_time_curent >= _time_start && _time_curent <= _time_stop) _res = true;

return(_res);

}

//+——————————————————————+

 

//+——————————————————————+
// 软纛痨桊钼囗桢 镱朦珙忄螂
void DrawInfo(){
if(Info){
//
int _x = PositionX,i;
int _y = PositionY;
color _clr = CLR_NONE;
string sInfo[9];
//—- 厌铕 溧眄
double _buy_lot = OrdersGetOpenLot(_Symbol, OP_BUY, 99, “”, 0, 0);
sInfo[0] = DoubleToStr(_buy_lot,iDigitLot);
double _sell_lot = OrdersGetOpenLot(_Symbol, OP_SELL, 99, “”, 0, 0);
sInfo[1] = DoubleToStr(_sell_lot,iDigitLot);
double _buy_result = OrdersGetProfit(99, OP_BUY, _Symbol, “”);
sInfo[2] = DoubleToStr(_buy_result,2);
double _sell_result = OrdersGetProfit(99, OP_SELL, _Symbol, “”);
sInfo[3] = DoubleToStr(_sell_result,2);
double _all_result = NormalizeDouble(_buy_result+_sell_result,2);
sInfo[4] = DoubleToStr(_all_result,2);
// dd
double _dd = 0.0;
if(_all_result < 0.0) _dd = NormalizeDouble((_all_result/AccountBalance())*100,2);
sInfo[5] = DoubleToStr(_dd,2);
// balance
double _balance = AccountBalance();
sInfo[6] = DoubleToStr(_balance,2);
// equity
double _equity = AccountEquity();
double _equity_persent = NormalizeDouble((_equity/_balance)*100,2);
sInfo[7] = DoubleToStr(AccountFreeMargin(),2);
// level
sInfo[8] = DoubleToStr(InfoGetMarginLevel(),2);
//—- 蔓聍栩噱?潆桧眢 襦祛?犷朦?耱痤觇
int _max_size = 0; int _temp_size = 0;
for(i=0;i<9;i++){
//_temp_size = GetStringSizeInPix(sInfo[i]);
if(_temp_size > _max_size) _max_size = _temp_size;
}
_max_size += (_x+50);
// —-
// 杨玟囗桢 / 镱滗屦驵龛?桧纛痨圉桀眄铋 镟礤腓
if(_buy_lot == 0.0) _clr = White; else _clr = clrDeepSkyBlue;
Label(“BuyVolume”, _max_size, _y, “勿溴?Buy:”, BaseColor);
Label(“vBuyVolume”, _x, _y, sInfo[0], _clr);

_y += FontSize + 5;

if(_sell_lot == 0.0) _clr = White; else _clr = clrRed;
Label(“SellVolume”, _max_size, _y, “勿溴?Sell:”, BaseColor);
Label(“vSellVolume”, _x, _y, sInfo[1], _clr);

_y += FontSize + 5;

if(_buy_result == 0.0) _clr = White; else if(_buy_result < 0.0) _clr = Red; else _clr = clrDeepSkyBlue;
Label(“BuyProfit”, _max_size, _y, “橡铘栩 Buy:”, BaseColor);
Label(“vBuyProfit”, _x, _y, sInfo[2], _clr);

_y += FontSize + 5;

if(_sell_result == 0.0) _clr = White; else if(_sell_result < 0.0) _clr = Red; else _clr = clrDeepSkyBlue;
Label(“SellProfit”, _max_size, _y, “橡铘栩 Sell:”, BaseColor);
Label(“vSellProfit”, _x, _y, sInfo[3], _clr);

_y += FontSize + 5;

if(_all_result == 0.0) _clr = White; else if(_all_result < 0.0) _clr = Red; else _clr = clrDeepSkyBlue;
Label(“AllProfit”, _max_size, _y, “洋祆囵睇?镳铘栩:”, BaseColor);
Label(“vAllProfit”, _x, _y, sInfo[4], _clr);

_y += FontSize + 5;

if(_dd == 0.0) _clr = White; else _clr = clrDarkOrange;
Label(“DD”, _max_size, _y, “橡铖噤赅:”, BaseColor);
Label(“vDD”, _x, _y, sInfo[5], _clr);

_y += FontSize + 10;

Label(“Balance”, _max_size, _y, “拎豚眈:”, BaseColor);
Label(“vBalance”, _x, _y, sInfo[6], clrDeepSkyBlue);

_y += FontSize + 5;

if(_equity_persent > 80) _clr = clrGreen; else if(_equity_persent > 50) _clr = clrDeepSkyBlue; else if(_equity_persent > 30) _clr = clrDarkOrange; else _clr = clrRed;
Label(“Equity”, _max_size, _y, “砚钺钿眍:”, BaseColor);
Label(“vEquity”, _x, _y, sInfo[7], _clr);

_y += FontSize + 5;

Label(“Level”, _max_size, _y, “羽钼屙?”, BaseColor);
Label(“vLevel”, _x, _y, sInfo[8], clrDeepSkyBlue);

_y += FontSize + 15;

if(TralPrice > 0.0){
Label(“vTral”, _x, _y, “> 马桁囗桢 朽犷蜞弪 茵嚯 <“, clrDarkOrange);
_y += FontSize + 5;
}else{
if(ObjectFind(sPrefIndPan+”vTral”)>-1) ObjectDelete(sPrefIndPan+”vTral”);
}

if(!NewCycle_ON){
Label(“vNewCycle_ON”, _x, _y, “> 青镳弪 NewCycle <“, clrDarkOrange);
_y += FontSize + 5;
}else{
if(ObjectFind(sPrefIndPan+”vNewCycle_ON”)>-1) ObjectDelete(sPrefIndPan+”vNewCycle_ON”);
}

if(!PiramidOn && PiramidAutoStart){
Label(“vPiramidAutoStart”, _x, _y, “> 袜镳噔脲龛?翔疣扈溧 率?<“, clrDarkOrange);
_y += FontSize + 5;
}else{
if(ObjectFind(sPrefIndPan+”vPiramidAutoStart”)>-1) ObjectDelete(sPrefIndPan+”vPiramidAutoStart”);
}

if(StopMartin){
Label(“vStopMartin”, _x, _y, “> 袜镳噔脲龛?锑痱桧沐殡 我仕 <“, clrDarkOrange);
_y += FontSize + 5;
}else{
if(ObjectFind(sPrefIndPan+”vStopMartin”)>-1) ObjectDelete(sPrefIndPan+”vStopMartin”);
}

if(StopPiramid){
Label(“vStopPiramid”, _x, _y, “> 袜镳噔脲龛?翔疣扈溧 我仕 <“, clrDarkOrange);
_y += FontSize + 5;
}else{
if(ObjectFind(sPrefIndPan+”vStopPiramid”)>-1) ObjectDelete(sPrefIndPan+”vStopPiramid”);

}

//—- 俞屦屐 ?沭圄桕?腓龛?铕溴痤?
GraphDelete(sPref);
// 项溷铗钼赅 溧眄
int _bar_on_chart = WindowBarsPerChart();
int _need_bar = _bar_on_chart / 2;
int _first_visible_bar = WindowFirstVisibleBar();
datetime _time_bar = Time[_first_visible_bar] + ((Period()*60) * _need_bar);
//
if(AveregeLine > 0.0){
GraphHLineCreate(sPref+”AverLine”, AveregeLine, BULineColor, STYLE_SOLID, 1);
GraphTextCreate(sPref+”txtAverLine”,0, _time_bar, AveregeLine, BULineColor, FontSize, 0.0, “羽钼屙?劣”, FontName);

GraphHLineCreate(sPref+”TPLine”, TPLine, TPLineColor, STYLE_SOLID, 1);
GraphTextCreate(sPref+”txtTPLine”,0, _time_bar, TPLine, TPLineColor, FontSize, 0.0, “羽钼屙?蚁”, FontName);
}
if(TralStartPrice > 0.0){
GraphHLineCreate(sPref+”TralPrice”, TralStartPrice, DarkOrange, STYLE_SOLID, 1);
GraphTextCreate(sPref+”txtTralPrice”,0, _time_bar, TralStartPrice, DarkOrange, FontSize, 0.0, “袜鬣腩 疣犷螓 蝠嚯”, FontName);
}else
if(TralPrice > 0.0){
GraphHLineCreate(sPref+”TralPrice”, TralPrice, DarkOrange, STYLE_SOLID, 1);
GraphTextCreate(sPref+”txtTralPrice”,0, _time_bar, TralPrice, DarkOrange, FontSize, 0.0, “朽犷蜞弪 茵嚯”, FontName);
}

if(MBuyStop > 0.0){
GraphHLineCreate(sPref+”MBuyStop”, MBuyStop, BuyStopColor, STYLE_SOLID, 1);
GraphTextCreate(sPref+”txtMBuyStop”,0, _time_bar, MBuyStop, BuyStopColor, FontSize, 0.0, “BUY”, FontName);
}
if(MSellStop > 0.0){
GraphHLineCreate(sPref+”MSellStop”, MSellStop, SellStopColor, STYLE_SOLID, 1);
GraphTextCreate(sPref+”txtMSellStop”,0, _time_bar, MSellStop, SellStopColor, FontSize, 0.0, “SELL”, FontName);
}
if(PBuyStop > 0.0){
GraphHLineCreate(sPref+”PBuyStop”, PBuyStop, BuyStopColor, STYLE_SOLID, 1);
GraphTextCreate(sPref+”txtPBuyStop”,0, _time_bar, PBuyStop, BuyStopColor, FontSize, 0.0, “BUY”, FontName);
}
if(PSellStop > 0.0){
GraphHLineCreate(sPref+”PSellStop”, PSellStop, SellStopColor, STYLE_SOLID, 1);
GraphTextCreate(sPref+”txtPSellStop”,0, _time_bar, PSellStop, SellStopColor, FontSize, 0.0, “SELL”, FontName);
}
if(StartSPrice > 0.0){
GraphHLineCreate(sPref+”StartSPrice”, StartSPrice, StartSPriceColor, STYLE_SOLID, 1);
GraphTextCreate(sPref+”txtStartSPrice”,0, _time_bar, StartSPrice, StartSPriceColor, FontSize, 0.0, “羊囵蝾忄 鲥磬 SELL”, FontName);
}
if(StartBPrice > 0.0){
GraphHLineCreate(sPref+”StartBPrice”, StartBPrice, StartBPriceColor, STYLE_SOLID, 1);
GraphTextCreate(sPref+”txtStartBPrice”,0, _time_bar, StartBPrice+shiftGraph*Point, StartBPriceColor, FontSize, 0.0, “羊囵蝾忄 鲥磬 BUY”, FontName);
}
}
}

//+——————————————————————+
// 杨玟囗桢 / 桤戾礤龛?桧纛痨圉桀眄铋 镟礤腓
void Label(string _name, int _x, int _y, string _text, color _clr){
_name = sPrefIndPan+_name;
if(ObjectFind(_name)==-1){
GraphLabelCreate(0, _name, _x, _y, 1, _text, FontSize, FontName, _clr);
}else{
if(ObjectGet(_name, OBJPROP_COLOR) != _clr) ObjectSet(_name,OBJPROP_COLOR,_clr);
if(ObjectGet(_name, OBJPROP_XDISTANCE) != _x) ObjectSet(_name,OBJPROP_XDISTANCE,_x);
if(ObjectGet(_name, OBJPROP_YDISTANCE) != _y) ObjectSet(_name,OBJPROP_YDISTANCE,_y);
if(ObjectDescription(_name) != _text) ObjectSetText(_name, _text, FontSize);
}
}
//+——————————————————————+
// 泽黻鲨 耦玟噱?钺牝 Horisontal Line 玎溧眄钽?鲡弪? 耱桦
void GraphHLineCreate(string sName, double _dPrice, color MyColor, int _iStyle, int _iWidth){ObjectCreate(sName,OBJ_HLINE,0,0,_dPrice);ObjectSet(sName,OBJPROP_COLOR,MyColor);ObjectSet(sName,OBJPROP_STYLE,_iStyle); ObjectSet(sName,OBJPROP_WIDTH,_iWidth); }
//+——————————————————————+
// 泽黻鲨 耦玟噱?钺牝 Label ?箨噻囗铎 铌礤(镱漕觏? 沭圄桕??玎溧眄 磬玮囗桢? 蝈犟蝾? 梏蝾? 疣珈屦铎 梏蜞, 鲡弪铎 梏蜞, ?疣耧铍铈屙桁 镱 蝾麝囔 ??y
void GraphLabelCreate(int Handle, string NameObject, int x, int y, int Corn, string text, int _FontSize, string _FontName, color FontColor){ObjectCreate(NameObject, OBJ_LABEL, Handle, 0, 0);ObjectSet(NameObject, OBJPROP_CORNER, Corn); ObjectSet(NameObject, OBJPROP_XDISTANCE, x); ObjectSet(NameObject, OBJPROP_YDISTANCE, y); ObjectSetText(NameObject, text, _FontSize, _FontName, FontColor);}
//+——————————————————————+
// 泽黻鲨 耦玟噱?钺牝 Text ?箨噻囗眍?铌礤(镱漕觏? 沭圄桕??玎溧眄 磬玮囗桢? 蝈犟蝾? 梏蝾? 疣珈屦铎 栩? 鲡弪铎 蝈犟蜞, 筱腩?磬觌铐?蝈犟蜞
void GraphTextCreate(string _n,int _h, datetime x, double y, color _c,int _FontSize, double _Angle, string _text, string _FontName){ ObjectCreate(_n, OBJ_TEXT, _h, x, y); ObjectSet(_n, OBJPROP_ANGLE, _Angle); ObjectSetText(_n, _text, _FontSize, _FontName, _c); }
//+——————————————————————+
// 骂玮疣弪 觐眚尻耱 篑蝠铋耱?觌桧蝰觐?钺豚耱?沭圄桕??玎溧眄 珥圜屙桢?疣珈屦??磬玮囗? 梏蜞
// 吾玎蝈朦眍 眢骓?恹玮囹?趔黻鲨?
void GetDCWithFontNameAndSize(string _font_name, int _font_size){
DC_hWnd=WindowHandle(Symbol(), Period());
DC_hnd = GetDC(DC_hWnd);
int dpi=GetDeviceCaps(DC_hnd,88); //88=LOGPIXELSX
int fontheight = MathRound(_font_size*dpi/72.0);
DC_hFont=CreateFontA(fontheight,0,0,0,0,0,0,0,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_MODERN,_font_name);
SelectObject(DC_hnd,DC_hFont);
}
// 务忸犷驿噱?钺牝?DC ?Font
void DCRelease(){ ReleaseDC(DC_hWnd,DC_hnd); DeleteObject(DC_hFont); DC_hWnd = 0; DC_hFont = 0; DC_hnd = 0; }
// 项塍鬣弪 疣珈屦 耱痤觇 ?镨犟咫?
int GetStringSizeInPix(string _str){
int size[2];
GetTextExtentPoint32A(DC_hnd,_str,StringLen(_str),size);
return(size[0]+4);
}
//+——————————————————————+
// 泽黻鲨 疣耨麒螓忄弪 箴钼屙?爨疰??镳铞屙蜞?
double InfoGetMarginLevel(){ double dMarginNow = AccountMargin(); if(dMarginNow==0) dMarginNow = 1; return(NormalizeDouble(((AccountEquity()/dMarginNow)*100),2)); }
//+——————————————————————+
// 泽黻鲨 忸玮疣弪 桧纛痨圉棹 ?镱耠邃礤?铗牮铎 铕溴疱 (铕溴?妁?礤 玎牮)
////// 相疣戾瘥:
// _symbol – 桧耱痼戾眚 潆 镱桉赅 铕溴疣 (“” – 镱桉?镱 怦屐 桧耱痼戾眚囔)
// _type_order – 蜩?桉觐祛泐 铕溴疣 (-1 – 膻犷?蜩?
// 灭箫镱忸?恹犷?
// 99 – 埋?铕溴疣
// 10 – Buy ?Sell
// 50 – 悟腩驽眄 (BuyStop, BuyLimit, SellStop, SellLimit)
// 51 – BuyStop ?BuyLimit
// 52 – SellStop ?SellLimit
// 53 – BuyStop ?SellStop
// 54 – BuyLimit ?SellLimit
// _magic – 箜桕嚯 眍戾?铕溴疣 桦?
// -1 – 镱桉?礤 玎忤耔?铗 箜桕嚯钽?眍戾疣
// 99 – 镱桉?镱 戾滏桕囔 Magic_martin ?Magic_piramid
// _comment – 耱痤赅 觐蝾痼?漕腈屙 耦溴疰囹?觐祆屙蜞痂?铕溴疣 (“” – 镱桉?礤 玎忤耔?铗 觐祆屙蜞痂 铕溴疣)
////// 青镱腠屐 爨耨桠?(耱痼牝箴?:
// dblInfo – 溧眄 麒耠钼钽?蜩镟 (鲨麴?钺铉磬鬣 屐屙螓 爨耨桠?:
// 0 – OrderTicket, 眍戾?蜩赍蜞 铕溴疣
// 1 – OrderType, 蜩?铕溴疣
// 2 – OrderOpenTime, 怵屐 铗牮? 铕溴疣
// 3 – OrderOpenPrice, 鲥磬 铗牮? 铕溴疣
// 4 – OrderStopLoss, 鲥磬 玎牮? 镱玷鲨?镳?漕耱桄屙梃 箴钼? 筢铟眍耱?
// 5 – OrderTakeProfit, 鲥磬 玎牮? 镱玷鲨?镳?漕耱桄屙梃 箴钼? 镳栳铖蜩
// 6 – OrderLots, 钺?铕溴疣
// 7 – OrderMagicNumber, 箜桕嚯 眍戾?铕溴疣
// 8 – OrderProfit, 珥圜屙桢 麒耱铋 镳栳?
// 9 – OrderCommission, 珥圜屙桢 疣耨麒蜞眄铋 觐扈耨梃
// 10- OrderSwap, 珥圜屙桢 疋铒?
// strInfo – 溧眄 耱痤觐忸泐 蜩镟:
// 0 – OrderSymbol, 桧耱痼戾眚 镱 觐蝾痤祗 铗牮 铕溴疣
// 1 – OrderComment, 觐祆屙蜞痂?恹狃囗眍泐 铕溴疣
//-// true 羼腓 桧纛痨圉? 耦狃囗? false ?镳铗桠眍?耠篦噱
bool OrdersGetLastOpenInfo(string _symbol, int _type_order, int _magic, string _comment, double& dblInfo[], string& strInfo[]){
bool res = false;
datetime time = 0;
int ticket = 0;

for(int i=OrdersTotal()-1;i>=0;i–){
if(OrderSelect(i,SELECT_BY_POS)){
if((time==0 || OrderOpenTime()>time) &&
(_symbol==”” || OrderSymbol()==_symbol) &&
(_type_order==-1 || InfoisTypeOrdPartOfGroup(OrderType(), _type_order)) &&
(_magic==-1 || _magic==OrderMagicNumber() || (_magic==99 && (Magic_martin==OrderMagicNumber() ||/* MagicRuchnik==OrderMagicNumber() ||*/ Magic_piramid==OrderMagicNumber()))) &&
(_comment==”” || StringFind(OrderComment(),_comment)!=-1))
{
time = OrderOpenTime();
ticket = OrderTicket();
}
}
}
if(time>0){
if(OrderSelect(ticket,SELECT_BY_TICKET)){
ArrayResize(dblInfo,11); ArrayInitialize(dblInfo,0);
ArrayResize(strInfo,2);
dblInfo[0] = OrderTicket();
dblInfo[1] = OrderType();
dblInfo[2] = OrderOpenTime();
dblInfo[3] = OrderOpenPrice();
dblInfo[4] = OrderStopLoss();
dblInfo[5] = OrderTakeProfit();
dblInfo[6] = OrderLots();
dblInfo[7] = OrderMagicNumber();
dblInfo[8] = OrderProfit();
dblInfo[9] = OrderCommission();
dblInfo[10]= OrderSwap();
strInfo[0] = OrderSymbol();
strInfo[1] = OrderComment();
res = true;
}
}
if(!res){
ArrayResize(dblInfo,0);
ArrayResize(strInfo,0);
}
return(res);
}
//+——————————————————————+
// 蔓镱腠弪 玎牮桢 镱 蚁 ?茵彘腓磴?
//-// 忸玮疣弪 true 羼腓 铕溴疣 猁腓 玎牮?
bool CloseByTPAndTral(){
bool _res = false;
//
if(TralPrice > 0.0){
switch(TralType){
case OP_BUY:
if(Bid <= TralPrice){
PlaySound(“wait.wav”);
OrdersClose(33, Magic_martin, true, _Symbol, “”);
OrdersClose(33, Magic_piramid, true, _Symbol, “”);
OrdersClose(33, MagicRuchnik, true, _Symbol, “”);
StartBPrice = -1;
StartSPrice = -1;
OpenCloseLineDraw();

if(!NewCycle_ON) isWorking = false;
else{
Sleep(PauseTrade2*60000);
}
TralPrice = 0.0;
StopMartin = false;
StopPiramid = false;
return(true);
}else{
if(NormalizeDouble(Bid-TralPrice,Digits) >= Tral_Size){
TralPrice = NormalizeDouble(Bid-Tral_Size,Digits);
}
}
break;
case OP_SELL:
if(Ask >= TralPrice){
PlaySound(“wait.wav”);
OrdersClose(33, Magic_martin, true, _Symbol, “”);
OrdersClose(33, Magic_piramid, true, _Symbol, “”);
OrdersClose(33, MagicRuchnik, true, _Symbol, “”);
StartBPrice = -1;
StartSPrice = -1;
OpenCloseLineDraw();

if(!NewCycle_ON) isWorking = false;
else{
Sleep(PauseTrade2*60000);
}
TralPrice = 0.0;
StopMartin = false;
StopPiramid = false;
return(true);
}else{
if(NormalizeDouble(TralPrice-Ask,Digits) >= Tral_Size){
TralPrice = NormalizeDouble(Ask+Tral_Size,Digits);
}
}
break;
}
}else{
// 橡钼屦赅 漕耱桄屙? 箴钼? StartTral
if(TralStartPrice > 0.0){
switch(TralType){
case OP_BUY:
if(NormalizeDouble(Bid-TralStartPrice,Digits) >= 0.0){
TralPrice = NormalizeDouble(Bid-Tral_Size,Digits);
PlaySound(“wait.wav”);
OrdersClose(2, Magic_piramid, true, _Symbol, “”);
OrdersClose(2, Magic_martin, true, _Symbol, “”);
OrdersClose(33, MagicRuchnik, true, _Symbol, “”);
StartBPrice = -1;
//StartSPrice = -1;
OpenCloseLineDraw();

TralStartPrice = 0.0;
return(true);
}
break;
case OP_SELL:
if(NormalizeDouble(TralStartPrice-Ask,Digits) >= 0.0){
TralPrice = NormalizeDouble(Ask+Tral_Size,Digits);
PlaySound(“wait.wav”);
OrdersClose(0, Magic_piramid, true, _Symbol, “”);
OrdersClose(0, Magic_martin, true, _Symbol, “”);
OrdersClose(33, MagicRuchnik, true, _Symbol, “”);
//StartBPrice = -1;
StartSPrice = -1;
OpenCloseLineDraw();

TralStartPrice = 0.0;
return(true);
}
break;
}
}
// 项聍栩囹屐 铗牮 钺禧 Buy ?Sell
double _buy_lot = OrdersGetOpenLot(_Symbol, OP_BUY, 99, “”, 0, 0);
double _sell_lot = OrdersGetOpenLot(_Symbol, OP_SELL, 99, “”, 0, 0);
// 物疱溴腓?赅觐?磬镳噔脲龛?桁邋?犷朦?钺?
int _type_ord_tp = EMPTY; if(_buy_lot > _sell_lot) _type_ord_tp = OP_BUY; else if(_buy_lot < _sell_lot) _type_ord_tp = OP_SELL;
// 项聍栩噱?耩邃睨?鲥眢 潆 礤钺躅滂祛泐 蜩镟
double _aver_price = 0.0;
double _tp_line = 0.0;
//
switch(_type_ord_tp){
case OP_BUY:
//_aver_price = OrdersGetAveragePrice(_Symbol, OP_BUY, 99, “”, 0, 0);
_aver_price = AveragePriceAllSeries(_buy_lot, _sell_lot);
if(_aver_price > 0.0){
_tp_line = NormalizeDouble(_aver_price + DefaultProfit,Digits);
// 篷腓 漕耱桡眢蜞 腓龛 蚁
if(Bid >= _tp_line){
// 愉嚯桁 怦?铗腩驽眄 铕溴疣
MBuyStop = 0.0;
MBuyStopLot = 0.0;
MBuyStopNumb= 0.0;
PSellStop = 0.0;
PSellStopLot = 0.0;
PSellStopNumb= 0.0;
PSellStopStopLoss=0.0;
PSellStopTakeProfit=0.0;
MSellStopStopLoss=0.0;
MSellStopTakeProfit=0.0;
// 橡钼屦桁 眢骓?腓 玎牮?怦?铕溴疣 耩噻?桦?蝾朦觐 鬣耱?- 铖蜞朦睇?蝠嚯栩?
if(!Trall_on){
// 青牮桢 怦艴 铕屦钼 钺睇?耧铖钺铎
PlaySound(“wait.wav”);
OrdersClose(33, Magic_martin, true, _Symbol, “”);
OrdersClose(33, Magic_piramid, true, _Symbol, “”);
OrdersClose(33, MagicRuchnik, true, _Symbol, “”);
StartBPrice = -1;
StartSPrice = -1;
OpenCloseLineDraw();

if(!NewCycle_ON) isWorking = false;
_res = true;
}else{
// 朽聍栩噱?箴钼屙?磬鬣豚 蝠彘腓磴?
TralStartPrice = NormalizeDouble(_tp_line+Tral_Start,Digits);
TralType = OP_BUY;
}
}else{
TralStartPrice = 0.0;
TralType = EMPTY;
}
}
break;
case OP_SELL:
//_aver_price = OrdersGetAveragePrice(_Symbol, OP_SELL, 99, “”, 0, 0);
_aver_price = AveragePriceAllSeries(_buy_lot, _sell_lot);
if(_aver_price > 0.0){
_tp_line = NormalizeDouble(_aver_price – DefaultProfit,Digits);
// 篷腓 漕耱桡眢蜞 腓龛 蚁
if(Ask <= _tp_line){
// 愉嚯桁 怦?铗腩驽眄 铕溴疣
MSellStop = 0.0;
MSellStopLot = 0.0;
MSellStopNumb= 0.0;
PBuyStop = 0.0;
PBuyStopLot = 0.0;
PBuyStopNumb= 0.0;
PBuyStopStopLoss=0.0;
PBuyStopTakeProfit=0.0;
MBuyStopStopLoss=0.0;
MBuyStopTakeProfit=0.0;
// 橡钼屦桁 眢骓?腓 玎牮?怦?铕溴疣 耩噻?桦?蝾朦觐 鬣耱?- 铖蜞朦睇?蝠嚯栩?
if(!Trall_on){
// 青牮桢 怦艴 铕屦钼 钺睇?耧铖钺铎
PlaySound(“wait.wav”);
OrdersClose(33, Magic_martin, true, _Symbol, “”);
OrdersClose(33, Magic_piramid, true, _Symbol, “”);
OrdersClose(33, MagicRuchnik, true, _Symbol, “”);
StartBPrice = -1;
StartSPrice = -1;
OpenCloseLineDraw();

if(!NewCycle_ON) isWorking = false;
_res = true;
}else{
// 朽聍栩噱?箴钼屙?磬鬣豚 蝠彘腓磴?
TralStartPrice = NormalizeDouble(_tp_line-Tral_Start,Digits);
TralType = OP_SELL;
}
}else{
TralStartPrice = 0.0;
TralType = EMPTY;
}
}
break;
}
//
AveregeLine = _aver_price;
TPLine = _tp_line;
}
return(_res);
}
//+——————————————————————+
// 泽黻鲨 疣聍栩噱?耩邃睨?鲥眢 怦艴 铗牮 铕溴痤?疣珥 磬镳噔脲龛?
double AveragePriceAllSeries(double _buy_lot, double _sell_lot){
double _res = 0.0;

double _buy_aver_price = OrdersGetAveragePrice(_Symbol, OP_BUY, 99, “”, 0, 0);
double _sell_aver_price = OrdersGetAveragePrice(_Symbol, OP_SELL, 99, “”, 0, 0);
double _lock_point = NormalizeDouble((_sell_aver_price-_buy_aver_price)/Point,0);
double _lock_in_currency = 0.0;
double _price_of_point = InfoGetPriceOfPoint(_Symbol);

// 吾疣犷蜿?耔蝮圉梃 觐沅?镱 钿眍祗 桤 磬镳噔脲龛?礤?铕溴痤?
if(_buy_aver_price == 0.0 && _sell_aver_price > 0.0){
_res = _sell_aver_price;
}else{
if(_buy_aver_price > 0.0 && _sell_aver_price == 0.0){
_res = _buy_aver_price;
}else{
if(_buy_lot < _sell_lot) _lock_in_currency = NormalizeDouble(_lock_point*(_price_of_point*_buy_lot),2);
else{
if(_lock_point > 0) _lock_point = -_lock_point;
else _lock_point = MathAbs(_lock_point);
_lock_in_currency = NormalizeDouble(_lock_point*(_price_of_point*_sell_lot),2);
}

double _target_lot = NormalizeDouble(MathAbs(_buy_lot-_sell_lot),iDigitLot);
if(_target_lot > 0.0){
int _target_pip = _lock_in_currency / (_target_lot * _price_of_point);
double _target_point = NormalizeDouble(_target_pip*Point,Digits);

if(_buy_lot > _sell_lot){
_res = NormalizeDouble(_buy_aver_price + _target_point,Digits);
}else{
_res = NormalizeDouble(_sell_aver_price + _target_point,Digits);
}
}
}
}
return(_res);
}
//+——————————————————————+
//泽黻鲨 忸玮瘗噱?耱铊祛耱?钿眍泐 矬黻蜞 磬 玎溧眄铋 镟疱 ?忄膻蝈 溴镱玷蜞 ?疣聍弪?磬 1 腩?
double InfoGetPriceOfPoint(string B)
{
RefreshRates();
double S = 0;
if(B!=””)
{
S = MarketInfo(B,MODE_TICKVALUE)/(MarketInfo(B,MODE_TICKSIZE)/MarketInfo(B,MODE_POINT));
}
return(S);
}
//+——————————————————————+
// 泽黻鲨 疣聍栩噱?耩邃睨?鲥眢 ?铕溴痤?镱 玎溧眄 镟疣戾蝠囔
// _symbol – 桧耱痼戾眚 (“”, 膻犷?桧耱痼戾眚)
// _type – 蜩?铕溴痤?(-1, 膻犷?蜩?镱玷鲨?
// _magic – 箜桕嚯 眍戾?铕溴痤?耦忮蝽桕?桦?
// -1 – 镱 膻犷祗 箜桕嚯铎?眍戾痼
// 99 – 镱桉?镱 戾滏桕囔 Magic_martin ?Magic_piramid
// _comm – 耱痤赅 觐蝾疣 漕腈磬 耦溴疰囹 ?觐祆屙蜞痂?(“”, ?膻猁?觐祆屙蜞痂屐)
// minOpenTime – 怵屐 铗牮? 铕溴疣 漕腈眍 猁螯 犷朦 桦?疣忭?玎溧眄铎?(0 – 礤 桉镱朦珞弪?)
// maxOpenTime – 怵屐 铗牮? 铕溴疣 漕腈眍 猁螯 戾睃 桦?疣忭?玎溧眄铎?(0 – 礤 桉镱朦珞弪?)
//-// 忸玮疣屐铄 珥圜屙桢: 耩邃? 鲥磬 桦?0 ?镳铗桠眍?耠篦噱
double OrdersGetAveragePrice(string _symbol, int _type, int _magic, string _comm, datetime minOpenTime, datetime maxOpenTime){
double dRes = 0, dSumLot=0, swap_comm = 0;
int _cnt_orders = 0;
double point_cost = InfoGetPriceOfPoint(_Symbol);

for(int i=OrdersTotal()-1;i>=0;i–){
if(OrderSelect(i,SELECT_BY_POS)){
if((_symbol==”” || OrderSymbol()==_symbol) &&
(_magic==-1 || OrderMagicNumber()==_magic || (_magic==99 && (OrderMagicNumber()==Magic_martin || OrderMagicNumber()==MagicRuchnik || OrderMagicNumber()==Magic_piramid))) &&
(_type==-1 || OrderType()==_type) &&
(_comm==”” || StringFind(OrderComment(),_comm)!=-1) &&
(minOpenTime==0 || OrderOpenTime()>=minOpenTime) &&
(maxOpenTime==0 || OrderOpenTime()<=maxOpenTime))
{
//— 篦弪 觐扈耨梃 ?疋铒?
if (OrderType() == OP_BUY) {
swap_comm = ((-1*OrderCommission())+OrderSwap())/OrderLots()*Point;
if (IsTesting()) swap_comm = (OrderSwap()/OrderLots()*Point)+(Test_com_in_pip*Point);
} else
if (OrderType() == OP_SELL) {
swap_comm = (OrderCommission()-OrderSwap())/OrderLots()*Point;
if (IsTesting()) swap_comm = (OrderSwap()/OrderLots()*Point)+(-1*Test_com_in_pip*Point);
}
//—
dRes += (OrderOpenPrice()+swap_comm)*OrderLots();
dSumLot += OrderLots();
_cnt_orders++;
}
}
}
if(_cnt_orders > 0){
dRes = NormalizeDouble(dRes/dSumLot,MarketInfo(_symbol,MODE_DIGITS));
}
return(dRes);
}
//+——————————————————————+
// 泽黻鲨 耋祆桊箦?觐?忸 铗牮 腩蝾?
// _symbol – 桧耱痼戾眚 (“”, 膻犷?桧耱痼戾眚)
// _type – 蜩?铕溴痤?(-1, 膻犷?蜩?镱玷鲨?
// 灭箫镱忸?恹犷?
// 99 – 埋?铕溴疣
// 10 – Buy ?Sell
// 50 – 悟腩驽眄 (BuyStop, BuyLimit, SellStop, SellLimit)
// 51 – BuyStop ?BuyLimit
// 52 – SellStop ?SellLimit
// 53 – BuyStop ?SellStop
// 54 – BuyLimit ?SellLimit
// _magic – 箜桕嚯 眍戾?铕溴痤?耦忮蝽桕?桦?
// -1 – 镱 膻犷祗 箜桕嚯铎?眍戾痼
// 99 – 镱桉?镱 戾滏桕囔 Magic_martin ?Magic_piramid
// _comm – 耱痤赅 觐蝾疣 漕腈磬 耦溴疰囹 ?觐祆屙蜞痂?(“”, ?膻猁?觐祆屙蜞痂屐)
// minOpenTime – 怵屐 铗牮? 铕溴疣 漕腈眍 猁螯 犷朦 桦?疣忭?玎溧眄铎?(0 – 礤 桉镱朦珞弪?)
// maxOpenTime – 怵屐 铗牮? 铕溴疣 漕腈眍 猁螯 戾睃 桦?疣忭?玎溧眄铎?(0 – 礤 桉镱朦珞弪?)
//-// 骂玮疣弪 觐?忸 铗牮 铕溴痤?桦?0
double OrdersGetOpenLot(string _symbol, int _type, int _magic, string _comm, datetime minOpenTime, datetime maxOpenTime){
int a1,order_type;
double lot=0;

for(a1=OrdersTotal()-1;a1>=0;a1–){
if(OrderSelect(a1,SELECT_BY_POS)){
if((_symbol==”” || OrderSymbol()==_symbol) &&
(_magic==-1 || OrderMagicNumber()==_magic || (_magic==99 && (OrderMagicNumber()==Magic_martin || OrderMagicNumber()==MagicRuchnik || OrderMagicNumber()==Magic_piramid))) &&
(_comm==”” || StringFind(OrderComment(),_comm)==-1) &&
(minOpenTime==0 || OrderOpenTime()>=minOpenTime) &&
(maxOpenTime==0 || OrderOpenTime()<=maxOpenTime))
{
if(_type==99){
lot +=OrderLots();
}else{
order_type = OrderType();
if((_type==OP_BUY || _type==10) && order_type==OP_BUY) lot +=OrderLots();
if((_type==OP_SELL || _type==10) && order_type==OP_SELL)lot+=OrderLots();
if((_type==OP_SELLSTOP || _type==50 || _type==52 || _type==53) && order_type==OP_SELLSTOP) lot+=OrderLots();
if((_type==OP_BUYSTOP || _type==50 || _type==51 || _type==53) && order_type==OP_BUYSTOP) lot+=OrderLots();
if((_type==OP_SELLLIMIT || _type==50 || _type==52 || _type==54) && order_type==OP_SELLLIMIT)lot+=OrderLots();
if((_type==OP_BUYLIMIT || _type==50 || _type==51 || _type==54) && order_type==OP_BUYLIMIT) lot+=OrderLots();
}
}
}
}
return(lot);
}
//+——————————————————————+
// 悟牮桢 忤痼嚯 铗腩驽眄 铕溴痤?
void OpenVirtPendOrd(){
if(Metod==2){
if(MSellStop > 0.0){
if(Bid <= MSellStop){
if((M()==-1 && Vxod_M==1) || Vxod_M==0 || (M2()==-1 && Vxod_M2==1) || Vxod_M2==0) //我市垡扰 涡呐欣 衔 韧娜世椅杏 膛娜犹
SendOrder(OP_SELL, MSellStopLot, Bid, Magic_martin, DoubleToStr(MSellStopNumb,0)+”:martin”,0,0);
MModifyOrders(OP_SELL);
Sleep(PauseTrade*1000);

MSellStop = 0.0;
MSellStopLot = 0.0;
MSellStopNumb = 0;
//MSellStopStopLoss = 0.0;
//MSellStopTakeProfit = 0.0;
}
}

if(MBuyStop > 0.0){
if(Ask >= MBuyStop){
if((M()==1 && Vxod_M==1) || Vxod_M==0 || (M2()==1 && Vxod_M2==1) || Vxod_M2==0) //我市垡扰 涡呐欣 衔 韧娜世椅杏 膛娜犹
SendOrder(OP_BUY, MBuyStopLot, Ask, Magic_martin, DoubleToStr(MBuyStopNumb,0)+”:martin”,0,0);
MModifyOrders(OP_BUY);
Sleep(PauseTrade*1000);

MBuyStopLot = 0.0;
MBuyStopNumb = 0;
MBuyStop = 0.0;
// MBuyStopStopLoss = 0.0;
//MBuyStopTakeProfit = 0.0;
}
}

if(PSellStop > 0.0){
if(Bid <= PSellStop){
if((P()==-1 && Vxod_P==1) || Vxod_P==0 || (P2()==-1 && Vxod_P2==1) || Vxod_P2==0) //我市垡扰 涡呐欣 衔 韧娜世椅杏 膛娜犹
SendOrder(OP_SELL, PSellStopLot, Bid, Magic_piramid, DoubleToStr(PSellStopNumb,0)+”:piramid”,0,0);
PModifyOrders (OP_SELL);
//
Sleep(PauseTrade*1000);
//
PSellStopLot = 0.0;
PSellStopNumb = 0;
PSellStop = 0.0;
//PSellStopStopLoss=0.0;
//PSellStopTakeProfit=0.0;
}
}

if(PBuyStop > 0.0){
if(Ask >= PBuyStop){
if((P()==1 && Vxod_P==1) || Vxod_P==0 || (P2()==1 && Vxod_P2==1) || Vxod_P2==0) //我市垡扰 涡呐欣 衔 韧娜世椅杏 膛娜犹
SendOrder(OP_BUY, PBuyStopLot, Ask, Magic_piramid, DoubleToStr(PBuyStopNumb,0)+”:piramid”,0,0);
PModifyOrders (OP_BUY);
//
Sleep(PauseTrade*1000);
//
PBuyStopLot = 0.0;
PBuyStopNumb = 0;
PBuyStop = 0.0;
//PBuyStopStopLoss = 0.0;
//PBuyStopTakeProfit = 0.0;
}
}
}
}

//+——————————————————————+
// 蔓镱腠弪 蝠彘腓磴 忤痱筻朦睇?铗腩驽眄 铕溴痤?铗牮 镱 爨痱桊眢 桦?镨疣扈溴 镳?戾蝾溴 2
void TrailVirtPendOrd(){
double _val = 0.0;
if(Metod==2){
if(MSellStop > 0.0){
if(NormalizeDouble(Bid-MSellStop,Digits) > Step){
_val = NormalizeDouble(Bid-Dist,Digits);
if(_val > MSellStop){
MSellStop = _val;
//Print(“MSellStop = “+MSellStop);
}
}
}
if(MBuyStop > 0.0){
if(NormalizeDouble(MBuyStop-Ask,Digits) > Step){
_val = NormalizeDouble(Ask+Dist,Digits);
if(_val < MBuyStop){
MBuyStop = _val;
//Print(“MBuyStop=”+MBuyStop);
}
}
}
if(PSellStop > 0.0){
if(NormalizeDouble(Bid-PSellStop,Digits) > Step){
_val = NormalizeDouble(Bid-Dist,Digits);
if(_val > PSellStop){
PSellStop = _val;
//Print(“PSellStop=”+PSellStop);
}
}
}
if(PBuyStop > 0.0){
if(NormalizeDouble(PBuyStop-Ask,Digits) > Step){
_val = NormalizeDouble(Ask+Dist,Digits);
if(_val < PBuyStop){
PBuyStop = _val;
//Print(“PBuySto=”+PBuyStop);
}
}
}
}
}
//+——————————————————————+
// 青牮噱?铕溴疣 镳?漕耱桄屙梃 玎溧眄钽?筢赅 ?忄膻蝈 溴镱玷蜞
// 骂玮疣弪 true 羼腓 玎牮桢 耦耱?腩顸 ?false 羼腓 礤?
bool CloseByStopLoss(){
bool _res = false;
//if(StopLoss > 0.0)
if (AccountEquity()<=AccountBalance()*(1-StopLoss /100))
{
double _all_result = OrdersGetProfit(99, 11, _Symbol, “”);
if(_all_result <= -StopLoss){
PlaySound(“wait.wav”);
OrdersClose(33, Magic_martin, true, _Symbol, “”);
OrdersClose(33, Magic_piramid, true, _Symbol, “”);
OrdersClose(33, MagicRuchnik, true, _Symbol, “”);
StartBPrice = -1;
StartSPrice = -1;
OpenCloseLineDraw();

if(!NewCycle_ON){
isWorking = false;
}else{
Sleep(PauseTrade2*60000);
}
_res = true;

StopMartin = false;
StopPiramid = false;
}
}
return(_res);
}
//+——————————————————————+
// 玛膻麇龛?镨疣扈潲 镳?漕耱桄屙梃 玎溧眄铋 镳铖噤觇
void EnablePiramid(){
if(!PiramidOn && PiramidStart > 0.0 && !PiramidAutoStart){

double _buy_result = OrdersGetProfit(99, OP_BUY, _Symbol, “”);
double _sell_result = OrdersGetProfit(99, OP_SELL, _Symbol, “”);
double _all_result = _buy_result+_sell_result;

if(NormalizeDouble((_all_result/AccountBalance())*100,2) <= -PiramidStart){
PiramidAutoStart = true;

double _open_martin = 0.0;
// 物疱溴腓?赅觐?桤 磬镳噔脲龛?蝾疸钼腓 怆弪? 爨痱桧铎
if(_buy_result < 0.0 && _sell_result >= 0.0){
// 项聍栩噱?钺?铗牮 爨痱桧 铕溴痤?
_open_martin = OrdersGetOpenLot(_Symbol, OP_BUY, Magic_martin, “:start”, 0, 0);
}else
if(_buy_result >= 0.0 && _sell_result < 0.0){
// 项聍栩噱?钺?铗牮 爨痱桧 铕溴痤?
_open_martin = OrdersGetOpenLot(_Symbol, OP_SELL, Magic_martin, “:start”, 0, 0);
}

// 朽耨麒蜞屐 礤钺躅滂禧?疣珈屦 腩蜞 镨疣扈潲
PiramidStartLot = NormalizeDouble(_open_martin*(Persen_open/100),iDigitLot);
if(PiramidStartLot > MarketInfo(_Symbol,MODE_MAXLOT)) PiramidStartLot = MarketInfo(_Symbol,MODE_MAXLOT);
if(PiramidStartLot < MarketInfo(_Symbol,MODE_MINLOT)) PiramidStartLot = MarketInfo(_Symbol,MODE_MINLOT);
}
}
}
//+——————————————————————+
// Revers
void ReversPiramid(int m_sell, int m_buy) {
///if(!PiramidOn && PiramidStart > 0.0 && !PiramidAutoStart){

double _buy_result = OrdersGetProfit(99, OP_BUY, _Symbol, “”);
double _sell_result = OrdersGetProfit(99, OP_SELL, _Symbol, “”);
//double _all_result = MathAbs(_buy_result+_sell_result);

if (_buy_result + _sell_result != 0) {
/* if(_buy_result < 0.0 && _sell_result >= 0.0){
Buy_flag = martin_flag;
Sell_flag = piramid_flag;
} else {
if(_buy_result >= 0.0 && _sell_result < 0.0){
Buy_flag = piramid_flag;
Sell_flag = martin_flag;
}
Magic_piramid = MagicPiramid;
Magic_martin = MagicMartin;
} */
if(NormalizeDouble((_buy_result/AccountBalance())*100,2) <= -PiramidRevers && m_buy == Magic_piramid){
Buy_flag = martin_flag;
Sell_flag = piramid_flag;
Magic_piramid = MagicMartin;
Magic_martin = MagicPiramid;
Martin_On = true;
}
if(NormalizeDouble((_sell_result/AccountBalance())*100,2) <= -PiramidRevers && m_sell == Magic_piramid){
Buy_flag = piramid_flag;
Sell_flag = martin_flag;
Magic_piramid = MagicMartin;
Magic_martin = MagicPiramid;
Martin_On = true;
}
}
GlobalVariableSet(“Buy_flag”,Buy_flag);
GlobalVariableSet(“Sell_flag”,Sell_flag);
GlobalVariableSet(“M_piramid”,Magic_piramid);
GlobalVariableSet(“M_martin”,Magic_martin);
}
//+——————————————————————+
// 泽黻鲨 痂耋弪 腓龛?戾驿?蝾麝铋 铗牮? ?玎牮? 铕溴痤?
void OpenCloseLineDraw(){
// 翌朦觐 ?铐豚轫 疱骅戾
if(Info /*&& !IsTesting() && !IsOptimization()*/){
string _name = “”;
color _clr = CLR_NONE;
for(int i=OrdersHistoryTotal()-1;i>=0;i–){
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)){
if(OrderSymbol()==Symbol() && (OrderMagicNumber() == Magic_martin || OrderMagicNumber() == Magic_piramid) && OrderType()<2){
_name = “close line by #”+DoubleToStr(OrderTicket(),0);
if(ObjectFind(_name)==-1){
if(OrderType()==OP_BUY) _clr = clrBlue; else _clr = clrRed;
GraphTrendLineCreate(_name, 0, OrderOpenTime(), OrderOpenPrice(), OrderCloseTime(), OrderClosePrice(), false, _clr, STYLE_DOT, 1);
}
}
}
}
}
}
//+——————————————————————+
// 泽黻鲨 耦玟噱?钺牝 Trend Line ?玎溧眄铎 铌礤(镱?铌礤) 沭圄桕? ?玎溧眄 桁屙屐, 觐铕滂磬蜞扈, 桉镱朦珙忄龛?塍黧 桦?腓龛? 鲡弪? 耱桦 腓龛?? 痂睇 腓龛?
void GraphTrendLineCreate(string sName, int _iHandle, datetime _x1, double _y1, datetime _x2, double _y2, bool _isRay, color _MyColor, int _iStyle, int _Width){ ObjectCreate(sName, OBJ_TREND, _iHandle, _x1, _y1, _x2, _y2); ObjectSet(sName, OBJPROP_RAY, _isRay); ObjectSet(sName, OBJPROP_COLOR, _MyColor); ObjectSet(sName, OBJPROP_STYLE, _iStyle); ObjectSet(sName,OBJPROP_WIDTH,_Width); }
//+——————————————————————+
// 泽黻鲨 镱塍鬣弪 蝈牦?镳铘栩 镱 钿眍?桦?礤耜铍桁 镱玷鲨?
// _m – 箜桕嚯 眍戾?铕溴痤?桦?
// -1 – 礤 篦栩噱蝰
// 99 – 镱桉?镱 戾滏桕囔 Magic_martin ?Magic_piramid
// _type – 蜩?铕溴痤?(-1, 膻犷?蜩?镱玷鲨?, 沭箫镱忄 钺疣犷蜿?
// 11 – 瘥眍黜 镱玷鲨?
// 12 – 铗腩驽眄 铕溴疣
// _s – 桧耱痼戾眚 (-1, 膻犷?桧耱痼戾眚)
// _scomm – 耱痤赅 觐蝾疣 漕腈磬 耦溴疰囹 ?觐祆屙蜞痂?(“”, ?膻猁?觐祆屙蜞痂屐)
double OrdersGetProfit(int _m, int _type, string _s, string _scomm){
double dRes = 0;
for(int i=OrdersTotal()-1;i>=0;i–){
if(OrderSelect(i,SELECT_BY_POS)){
if((_m==-1 || OrderMagicNumber()==_m || (_m==99 && (Magic_martin==OrderMagicNumber()|| MagicRuchnik==OrderMagicNumber() || Magic_piramid==OrderMagicNumber()))) &&
(_s==”” || _s==OrderSymbol()) &&
(_scomm==”” || StringFind(OrderComment(),_scomm)!=-1) &&
(_type==-1 || _type==OrderType() || (_type==11 && OrderType()<2) || (_type==12 && OrderType()>1)))
{
dRes += OrderProfit()+OrderCommission()+OrderSwap();
}
}
}
return(NormalizeDouble(dRes,2));
}
//+——————————————————————+
// 泽黻鲨 忸玮疣弪 钺?耠邃簋泐 铕溴疣 ?玎忤耔祛耱?铗 蜩镟
// 0 – 铗牮桢 镥疴 铕溴痤?鲥镱麝?
double GetLot(int _type=1, double _lst_lot = 0.0, int _number_order = 0, double _real_step = 0.0, double _target_step = 0.0){
double _res = 0.0;
switch(_type){
case 1: // 祟?潆 镥疴 铕溴痤?
if(Risk==0.0){
_res = DefaultLot;
}else{
_res = InfoLotPersentOfDeposit(_Symbol, Risk, iDigitLot);
}
break;
case 2: // 祟?潆 爨痱桧 铕溴疣
if(_number_order >= 1){
if(!FixLot && CCI_On && !PiramidOn){
// 项聍栩噱?疣珈屦 徉珙忸泐 腩蜞
_res = NormalizeDouble(_lst_lot*GetMartinLotExponent(_number_order),iDigitLot);
// 项聍栩噱?磬 耜铍?眢骓?筲咫梓栩?疣珈屦 徉珙忸泐 腩蜞 ?玎忤耔祛耱?铗 镳铋溴眄 矬黻蝾?
if(_real_step > _target_step){
double _lot_exponent = NormalizeDouble(_real_step/_target_step,2);
_res = NormalizeDouble(_res*_lot_exponent,iDigitLot);
}
}else{
_res = NormalizeDouble(_lst_lot*GetMartinLotExponent(_number_order),iDigitLot);
}
} else {
_res = GetLot();
}
break;
case 3: // 祟?潆 铕溴疣 镨疣扈潲

if(_number_order == 0){
_res = _lst_lot;
}else{
_res = NormalizeDouble(_lst_lot*GetPiramidLotExponent(_number_order),iDigitLot);
}
break;
}
return(_res);
}
//+——————————————————————+
// 悟镳噔赅 镳桕噻?
void SendOrder(int _type, double _dlot, double _price, int _magic, string _comment, double _stoploss = 0.0, double _takeprofit = 0.0){
// 暑眚痤朦磬 镳钼屦赅 疣珈屦?腩蜞
if(_dlot > MaxLot) _dlot = MaxLot;
// 橡钼屦赅 磬 漕耱囹铟眍耱?耩邃耱?磬 聍弪?
bool _check_margin = true;
ResetLastError();
if(AccountFreeMarginCheck(_Symbol,_type,_dlot)<=0.0 || GetLastError()==134){
_check_margin = false;
}
if(_check_margin){
// 悟镳噔赅 镳桕噻?磬 铗牮桢 铕溴疣
OrdersOpen(InfoGetTypeTrdOperInInterFrm(_type), _dlot, _price, _Symbol, _comment, _stoploss, _takeprofit, iDigitLot, Slippege, _magic, iTicket);
// 勿溴疣 礤 猁?铗牮 – 牮栩梓羼赅 铠栳赅
if(iTicket < 0){
// 聋豚 镱稃蜿?铌蝠桢 镥疴钽?铕溴疣 皴痂?
if(_comment == “1:start”){
Alert(“马桁囗桢!署栩梓羼赅 铠栳赅 镳?铗牮梃 镥疴钽?铕溴疣 皴痂?勿溴?礤 猁?铗牮!”);
}
PlaySound(“stops.wav”);
}else{
PlaySound(“ok.wav”);
}
}else{
Comment(“马桁囗桢! 湾 漕耱囹铟眍 耩邃耱?潆 铗牮? 眍忸泐 铕溴疣!”);
Print ( “湾 漕耱囹铟眍 耩邃耱?潆 铗牮? 眍忸泐 铕溴疣! “);
Sleep (10000);
CommentSet = true;

}
}
//+——————————————————————+
// 骂玮疣弪 true 羼腓 礤钺躅滂祛 铖蜞眍忤螯 铗牮桢 爨痱桧 铕溴痤?镱耠?玎溧眄钽?觐脲磬
bool fStopMartin(int _number_order){
bool _res = false;
if(MartinOnNew && _number_order >= LotNoM){
_res = true;
StopMartin = true;
}
return(_res);
}
//+——————————————————————+
// 骂玮疣弪 true 羼腓 礤钺躅滂祛 铖蜞眍忤螯 铗牮桢 铕溴痤??镨疣扈溴 镱耠?玎溧眄钽?觐脲磬
bool fStopPiramid(int _number_order){
bool _res = false;
if(PiramidOnNew && _number_order >= LotNoP){
_res = true;
StopPiramid = true;
}
return(_res);
}
//+——————————————————————+
// 骂玮疣弪 觐?忸 矬黻蝾?铗 鲥睇 铗牮? 镳邃簌邈?铕溴疣 潆 铗牮? 眍忸泐 爨痱桧 铕溴疣
double GetMartinStepPip(int _number_order){
double _res = MartinStep;
if(MartinOnNew && _number_order >= LotN_M){
if(MartinK_Step > 0.0){
_res = MartinStepNew * MathPow(MartinK_Step,_number_order-LotN_M);
}else _res = MartinStepNew;
}
return(_res);
}
//+——————————————————————+
// 骂玮疣弪 觐?忸 矬黻蝾?铗 鲥睇 铗牮? 镳邃簌邈?铕溴疣 潆 铗牮? 眍忸泐 铕溴疣 ?镨疣扈溴
double GetPiramidStepPip(int _number_order){
double _res = 0.0;
if(Metod==2 && PiramidOn && Martin_On){
_res = MartinStep;
if(MartinOnNew && _number_order >= LotN_M){
_res = MartinStepNew;
}
}else{
_res = PiramidStep;
if(PiramidOnNew && _number_order >= LotN_P){
_res = PiramidStepNew;
}
}
return(_res);
}
//+——————————————————————+
// 骂玮疣弪 祉铈栩咫?腩蜞 潆 铗牮? 爨痱桧 铕溴疣
double GetMartinLotExponent(int _number_order){
double _res = MartinLotExponent;
if(MartinOnNew && _number_order >= LotN_M){
_res = MartinLotExponenNew;
}
return(_res);
}
//+——————————————————————+
// 骂玮疣弪 祉铈栩咫?腩蜞 潆 铗牮? 铕溴疣 ?镨疣扈溴
double GetPiramidLotExponent(int _number_order){
double _res = PiramidLotExponent;
if(PiramidOnNew && _number_order >= LotN_P){
_res = PiramidLotExponenNew;
}
return(_res);
}
//+——————————————————————+
// 暑礅屦蜩痼弪 蜩稃 蝾疸钼 铒屦圉栝 MT 忸 忭篁疱眄邋 镳邃耱噔脲龛?潆 泽黻鲨?Order.Open
// _type – 蜩?蝾疸钼铋 铒屦圉梃
//-// 骂玮瘗噱?蜩?蝾疸钼铋 铒屦圉梃 忸 忭篁疱眄屐 镳邃耱噔脲龛?桦?-1
int InfoGetTypeTrdOperInInterFrm(int _type){ int _res = -1; switch(_type){ case OP_BUY: _res = 1; break; case OP_SELL: _res = 2; break; case OP_BUYSTOP: _res = 3; break; case OP_SELLSTOP: _res = 4; break; case OP_BUYLIMIT: _res = 5; break; case OP_SELLLIMIT: _res = 6; break; } return(_res); }
//+——————————————————————+
// 泽黻鲨 疣聍栩噱?腩?磬 铖眍忄龛?玎溧眄钽?镳铞屙蜞 铗 溴镱玷蜞
// _Symb – 桧耱痼戾眚 镱 觐蝾痤祗 狍溴?铗牮?镱玷鲨
// _dPersent – 镳铞屙?铗 溴镱玷蜞
// _iDigitLot – 蝾黜铖螯 腩蜞
// _isCalcRealPos – 篦栩囹?蝈牦?铗牮桢 镱玷鲨?(true – 溧, false – 礤?. 橡?铎 篦栩帼蝰 镱玷鲨??篑蜞眍怆屙 阉
// _imagic – 箜桕嚯 眍戾?铕溴痤?觐蝾瘥?眢骓?篦栩囹?(-1, 篦栩囹?怦?铕溴疣), 镱 箪铍鬣龛?-1
//-// 骂玮疣弪 疣珈屦 铗牮噱祛泐 腩蜞
double InfoLotPersentOfDeposit(string _Symb, double _dPersent, int _iDigitLot){
double dL = 0;
double One_Lot = MarketInfo(_Symb,MODE_MARGINREQUIRED);
double Balance = AccountEquity();
double dPriceP = 0;
double dLossRes = 0;
int iTypeOrder = 0;

dL = NormalizeDouble(Balance*_dPersent/100/One_Lot,_iDigitLot);
if(dL<MarketInfo(_Symb,MODE_MINLOT)){
Print(“朽聍栩囗睇?腩?”+DoubleToStr(dL,2)+”) 戾睃 扈龛爨朦眍泐(“+DoubleToStr(MarketInfo(_Symb,MODE_MINLOT),2)+”). 祟?桤戾礤?磬 扈龛爨朦睇?”);
dL=MarketInfo(_Symb,MODE_MINLOT);
}
if(dL>MarketInfo(_Symb,MODE_MAXLOT)){
Print(“朽聍栩囗睇?腩?”+DoubleToStr(dL,2)+”) 犷朦 爨犟桁嚯钽?”+DoubleToStr(MarketInfo(_Symb,MODE_MAXLOT),2)+”). 祟?桤戾礤?磬 爨犟桁嚯.”);
dL=MarketInfo(_Symb,MODE_MAXLOT);
}
return(dL);
}
//+——————————————————————+
// 蔓镱腠弪 溴蜞朦眍?腩汨痤忄龛?
//void Log(string _str){ if(Info) Print(“_str”); }
//+——————————————————————+
// 蔓镱腠弪 溴蜞朦眍?腩汨痤忄龛?镳?铗豚潢?
//void Debug(string _str){ Print(“DEBUG :: “+_str); }
//+——————————————————————+
// 襄疱忸滂?鲥腩?珥圜屙桢 ?漯钺眍?镱 觐?怏 珥嚓钼 ?觐蜩痤怅圊
// symbol – 桧耱痼戾眚 镱 觐蝾痤祗 铒疱溴?弪? 蝾黜铖螯 觐蜩痤忸?
// v – 珥圜屙桢 镥疱溧眄铄 镱 耨赍, 觐蝾痤?眢骓?觐礅屦蜩痤忄螯
//–// 湾 忸玮疣弪 珥圜屙桢
void InfoChangeToDigit(string symbol, double& v) { v *= MarketInfo(symbol,MODE_TICKSIZE); return; }
//+——————————————————————+
// 泽黻鲨 箐嚯弪 钺牝?桁屙?觐蝾瘥?耦溴疰囹 镥疱溧眄簋 耱痤牦
void GraphDelete(string _sName){ for(int i=0;i<ObjectsTotal();i++){ if(StringFind(ObjectName(i),_sName,0)!=-1){ ObjectDelete(ObjectName(i)); i=-1; } } }
//+——————————————————————++
// 皖痨嚯桤桊箦?镥疱溧眄铄 珥圜屙桢 钺爨 镱玷鲨?
// _symbol – 磬玮囗桢 桧耱痼戾眚?
// _volume – 钺?觐蝾瘥?眢骓?铌痼汶栩?
// _round_met – 耧铖钺 铌痼沐脲龛 (false – 忭桤 (镱 箪铍鬣龛?, true – 忖屦?
double InfoNormalizeVolume(string _symbol, double _volume, bool _round_met=false, bool _pre_round = true){ double new_volume = -1, k; if (_symbol==””) _symbol=Symbol(); double lot_step=MarketInfo(_symbol, MODE_LOTSTEP); double min_lot=MarketInfo(_symbol, MODE_MINLOT); double max_lot=MarketInfo(_symbol, MODE_MAXLOT); int digit_lot = InfoGetLotDigit(_symbol); if(_pre_round) _volume = NormalizeDouble(_volume,digit_lot); if(min_lot>0 && max_lot>0){ if (lot_step>0) k=1/lot_step; else k=1/min_lot; if (_round_met) new_volume = MathCeil(_volume*k)/k; else new_volume = MathFloor(_volume*k)/k; if (new_volume<min_lot) new_volume=min_lot; if (new_volume>max_lot) new_volume=max_lot; if(NormalizeDouble(_volume-new_volume,digit_lot)!=0) Print(“InfoNormalizeVolume : 腩?(“+DoubleToStr(_volume,digit_lot)+”) 猁?铌痼汶屙 漕 “+DoubleToStr(new_volume,digit_lot)); } return(NormalizeDouble(new_volume,digit_lot)); }
//+——————————————————————++
//泽黻鲨 忸玮疣弪 蝾黜铖螯 腩蜞
// symbol – 桧耱痼戾眚 镱 觐蝾痤祗 疣聍栩噱蝰 珥圜屙桢 蝾黜铖蜩
//–// 暑?忸 珥嚓钼 镱耠?玎?蝾?桦?0
//int InfoGetLotDigit(string symbol){ return(MathCeil(MathAbs(MathLog( MarketInfo(Symbol(), MODE_MINLOT) )/MathLog(10)))); }
int InfoGetLotDigit(string symbol){return(MathLog(1/MarketInfo(Symbol(),MODE_LOTSTEP))/MathLog(10));}
//+——————————————————————+
// 泽黻鲨 聍栩噱?觐?忸 铕溴痤?
// _symbol – 桧耱痼戾眚 (“”, 膻犷?桧耱痼戾眚)
// _type – 蜩?铕溴痤?(-1, 膻犷?蜩?镱玷鲨?
// 灭箫镱忸?恹犷?
// 99 – 埋?铕溴疣
// 10 – Buy ?Sell
// 50 – 悟腩驽眄 (BuyStop, BuyLimit, SellStop, SellLimit)
// 51 – BuyStop ?BuyLimit
// 52 – SellStop ?SellLimit
// 53 – BuyStop ?SellStop
// 54 – BuyLimit ?SellLimit
// _magic – 箜桕嚯 眍戾?铕溴痤?耦忮蝽桕?(-1, 镱 膻犷祗 箜桕嚯铎?眍戾痼)
// _comm – 耱痤赅 觐蝾疣 漕腈磬 耦溴疰囹 ?觐祆屙蜞痂?(“”, ?膻猁?觐祆屙蜞痂屐)
// minOpenTime – 怵屐 铗牮? 铕溴疣 漕腈眍 猁螯 犷朦 桦?疣忭?玎溧眄铎?(0 – 礤 桉镱朦珞弪?)
// maxOpenTime – 怵屐 铗牮? 铕溴疣 漕腈眍 猁螯 戾睃 桦?疣忭?玎溧眄铎?(0 – 礤 桉镱朦珞弪?)
//-// 骂玮疣弪 觐?忸 铗牮 铕溴痤?桦?0
int OrdersGetCount(string _symbol, int _type, int _magic, string _comm, datetime minOpenTime, datetime maxOpenTime){ int iCount=0; if(OrdersTotal()<=0) return(0); for(int a1=OrdersTotal()-1;a1>=0;a1–){ if(OrderSelect(a1,SELECT_BY_POS)){ if((_symbol==”” || _symbol==OrderSymbol()) && (_magic==-1 || _magic==OrderMagicNumber()) && (_comm==”” || StringFind(OrderComment(),_comm)!=-1) && (minOpenTime==0 || OrderOpenTime()>=minOpenTime) && (maxOpenTime==0 || OrderOpenTime()<=maxOpenTime)){ if(_type==99){ iCount++; }else{ switch(OrderType()){ case OP_BUY: if(_type==OP_BUY || _type==10) iCount++; break; case OP_BUYSTOP: if(_type==OP_BUYSTOP || _type==50 || _type==51 || _type==53) iCount++; break; case OP_BUYLIMIT: if(_type==OP_BUYLIMIT || _type==50 || _type==51 || _type==54) iCount++; break; case OP_SELL: if(_type==OP_SELL || _type==10) iCount++; break; case OP_SELLSTOP: if(_type==OP_SELLSTOP || _type==50 || _type==52 || _type==53) iCount++; break; case OP_SELLLIMIT: if(_type==OP_SELLLIMIT || _type==50 || _type==52 || _type==54) iCount++; break; } } } } } return(iCount); }
//+——————————————————————+
// 杂褪秩?友依屠滤嚷琅?涡呐欣
// 1 – Buy, 2 – Sell, 3 – BuyStop, 4 – SellStop, 5 – BuyLimit, 6 – SellLimit
void OrdersOpen(int type_order,double Lot, double price, string SymbolSend, string Comm, double SL, double TP, int dlot, int slip, int mag, int& tick, color clr=CLR_NONE)
{int l_error_130=0; double takeprofit, stoplosse;
switch(type_order){
case 1 :
while(true){
if(IsTradeAllowed())
{RefreshRates();
tick = OrderSend(SymbolSend,OP_BUY,NormalizeDouble(Lot,dlot),NormalizeDouble(MarketInfo(SymbolSend,MODE_ASK),MarketInfo(SymbolSend,MODE_DIGITS)),slip,0,0,Comm,mag,0,clrBlue);
if(tick==-1) { if(ErrorCheck(GetLastError(),l_error_130)) return; }else{ break; }
continue;
} }
if(tick!=-1 && (SL!=0 || TP!=0)){
while(true){
if(IsTradeAllowed()){
RefreshRates();
if(OrderSelect(tick,SELECT_BY_TICKET)){
if(SL==0) { stoplosse = 0; }else{ stoplosse = OrderOpenPrice()-SL; }
if(TP==0) { takeprofit = 0;}else{ takeprofit= OrderOpenPrice()+TP; }
if(OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(stoplosse,MarketInfo(SymbolSend,MODE_DIGITS)),NormalizeDouble(takeprofit,MarketInfo(SymbolSend,MODE_DIGITS)),0)) break;
if(ErrorCheck(GetLastError(),l_error_130)) break;
continue;
}else{ Print(“OrderSelectError “+DoubleToStr(GetLastError(),0)); }
} } }
break;
case 2 :
while(true){
if(IsTradeAllowed()){
RefreshRates();
tick = OrderSend(SymbolSend,OP_SELL,NormalizeDouble(Lot,dlot),NormalizeDouble(MarketInfo(SymbolSend,MODE_BID),MarketInfo(SymbolSend,MODE_DIGITS)),slip,0,0,Comm,mag,0,clrRed);
if(tick==-1) { if(ErrorCheck(GetLastError(),l_error_130)) return; }else{ break; }
continue;
} }
if(tick!=-1 && (SL!=0 || TP!=0)){
while(true){
if(IsTradeAllowed()){
RefreshRates();
if(OrderSelect(tick,SELECT_BY_TICKET)){
if(SL==0) { stoplosse = 0; }else{ stoplosse = OrderOpenPrice()+SL; }
if(TP==0) { takeprofit = 0;}else{ takeprofit= OrderOpenPrice()-TP; }
if(OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(stoplosse,MarketInfo(SymbolSend,MODE_DIGITS)),NormalizeDouble(takeprofit,MarketInfo(SymbolSend,MODE_DIGITS)),0)) break;
if(ErrorCheck(GetLastError(),l_error_130)) break;
continue;
}else{ Print(“OrderSelectError “+DoubleToStr(GetLastError(),0)); }
} } }
break;
case 3 :
while(true){
if(IsTradeAllowed()){
RefreshRates();
if(SL==0) { stoplosse = 0; }else{ stoplosse = price-SL;}
if(TP==0) { takeprofit = 0;}else{ takeprofit= price+TP;}
tick = OrderSend(SymbolSend,OP_BUYSTOP,NormalizeDouble(Lot,dlot),NormalizeDouble(price,MarketInfo(SymbolSend,MODE_DIGITS)),slip,NormalizeDouble(stoplosse,MarketInfo(SymbolSend,MODE_DIGITS)),NormalizeDouble(takeprofit,MarketInfo(SymbolSend,MODE_DIGITS)),Comm,mag,0,clr);
if(tick==-1){if(ErrorCheck(GetLastError(),l_error_130)) break;}else{ break; }
continue;
} }
break;
case 4 :
while(true){
if(IsTradeAllowed()){
RefreshRates();
if(SL==0) { stoplosse = 0; }else{ stoplosse = price+SL;}
if(TP==0) { takeprofit = 0;}else{ takeprofit= price-TP;}
tick = OrderSend(SymbolSend,OP_SELLSTOP,NormalizeDouble(Lot,dlot),NormalizeDouble(price,MarketInfo(SymbolSend,MODE_DIGITS)),slip,NormalizeDouble(stoplosse,MarketInfo(SymbolSend,MODE_DIGITS)),NormalizeDouble(takeprofit,MarketInfo(SymbolSend,MODE_DIGITS)),Comm,mag,0,clr);
if(tick==-1){if(ErrorCheck(GetLastError(),l_error_130)) break;}else{ break; }
continue;
} }
break;
case 5 :
while(true){
if(IsTradeAllowed()){
RefreshRates();
if(SL==0) { stoplosse = 0; }else{ stoplosse = price-SL;}
if(TP==0) { takeprofit = 0;}else{ takeprofit= price+TP;}
tick = OrderSend(SymbolSend,OP_BUYLIMIT,NormalizeDouble(Lot,dlot),NormalizeDouble(price,MarketInfo(SymbolSend,MODE_DIGITS)),slip,NormalizeDouble(stoplosse,MarketInfo(SymbolSend,MODE_DIGITS)),NormalizeDouble(takeprofit,MarketInfo(SymbolSend,MODE_DIGITS)),Comm,mag,0,clr);
if(tick==-1){if(ErrorCheck(GetLastError(),l_error_130)) break;}else{ break; }
continue;
} }
break;
case 6 :
while(true){
if(IsTradeAllowed()){
RefreshRates();
if(SL==0) { stoplosse = 0; }else{ stoplosse = price+SL;}
if(TP==0) { takeprofit = 0;}else{ takeprofit= price-TP;}
tick = OrderSend(SymbolSend,OP_SELLLIMIT,NormalizeDouble(Lot,dlot),NormalizeDouble(price,MarketInfo(SymbolSend,MODE_DIGITS)),slip,NormalizeDouble(stoplosse,MarketInfo(SymbolSend,MODE_DIGITS)),NormalizeDouble(takeprofit,MarketInfo(SymbolSend,MODE_DIGITS)),Comm,mag,0,clr);
if(tick==-1){if(ErrorCheck(GetLastError(),l_error_130)) break;}else{ break; }
continue;
} }
break;
} }
//+——————————————————————+
// 杂褪秩 抢市勐琅?涡呐欣
//33 – all, 0 – buy, 2 – sell, 11 – buystop and buylimit, 21 – sellstop and selllimit,
//31 – selllimit and buylimit, 41 – buystop and sellstop
//51 – buylimit and sellstop, 61 – selllimit and buystop
//_mag = -1 – 玎牮噱?镱 膻犷祗 爨汨牦
// 杂褪秩 抢市勐琅?涡呐欣
bool OrdersClose(int type, int _mag, bool _isMagic, string _sSymbol, string _scomm, color clr=CLR_NONE){
if(OrdersTotal()<1) return(true);
int ordertype, l_error_130;
for(int a1=OrdersTotal()-1;a1>=0;a1–){
if(OrderSelect(a1,SELECT_BY_POS) && ((_isMagic && OrderMagicNumber()==_mag) || (!_isMagic && OrderTicket()==_mag) || _mag==-1 )
&& ((_sSymbol!=”” && OrderSymbol()==_sSymbol) || _sSymbol==””) && (_scomm==”” || StringFind(OrderComment(),_scomm)!=-1) ){
ordertype = OrderType();
if((type==33 || type==0) && ordertype==OP_BUY) {
while(true) {
RefreshRates();
if(IsTradeAllowed()){
if(OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(MarketInfo(OrderSymbol(),MODE_BID),MarketInfo(OrderSymbol(),MODE_DIGITS)),0,clrDarkOrange)) break;
else if(ErrorCheck(GetLastError(),l_error_130)) break;
}
} }
if((type==33 || type==11 || type==41 || type==61) && ordertype==OP_BUYSTOP) {
while(true) {
RefreshRates();
if(IsTradeAllowed()){
if(OrderDelete(OrderTicket(),clr)) break;
else if(ErrorCheck(GetLastError(),l_error_130)) break;
}
} }
if((type==33 || type==11 || type==31 || type==51) && ordertype==OP_BUYLIMIT) {
while(true) {
RefreshRates();
if(IsTradeAllowed()){
if(OrderDelete( OrderTicket(),clr)) break;
else if(ErrorCheck(GetLastError(),l_error_130)) break;
}
} }
if((type==33 || type==2) && ordertype==OP_SELL) {
while(true) {
RefreshRates();
if(IsTradeAllowed()){
if(OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(MarketInfo(OrderSymbol(),MODE_ASK),MarketInfo(OrderSymbol(),MODE_DIGITS)),0,clrDarkOrange)) break;
else if(ErrorCheck(GetLastError(),l_error_130)) break;
}
} }
if((type==33 || type==21 || type==41 || type==51) && ordertype==OP_SELLSTOP) {
while(true) {
RefreshRates();
if(IsTradeAllowed()){
if(OrderDelete(OrderTicket(),clr)) break;
else if(ErrorCheck(GetLastError(),l_error_130)) break;
}
} }
if((type==33 || type==21 || type==31 || type==61) && ordertype==OP_SELLLIMIT) {
while(true) {
RefreshRates();
if(IsTradeAllowed()){
if(OrderDelete(OrderTicket(),clr)) break;
else if(ErrorCheck(GetLastError(),l_error_130)) break;
}
} } } }
//if (ordTotal == 0) { StartBPrice = -1; StartSPrice = -1;}
return(true);
}
//+——————————————————————+
//杂褪秩?闲温判吲?胰?呜攘嗜
bool ErrorCheck(int l_error_64, int& error_130){
if(l_error_64==0) return(true);
switch(l_error_64){
case 4: Print(“翌疸钼 皴疴屦 玎?? 其屐 500 祚…”); Sleep(500); return(false);
case 6: Print(“湾?疋玷 ?皴疴屦铎. 其屐 2 皴?..”); Sleep(2000);return(false);
case 8: Print(“央桫觐?鬣耱 玎镳铖? 其屐 1 皴?..”); Sleep(1000);return(false);
case 129:Print(“硒栳赅 ?鲥礤. 其屐 500 祚 ?钺眍忤?鲥睇…”);Sleep(500); return(false);
case 135:Print(“皱磬 桤戾龛豚顸. 橡钺箦?妁?疣?.”); return(false);
case 136:Print(“湾?鲥? 其胳 眍恹?蜩?.”); Sleep(1); return(false);
case 137:Print(“琉铌屦 玎?? 其屐 500 祚…”); Sleep(500); return(false);
case 138:Print(“皖恹?鲥睇. 吾眍忤?”); return(false);
case 141:Print(“央桫觐?祉钽?铒屦圉栝. 其屐 1 扈眢蝮..”); Sleep(60000);return(false);
case 146:Print(“项漶桉蝈爨 蝾疸钼腓 玎?蜞. 橡钺箦?妁?.”); Sleep(500); return(false);
case 130: if(error_130==0) {Print(“硒栳赅 鲥睇. 项稃蜿?钺眍忤螯 鲥睇…”);Sleep(1000);error_130++;return(false); }else{ Print(“署栩梓羼赅 铠栳赅 ?鲥礤.”); return(true);}
default: Print(“署栩梓羼赅 铠栳赅 ?”+DoubleToStr(l_error_64,0)); return(true);
}
return(true);
}
//+——————————————————————+
// 物疱溴?弪 怩钿栩 腓 玎溧眄 蜩?铕溴疣 玎溧眄簋 沭箫矬 蜩镱?铕溴痤?
// _type_order – 蜩?铕溴疣 (Buy, Sell, BuyStop, SellStop, BuyLimit, SellLimit)
// _type_group – 蜩?沭箫稃:
// 99 – 埋?铕溴疣
// 10 – Buy ?Sell
// 50 – 悟腩驽眄 (BuyStop, BuyLimit, SellStop, SellLimit)
// 51 – BuyStop ?BuyLimit
// 52 – SellStop ?SellLimit
// 53 – BuyStop ?SellStop
// 54 – BuyLimit ?SellLimit
bool InfoisTypeOrdPartOfGroup(int _type_order, int _type_group){ if(_type_order < 0) return(false); bool _res = false; switch(_type_order){ case OP_BUY: switch(_type_group){ case 99: case 10: case OP_BUY: _res = true; } break; case OP_SELL: switch(_type_group){ case 99: case 10: case OP_SELL: _res = true; } break; case OP_BUYSTOP: switch(_type_group){ case 99: case 50: case 51: case 53: case OP_BUYSTOP: _res = true; } break; case OP_SELLSTOP: switch(_type_group){ case 99: case 50: case 52: case 53: case OP_SELLSTOP: _res = true; } break; case OP_BUYLIMIT: switch(_type_group){ case 99: case 50: case 51: case 54: case OP_BUYLIMIT: _res = true; } break; case OP_SELLLIMIT: switch(_type_group){ case 99: case 50: case 52: case 54: case OP_SELLLIMIT: _res = true; } break; } return(_res); }
//+——————————————————————+
//=========================================================================================================================================//
// Kordan . 泽黻鲨 箐嚯屙? 钺牝钼 //
//=========================================================================================================================================//

int DeleteObject() {

int ObjTotal = ObjectsTotal() ;
string ObName ;
for(int i = 0; i < ObjTotal; i++){
ObName = ObjectName(i) ;
if(StringSubstr(ObName,0,1) == “I”
|| StringSubstr(ObName,0,1) == “i”) {
ObjectDelete(ObName) ;
Comment(“”) ;
i = i – 1 ;
}
}

return(0);
}

//=========================================================================================================================================//
// 耔沩嚯 镱 桧滂赅蝾痼 MTS //
int mper[10]={0,1,5,15,30,60,240,1440,10080,43200};
//=========================================================================================================================================//
int M(){
int MTSSignal=0;
int MTSstart=0;
double MTS_Green1=iCustom(Symbol(),mper[TF_M],”medium”,Sensitivity_M,1,0);
double MTS_Red1=iCustom(Symbol(),mper[TF_M],”medium”,Sensitivity_M,2,0);
double MTS_Green2=iCustom(Symbol(),mper[TF_M],”medium”,Sensitivity_M,1,1);
double MTS_Red2=iCustom(Symbol(),mper[TF_M],”medium”,Sensitivity_M,2,1);
if((MTS_Green1!=EMPTY_VALUE)&&(MTS_Green2!=EMPTY_VALUE)) MTSstart=1;
if((MTS_Red1!=EMPTY_VALUE)&&(MTS_Red2!=EMPTY_VALUE)) MTSstart=-1;
if(MTSstart<0) MTSSignal= -1; //耔沩嚯 Sell
if(MTSstart>0) MTSSignal = 1; // 耔沩嚯 Buy
return(MTSSignal);
}

int M2(){
int MTSSignal2=0;
int MTSstart2=0;
double MTS_Green1=iCustom(Symbol(),mper[TF_M2],”medium”,Sensitivity_M2,1,0);
double MTS_Red1=iCustom(Symbol(),mper[TF_M2],”medium”,Sensitivity_M2,2,0);
double MTS_Green2=iCustom(Symbol(),mper[TF_M2],”medium”,Sensitivity_M2,1,1);
double MTS_Red2=iCustom(Symbol(),mper[TF_M2],”medium”,Sensitivity_M2,2,1);
if((MTS_Green1!=EMPTY_VALUE)&&(MTS_Green2!=EMPTY_VALUE)) MTSstart2=1;
if((MTS_Red1!=EMPTY_VALUE)&&(MTS_Red2!=EMPTY_VALUE)) MTSstart2=-1;
if(MTSstart2<0) MTSSignal2= -1; //耔沩嚯 Sell
if(MTSstart2>0) MTSSignal2 = 1; // 耔沩嚯 Buy
return(MTSSignal2);
}
//++—————————————————————————————————————
int P(){
int MTSSignal=0;
int MTSstart=0;
double MTS_Green1=iCustom(Symbol(),mper[TF_P],”medium”,Sensitivity_P,1,0);
double MTS_Red1=iCustom(Symbol(),mper[TF_P],”medium”,Sensitivity_P,2,0);
double MTS_Green2=iCustom(Symbol(),mper[TF_P],”medium”,Sensitivity_P,1,1);
double MTS_Red2=iCustom(Symbol(),mper[TF_P],”medium”,Sensitivity_P,2,1);
if((MTS_Green1!=EMPTY_VALUE)&&(MTS_Green2!=EMPTY_VALUE)) MTSstart=1;
if((MTS_Red1!=EMPTY_VALUE)&&(MTS_Red2!=EMPTY_VALUE)) MTSstart=-1;
if(MTSstart<0) MTSSignal= -1; //耔沩嚯 Sell
if(MTSstart>0) MTSSignal = 1; // 耔沩嚯 Buy
return(MTSSignal);
}

int P2(){
int MTSSignal2=0;
int MTSstart2=0;
double MTS_Green1=iCustom(Symbol(),mper[TF_P2],”medium”,Sensitivity_P2,1,0);
double MTS_Red1=iCustom(Symbol(),mper[TF_P2],”medium”,Sensitivity_P2,2,0);
double MTS_Green2=iCustom(Symbol(),mper[TF_P2],”medium”,Sensitivity_P2,1,1);
double MTS_Red2=iCustom(Symbol(),mper[TF_P2],”medium”,Sensitivity_P2,2,1);
if((MTS_Green1!=EMPTY_VALUE)&&(MTS_Green2!=EMPTY_VALUE)) MTSstart2=1;
if((MTS_Red1!=EMPTY_VALUE)&&(MTS_Red2!=EMPTY_VALUE)) MTSstart2=-1;
if(MTSstart2<0) MTSSignal2= -1; //耔沩嚯 Sell
if(MTSstart2>0) MTSSignal2 = 1; // 耔沩嚯 Buy
return(MTSSignal2);
}
//+——————————————————————+
// 泽黻鲨 祛滂翳赅鲨?铕溴痤?
//+——————————————————————+
void PModifyOrders(int otype)//蜩?铕溴疣
{
if (dPiramidTP == 0 && dPiramidStopLoss == 0) {/*Print(“义殛 镳铘栩 ?耱铒 腩耨 镨疣扈潲 礤 玎溧睇!”); */return;}

double avgprice = 0,// 耩邃? 鲥磬 = 0
order_lots = 0; // 耩邃龛?钺?镱赅 =0
bool omodif = false;
double price,Tp,Sl;
// 痒栩噱?钺禧
price = 0;
for ( int i = OrdersTotal()-1; i>=0; i–)//襄疱徼疣屐 怦?铕溴疣 ?鲨觌?
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))// 蔓徼疣屐 铕溴疣
{ // 镳钼屦屐 磬 磬腓麒?蝈犍邈?铕溴疣 磬 磬?耔焘铍??耦铗忮蝰蜮桢 爨汨赅,?蜞?驽 邈?磬镳噔脲龛?蜩镟
if (OrderSymbol()== Symbol() && OrderMagicNumber() == Magic_piramid && OrderType() == otype)
{
price += OrderOpenPrice() * OrderLots();// 痒栩噱?耋祆囵眢?鲥眢 ?篦弪铎 钺祛?
order_lots += OrderLots();// 痒栩噱?耋爨痦 钺?
}
}
}
// 痒栩噱?耩邃睨?鲥眢
if (order_lots > 0) avgprice = NormalizeDouble (price / order_lots, Digits);
// 镳钼屦屐 赅觐?镳桫咫 玎镳铖 ?疣聍栩噱?蝈殛 镳铘栩
if (dPiramidTP > 0) {
if (otype == OP_BUY)Tp = NormalizeDouble(avgprice + dPiramidTP,Digits);
if (otype == OP_SELL)Tp = NormalizeDouble(avgprice – dPiramidTP,Digits);
} else {
Tp=0;
//Print(“义殛 镳铘栩 镨疣扈潲 礤 玎溧?桦?玎溧?礤忮痦? 湾忸珈铈眍 篑蜞眍忤螯 钺?蝈殛 镳铘栩!”);
}
if (dPiramidStopLoss > 0) {
if (otype == OP_BUY)Sl = NormalizeDouble(avgprice – dPiramidStopLoss,Digits);
if (otype == OP_SELL)Sl = NormalizeDouble(avgprice + dPiramidStopLoss,Digits);
} else {
Sl=0;
//Print(“羊铒 腩耨 镨疣扈潲 礤 玎溧?桦?玎溧?礤忮痦? 湾忸珈铈眍 篑蜞眍忤螯 钺?耱铒 腩耨!”);
}
// 填滂翳鲨痼屐 怦?铕溴疣
for ( i = OrdersTotal()-1; i>=0; i–)//襄疱徼疣屐 怦?铕溴疣 ?鲨觌?
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))// 蔓徼疣屐 铕溴?
{ // 镳钼屦屐 磬 磬腓麒?蝈犍邈?铕溴疣 磬 磬?耔焘铍??耦铗忮蝰蜮桢 爨汨赅,?蜞?驽 邈?磬镳噔脲龛?蜩镟
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic_piramid && OrderType() == otype)

if (Tp != OrderTakeProfit() || Sl != OrderStopLoss())

{
omodif=OrderModify(OrderTicket(),OrderOpenPrice(),Sl,Tp,0);// 橡铊玮钿桁 祛滂翳赅鲨?
}
}
}
}
//+——————————————————————+
void MModifyOrders(int otype)//蜩?铕溴疣
{
if (dMartinTP == 0 && dMartinStopLoss == 0) {/*Print(“义殛 镳铘栩 ?耱铒 腩耨 镨疣扈潲 礤 玎溧睇!”); */return;}

double avgprice = 0,// 耩邃? 鲥磬 = 0
order_lots = 0; // 耩邃龛?钺?镱赅 =0
bool omodif = false;
double price,Tp,Sl;
// 痒栩噱?钺禧
price = 0;
for ( int i = OrdersTotal()-1; i>=0; i–)//襄疱徼疣屐 怦?铕溴疣 ?鲨觌?
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))// 蔓徼疣屐 铕溴疣
{ // 镳钼屦屐 磬 磬腓麒?蝈犍邈?铕溴疣 磬 磬?耔焘铍??耦铗忮蝰蜮桢 爨汨赅,?蜞?驽 邈?磬镳噔脲龛?蜩镟
if (OrderSymbol()== Symbol() && OrderMagicNumber() == Magic_martin && OrderType() == otype)
{
price += OrderOpenPrice() * OrderLots();// 痒栩噱?耋祆囵眢?鲥眢 ?篦弪铎 钺祛?
order_lots += OrderLots();// 痒栩噱?耋爨痦 钺?
}
}
}
// 痒栩噱?耩邃睨?鲥眢
if (order_lots > 0) avgprice = NormalizeDouble (price / order_lots, Digits);
// 镳钼屦屐 赅觐?镳桫咫 玎镳铖 ?疣聍栩噱?蝈殛 镳铘栩
if (dMartinTP > 0) {
if (otype == OP_BUY)Tp = NormalizeDouble(avgprice + dMartinTP,Digits);
if (otype == OP_SELL)Tp = NormalizeDouble(avgprice – dMartinTP,Digits);
} else {
Tp=0;
//Print(“义殛 镳铘栩 镨疣扈潲 礤 玎溧?桦?玎溧?礤忮痦? 湾忸珈铈眍 篑蜞眍忤螯 钺?蝈殛 镳铘栩!”);
}
if (dMartinStopLoss > 0) {
if (otype == OP_BUY)Sl = NormalizeDouble(avgprice – dMartinStopLoss,Digits);
if (otype == OP_SELL)Sl = NormalizeDouble(avgprice + dMartinStopLoss,Digits);
} else {
Sl=0;
//Print(“羊铒 腩耨 镨疣扈潲 礤 玎溧?桦?玎溧?礤忮痦? 湾忸珈铈眍 篑蜞眍忤螯 钺?耱铒 腩耨!”);
}
// 填滂翳鲨痼屐 怦?铕溴疣
for ( i = OrdersTotal()-1; i>=0; i–)//襄疱徼疣屐 怦?铕溴疣 ?鲨觌?
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))// 蔓徼疣屐 铕溴?
{ // 镳钼屦屐 磬 磬腓麒?蝈犍邈?铕溴疣 磬 磬?耔焘铍??耦铗忮蝰蜮桢 爨汨赅,?蜞?驽 邈?磬镳噔脲龛?蜩镟
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic_martin && OrderType() == otype)

if (Tp != OrderTakeProfit() || Sl != OrderStopLoss())

{
omodif=OrderModify(OrderTicket(),OrderOpenPrice(),Sl,Tp,0);// 橡铊玮钿桁 祛滂翳赅鲨?
}
}
}
}
//++—————————————————————————————————————–++
bool isCloseLastPos() {
datetime t;
double ocp, osl, otp;
int i, j=-1, k=OrdersHistoryTotal();
for (i=0; i<k; i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
if (OrderMagicNumber()==Magic_martin || OrderMagicNumber()==Magic_piramid) {
if (t<OrderCloseTime()) {
t=OrderCloseTime();
j=i;
}
}
}
}
}
if (OrderSelect(j, SELECT_BY_POS, MODE_HISTORY)) {
ocp=NormalizeDouble(OrderClosePrice(), Digits);
osl=NormalizeDouble(OrderStopLoss(), Digits);
otp=NormalizeDouble(OrderTakeProfit(), Digits);
if (ocp==osl || ocp==otp) return(True);
}
return(False);
}

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

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

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

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

相关资源

暂无评论

暂无评论...