//+——————————————————————+
//| FM-CONECT.mq4 |
//| |
//| |
//+——————————————————————+
#property copyright “”
#property link “”
//———————–相疣戾蝠?———————————–+
extern string c0=”————————“;
extern double Risk =5; //需耜, 腩??镳铞屙蜞?
extern double MaxRisk =10; //锑犟桁嚯 痂耜 (羼腓 玎溴轳蜮钼囗?耧铐屙蜞)
extern int TakeProfit =20; //羽钼屙?蝈殛 镳铘栩??矬黻蜞?
extern double ProfitProcent =20; //羽钼屙?蝈殛 镳铘栩??镳铞屙蜞?
extern double StopMinus =20; //锑犟桁嚯 疣珈屦 筢赅 ?镳铞屙蜞?
extern string c1=”————————“;
extern int FrameBar =1440; //袜 赅觐?麴彘戾 翳朦蝠箦?怩钿?
extern int TimeStart =0; //吗屐 磬鬣豚 疣犷螓
extern int TimeEnd =23; //吗屐 铌铐鬣龛 疣犷螓
extern string c2=”————————“;
extern double UpLot =1; //羊屣屙?筲咫梓屙? 腩蜞 (耧铐屙蜞)
extern int Step =5; //剜?皴蜿?
extern int MaxOrders =10; //锑犟桁嚯铄 觐腓麇耱忸 铕溴痤??皴蜿?
extern int xOrders =20; //锑犟桁嚯铄 觐腓麇耱忸 铕溴痤??皴蜿??镫
extern string c4=”————————“;
extern int Magic =7777; //锑痍屦 铕溴痤?
//——————————————————————–+
string CommentEA =”FM-CONECT”;
int D;
double OpPric =0;
string Name;
bool Buy,Sell;
double NewTP;
int Ticket;
int init()
{D=1;
if (Digits==5 || Digits==3)D=10;
Name=WindowExpertName();
return(0);}
//——————————————————————–+
int start(){
//——————————————————————–+//——————————————————————–+
double Lot=0;
Lot=NormalizeDouble(AccountBalance()/100*Risk/(MarketInfo(Symbol(),MODE_TICKVALUE)*100*D),2);
if (Lot<MarketInfo(Symbol(),MODE_MINLOT))Lot=MarketInfo(Symbol(),MODE_MINLOT);double MaxLot=0;
MaxLot=NormalizeDouble(AccountBalance()/100*MaxRisk/(MarketInfo(Symbol(),MODE_TICKVALUE)*100*D),2);
if (MaxLot<MarketInfo(Symbol(),MODE_MINLOT))MaxLot=MarketInfo(Symbol(),MODE_MINLOT);if(MarketInfo(Symbol(),MODE_LOTSTEP)==0.01) int dig =2;
if(MarketInfo(Symbol(),MODE_LOTSTEP)==0.10) dig =1;
if(MarketInfo(Symbol(),MODE_LOTSTEP)==1.00) dig =0;
//——————————————————————–+
int OB,OS;
double PipBuy,PipSell,PipBp,PipSp;
for (int i=0; i<OrdersTotal(); i++)
{bool sel0=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if (OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{if (OrderType()==0){OB++;PipBuy=Bid-OrderOpenPrice(); PipBp=OrderOpenPrice()-Ask;}
if (OrderType()==1){OS++;PipSell=OrderOpenPrice()-Ask; PipSp=Bid-OrderOpenPrice();}}}int OBH,OSH;
for (i=0; i<OrdersHistoryTotal(); i++)
{bool sel01=OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
if (OrderSymbol()==Symbol() && OrderMagicNumber()==Magic && OrderOpenTime()>=iTime(Symbol(),FrameBar,0))
{if (OrderType()==0){OBH++;}
if (OrderType()==1){OSH++;}}}
//——————————————————————–+
Buy=false;Sell=false;
if (Open[1]<Close[1] && Open[2]<Close[2] && Open[3]>Close[3] && Open[4]>Close[4] && Open[5]>Close[5])Buy=true;
if (Open[1]>Close[1] && Open[2]>Close[2] && Open[3]<Close[3] && Open[4]<Close[4] && Open[5]<Close[5])Sell=true;
//——————————————————————–+
double NLot=Lot*(MathPow(UpLot,OB+OS));
if(NLot>=MaxLot){double NewLot=MaxLot;}
if(NLot<MaxLot){NewLot=NLot;}
//——————————————————————–+
double lots=0;
double sum=0;
for (i=0; i<OrdersTotal(); i++)
{if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break;
if (OrderSymbol()!=Symbol()) continue;
if (OrderType()==OP_BUY)
{lots=lots+OrderLots();
sum=sum+OrderLots()*OrderOpenPrice();}
if (OrderType()==OP_SELL)
{lots=lots-OrderLots();
sum=sum-OrderLots()*OrderOpenPrice();}}double price=0;
if (lots!=0) price=sum/lots;
if (price>0) OpPric=NormalizeDouble(price,Digits);
//——————————————————————–+
if(TimeHour(TimeCurrent())>=TimeStart && TimeHour(TimeCurrent())<TimeEnd)
{
if(OB+OS==0 && OBH+OSH==0 && Buy)
{Ticket=OpenOrder(Symbol(),OP_BUY,Lot,NormalizeDouble(Ask,Digits),0,0,CommentEA,Magic);}if(OB+OS==0 && OBH+OSH==0 && Sell)
{Ticket=OpenOrder(Symbol(),OP_SELL,Lot,NormalizeDouble(Bid,Digits),0,0,CommentEA,Magic);}
}
//——————————————————————–+
if (OB>0 && OB<MaxOrders && PipBuy/D/Point<=-Step && CountP(-1)==0)
{OpenOrder(Symbol(),OP_BUY,NewLot,NormalizeDouble(Ask,Digits),0,0,CommentEA,Magic);}
//——————————————————————–+
if (OS>0 && OS<MaxOrders && PipSell/D/Point<=-Step && CountP(-1)==0)
{OpenOrder(Symbol(),OP_SELL,NewLot,NormalizeDouble(Bid,Digits),0,0,CommentEA,Magic);}
//——————————————————————–+
if (OB>0 && OB<xOrders && PipBp/D/Point<=-Step && CountM(-1)==0)
{OpenOrder(Symbol(),OP_BUY,Lot,NormalizeDouble(Ask,Digits),0,0,CommentEA,Magic);}
//——————————————————————–+
if (OS>0 && OS<xOrders && PipSp/D/Point<=-Step && CountM(-1)==0)
{OpenOrder(Symbol(),OP_SELL,Lot,NormalizeDouble(Bid,Digits),0,0,CommentEA,Magic);}
//——————————————————————–+
//——————————————————————–+
double ProfProc=(AccountBalance()/100)*ProfitProcent;
if(Profit(-1)>=ProfProc && ProfProc!=0)
{Closer();}if(OB>0 && Bid>OpPric+TakeProfit*D*Point)
{Closer();}if(OS>0 && Ask<OpPric-TakeProfit*D*Point)
{Closer();}double S_Max=(AccountBalance()/100)*StopMinus*(-1);
if(Profit(-1)<S_Max && S_Max!=0)
{Closer();}return(0);}
//——————————————————————–+
int CountP(int type)
{int count=0;
for(int i=OrdersTotal()-1;i>=0;i–)
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{if(Symbol()==OrderSymbol() && OrderMagicNumber()==Magic && OrderProfit()>0 && (type==-1 || OrderType()==type)) count++;}
return(count);}int CountM(int type)
{int count=0;
for(int i=OrdersTotal()-1;i>=0;i–)
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{if(Symbol()==OrderSymbol() && OrderMagicNumber()==Magic && OrderProfit()<0 && (type==-1 || OrderType()==type)) count++;}
return(count);}
//——————————————————————–+
int OpenOrder(string symbol,int cmd,double volume,double price,double stoploss,double takeprofit,string comment,int magic)
{
int err,i,ticket;
while(i<10)
{
RefreshRates();
if (cmd==0)price=Ask;
if (cmd==1)price=Bid;
ticket=OrderSend(symbol,cmd,volume,NormalizeDouble(price,Digits),1000*D,NormalizeDouble(stoploss,Digits),NormalizeDouble(takeprofit,Digits),comment,magic);
err = GetLastError();
if (err == 0) break;
Print(Name,Symbol(),Error(err),” 镳?铗牮梃 铕溴疣”);
Sleep(1000);
i++;
}
return(ticket);
}
//——————————————————————–+
int ModifyOrder(int ticket,double price,double stoploss,double takeprofit)
{
int err,i;while(i<10)
{
RefreshRates();
bool sel7=OrderModify(ticket,NormalizeDouble(price,Digits),NormalizeDouble(stoploss,Digits),NormalizeDouble(takeprofit,Digits),0,CLR_NONE);
err = GetLastError();
if (err == 0) break;
Print(Name,Symbol(),Error(err),” 镳?祛滂翳赅鲨?铕溴疣”);
Sleep(1000);
i++;
}
return(0);
}
//——————————————————————–+
string Error(int error_code)
{
string error_string;
switch(error_code)
{
case 0: error_string=”湾?铠栳铌”; break;
case 1: error_string=”湾?铠栳觇, 眍 疱珞朦蜞?礤桤忮耱屙”; break;
case 2: error_string=”吾 铠栳赅”; break;
case 3: error_string=”湾镳噔桦 镟疣戾蝠?; break;
case 4: error_string=”翌疸钼 皴疴屦 玎??; break;
case 5: error_string=”羊囵? 忮瘃? 觌桢眚耜钽?蝈痨桧嚯?; break;
case 6: error_string=”湾?疋玷 ?蝾疸钼 皴疴屦铎”; break;
case 7: error_string=”湾漕耱囹铟眍 镳噔”; break;
case 8: error_string=”央桫觐?鬣耱 玎镳铖?; break;
case 9: error_string=”湾漕矬耱桁? 铒屦圉? 磬痼? 趔黻鲨铐桊钼囗桢 皴疴屦?; break;
case 64: error_string=”痒弪 玎犭铌桊钼囗”; break;
case 65: error_string=”湾镳噔桦 眍戾?聍弪?; break;
case 128: error_string=”锐蝈?耩铌 铈桎囗? 耦忮瘌屙? 皲咫觇”; break;
case 129: error_string=”湾镳噔桦? 鲥磬”; break;
case 130: error_string=”湾镳噔桦 耱铒?; break;
case 131: error_string=”湾镳噔桦 钺?; break;
case 132: error_string=”宣眍?玎牮”; break;
case 133: error_string=”翌疸钼? 玎镳妁屙?; break;
case 134: error_string=”湾漕耱囹铟眍 溴礤?潆 耦忮瘌屙? 铒屦圉梃”; break;
case 135: error_string=”皱磬 桤戾龛豚顸”; break;
case 136: error_string=”湾?鲥?; break;
case 137: error_string=”琉铌屦 玎??; break;
case 138: error_string=”皖恹?鲥睇”; break;
case 139: error_string=”勿溴?玎犭铌桊钼囗 ?箧?钺疣徉螓忄弪?”; break;
case 140: error_string=”朽琊屮屙?蝾朦觐 镱牦镪?; break;
case 141: error_string=”央桫觐?祉钽?玎镳铖钼”; break;
case 145: error_string=”填滂翳赅鲨 玎镳妁屙? 蜞?赅?铕溴?耠桫觐?犭桤铌 ?瘥黻?; break;
case 146: error_string=”项漶桉蝈爨 蝾疸钼腓 玎?蜞”; break;
case 147: error_string=”锐镱朦珙忄龛?溧螓 桉蝈麇龛 铕溴疣 玎镳妁屙?狃铌屦铎”; break;
case 148: error_string=”暑腓麇耱忸 铗牮 ?铗腩驽眄 铕溴痤?漕耱桡腩 镳邃咫? 篑蜞眍怆屙眍泐 狃铌屦铎.”;break;
case 4000: error_string=”湾?铠栳觇”; break;
case 4001: error_string=”湾镳噔桦 箨噻囹咫?趔黻鲨?; break;
case 4002: error_string=”软溴犟 爨耨桠?- 忭?滂囡噻铐?; break;
case 4003: error_string=”湾?镟?蜩 潆 耱尻?趔黻鲨?; break;
case 4004: error_string=”襄疱镱腠屙桢 耱尻?镱耠?疱牦瘃桠眍泐 恹珙忄”; break;
case 4005: error_string=”袜 耱尻?礤?镟?蜩 潆 镥疱溧麒 镟疣戾蝠钼”; break;
case 4006: error_string=”湾?镟?蜩 潆 耱痤觐忸泐 镟疣戾蝠?; break;
case 4007: error_string=”湾?镟?蜩 潆 怵屐屙眍?耱痤觇”; break;
case 4008: error_string=”湾桧桷栲腓玷痤忄眄? 耱痤赅”; break;
case 4009: error_string=”湾桧桷栲腓玷痤忄眄? 耱痤赅 ?爨耨桠?; break;
case 4010: error_string=”湾?镟?蜩 潆 耱痤觐忸泐 爨耨桠?; break;
case 4011: error_string=”央桫觐?潆桧磬 耱痤赅”; break;
case 4012: error_string=”务蜞蝾?铗 溴脲龛 磬 眍朦”; break;
case 4013: error_string=”腻脲龛?磬 眍朦”; break;
case 4014: error_string=”湾桤忮耱磬 觐爨礓?; break;
case 4015: error_string=”湾镳噔桦 镥疱躅?; break;
case 4016: error_string=”湾桧桷栲腓玷痤忄眄 爨耨桠”; break;
case 4017: error_string=”蔓珙恹 DLL 礤 疣琊屮屙?; break;
case 4018: error_string=”湾忸珈铈眍 玎沭箸栩?徼犭桀蝈牦”; break;
case 4019: error_string=”湾忸珈铈眍 恹玮囹?趔黻鲨?; break;
case 4020: error_string=”蔓珙恹 忭屮龛?徼犭桀蝈黜 趔黻鲨?礤 疣琊屮屙?; break;
case 4021: error_string=”湾漕耱囹铟眍 镟?蜩 潆 耱痤觇, 忸玮疣屐铋 桤 趔黻鲨?; break;
case 4022: error_string=”谚耱屐?玎?蜞”; break;
case 4050: error_string=”湾镳噔桦铄 觐腓麇耱忸 镟疣戾蝠钼 趔黻鲨?; break;
case 4051: error_string=”湾漕矬耱桁铄 珥圜屙桢 镟疣戾蝠?趔黻鲨?; break;
case 4052: error_string=”马篁疱眄 铠栳赅 耱痤觐忸?趔黻鲨?; break;
case 4053: error_string=”硒栳赅 爨耨桠?; break;
case 4054: error_string=”湾镳噔桦铄 桉镱朦珙忄龛?爨耨桠?蜞殪皴痂?; break;
case 4055: error_string=”硒栳赅 镱朦珙忄蝈朦耜钽?桧滂赅蝾疣”; break;
case 4056: error_string=”锑耨桠?礤耦忪羼蜩禧”; break;
case 4057: error_string=”硒栳赅 钺疣犷蜿?汶钺嚯?镥疱戾眄”; break;
case 4058: error_string=”秒钺嚯? 镥疱戾眄? 礤 钺磬痼驽磬”; break;
case 4059: error_string=”泽黻鲨 礤 疣琊屮屙??蝈耱钼铎 疱骅戾”; break;
case 4060: error_string=”泽黻鲨 礤 疣琊屮屙?; break;
case 4061: error_string=”硒栳赅 铗镳噔觇 镱黩?; break;
case 4062: error_string=”捂桎噱蝰 镟疣戾蝠 蜩镟 string”; break;
case 4063: error_string=”捂桎噱蝰 镟疣戾蝠 蜩镟 integer”; break;
case 4064: error_string=”捂桎噱蝰 镟疣戾蝠 蜩镟 double”; break;
case 4065: error_string=”?赅麇耱忮 镟疣戾蝠?铈桎噱蝰 爨耨桠”; break;
case 4066: error_string=”青镳铠屙睇?桉蝾痂麇耜桢 溧眄 ?耦耱?龛?钺眍怆屙?”; break;
case 4067: error_string=”硒栳赅 镳?恹镱腠屙梃 蝾疸钼铋 铒屦圉梃”; break;
case 4099: error_string=”暑礤?羿殡?; break;
case 4100: error_string=”硒栳赅 镳?疣犷蝈 ?羿殡铎”; break;
case 4101: error_string=”湾镳噔桦铄 桁 羿殡?; break;
case 4102: error_string=”央桫觐?祉钽?铗牮 羿殡钼”; break;
case 4103: error_string=”湾忸珈铈眍 铗牮?羿殡”; break;
case 4104: error_string=”湾耦忪羼蜩禧?疱骅?漕耱箫??羿殡?; break;
case 4105: error_string=”丸 钿桧 铕溴?礤 恹狃囗”; break;
case 4106: error_string=”湾桤忮耱睇?耔焘铍”; break;
case 4107: error_string=”湾镳噔桦 镟疣戾蝠 鲥睇 潆 蝾疸钼铋 趔黻鲨?; break;
case 4108: error_string=”湾忮痦 眍戾?蜩赍蜞”; break;
case 4109: error_string=”翌疸钼? 礤 疣琊屮屙? 湾钺躅滂祛 怅膻麒螯 铒鲨?朽琊屮栩?耦忮蝽桕?蝾疸钼囹??疋铋耱忄?耧屦蜞.”; break;
case 4110: error_string=”碾桧睇?镱玷鲨?礤 疣琊屮屙? 湾钺躅滂祛 镳钼屦栩?疋铋耱忄 耧屦蜞.”; break;
case 4111: error_string=”暑痤蜿桢 镱玷鲨?礤 疣琊屮屙? 湾钺躅滂祛 镳钼屦栩?疋铋耱忄 耧屦蜞.”; break;
case 4200: error_string=”吾牝 箧?耋耱怏弪”; break;
case 4201: error_string=”青镳铠屙?礤桤忮耱眍?疋铋耱忸 钺牝?; break;
case 4202: error_string=”吾牝 礤 耋耱怏弪”; break;
case 4203: error_string=”湾桤忮耱睇?蜩?钺牝?; break;
case 4204: error_string=”湾?桁屙?钺牝?; break;
case 4205: error_string=”硒栳赅 觐铕滂磬?钺牝?; break;
case 4206: error_string=”湾 磬殇屙?箨噻囗眍?镱漕觏?; break;
default: error_string=”硒栳赅 镳?疣犷蝈 ?钺牝铎”;
}
return(error_string);
}
//——————————————————————–+
double Profit(int type)
{double Profit = 0;
for (int cnt = OrdersTotal() – 1; cnt >= 0; cnt–) {
if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
{if (Symbol()==OrderSymbol() && OrderMagicNumber()==Magic && (OrderType() == type || type==-1)) Profit += OrderProfit()+OrderSwap()+OrderCommission();}}
return (Profit);}
//——————–青牮桢—————————————–+
void Closer()
{double priceB, priceS;
for(int i=OrdersTotal()-1;i>=0;i–)
{if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{if(Symbol()==OrderSymbol() && OrderType()==OP_BUY)
{priceB=NormalizeDouble(MarketInfo(OrderSymbol(),MODE_BID), Digits);
OrderClose(OrderTicket(),OrderLots(),priceB,1000,0);}
if(Symbol()==OrderSymbol() && OrderType()==OP_SELL)
{priceS=NormalizeDouble(MarketInfo(OrderSymbol(),MODE_ASK), Digits);
OrderClose(OrderTicket(),OrderLots(),priceS,1000,0);}
if(OrderType()==-1) OrderDelete(OrderTicket());}}
return;}
相关资源
暂无评论...