//+——————————————————————+
//| FM-GOLDAST.mq4 |
//| |
//| |
//+——————————————————————+
#property copyright “”
#property link “”
//———————–相疣戾蝠?———————————–+
extern double Risk =2; //朽犷麒?痂耜 ?%
extern int Step =10; //剜?戾驿?铕溴疣扈
extern double SLproc =0; //羊铒 ?%
extern int Tral =40; //茵嚯 ?矬黻蜞?
extern int Dist =30; //朽耱?龛?铗 鲥睇 漕 铗腩驽?
extern bool Use_Limit =true; //玛膻鬣屐 腓扈蝽 铗腩骊?
extern bool Use_Stop =false; //玛膻鬣屐 耱铒钼 铗腩骊?
//——————————————————————–+
int time2,time3,time4,time5;
//——————————————————————–+
datetime NewBar =0;
int TralStep =1;
int Modify =1;
bool Use_Modyfy =true;
int Slip =10;
int Magic =123;
string Name =”FM-GOLDAST”;
int D;
int init()
{D=1;
if (Digits==5 || Digits==3)D=10;
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);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;
//———————–悟牮噱?铕溴疣——————————+
if(NewBar!= Time[0])
{NewBar = Time[0];
if(Use_Limit)
if(Count(OP_BUY)==0 && Count(OP_SELL)==0 && Count(OP_BUYLIMIT)==0)
{OrderSend(Symbol(),OP_BUYLIMIT,Lot,Ask-Dist*D*Point,Slip,0,0,Name,Magic,0,Green);}if(Use_Limit)
if(Count(OP_SELL)==0 && Count(OP_BUY)==0 && Count(OP_SELLLIMIT)==0)
{OrderSend(Symbol(),OP_SELLLIMIT,Lot,Bid+Dist*D*Point,Slip,0,0,Name,Magic,0,Red);}if(Use_Stop)
if(Count(OP_BUY)==0 && Count(OP_SELL)==0 && Count(OP_BUYSTOP)==0)
{OrderSend(Symbol(),OP_BUYSTOP,Lot,Bid+Dist*D*Point,Slip,0,0,Name,Magic,0,Green);}if(Use_Stop)
if(Count(OP_SELL)==0 && Count(OP_BUY)==0 && Count(OP_SELLSTOP)==0)
{OrderSend(Symbol(),OP_SELLSTOP,Lot,Ask-Dist*D*Point,Slip,0,0,Name,Magic,0,Red);}if(Use_Modyfy && Count(OP_BUY)==0 && Count(OP_SELL)==0)modify();}
//————————–茵彘腓磴 耱铒——————————+
if(Count(OP_BUY)==1)
{Trail(Magic);}
if(Count(OP_SELL)==1)
{Trail(Magic);}
//———————————————————————+
if(Count(OP_BUY)>0 && Ask+Step*D*Point<=BuyPric())
{double Lotb=Lot*Count(OP_BUY)+Lot;
OrderSend(Symbol(),OP_BUY,Lotb,Ask,Slip,0,0,Name,Magic,0,Green);}
if(Count(OP_SELL)>0 && Bid-Step*D*Point>=SellPric())
{double Lots=Lot*Count(OP_SELL)+Lot;
OrderSend(Symbol(),OP_SELL,Lots,Bid,Slip,0,0,Name,Magic,0,Red);}double P_Max=(AccountBalance()/100)*(Risk/2);
double S_Max=(AccountBalance()/100)*SLproc*(-1);
if(Count(-1)>1 && Profit(-1)>=P_Max && P_Max!=0)Closer(-1);
if(Count(-1)>1 && Profit(-1)<S_Max && S_Max!=0)Closer(-1);
//———————–愉嚯屐 铗腩骊?——————————+
if(Count(OP_BUY)>0) CloserS(Magic,-1);
if(Count(OP_SELL)>0) CloserB(Magic,-1);
return(0);}
//————————–茵彘腓磴 耱铒——————————+
void Trail(int _key)
{for(int i=0; i<OrdersTotal(); i++)
if (OrderSelect(i,SELECT_BY_POS) && OrderSymbol()==Symbol() && OrderMagicNumber()==_key)
{if(Tral!=0){
if (OrderType()==OP_BUY && Bid>MathMax(OrderOpenPrice(),OrderStopLoss())+(Tral+TralStep)*D*Point)
if (!OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Tral*D*Point,OrderTakeProfit(),0))
{}
if (OrderType()==OP_SELL && ((Ask<MathMin(OrderOpenPrice(),OrderStopLoss())-(Tral+TralStep)*D*Point &&
OrderStopLoss()!=0)||(Ask<OrderOpenPrice()-(Tral+TralStep)*D*Point && OrderStopLoss()==0)))
if (!OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Tral*D*Point,OrderTakeProfit(),0))
{}}}}
//—————-物疱溴?屐 蜩?铕溴疣——————————–+
int Count(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 && (type==-1 || OrderType()==type)) count++;}
return(count);}
//——————填滂翳鲨痼屐 铕溴疣——————————–+
void modify()
{for(int i=OrdersTotal()-1;i>=0;i–)
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{if(Symbol()==OrderSymbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==2 && time2+(Modify)<TimeCurrent())
{OrderModify(OrderTicket(),Ask-Dist*D*Point,0,0,0,Green);
time2=TimeCurrent();}
if(OrderType()==3 && time3+(Modify)<TimeCurrent())
{OrderModify(OrderTicket(),Ask+Dist*D*Point,0,0,0,Red);
time3=TimeCurrent();}
if(OrderType()==5 && time5+(Modify)<TimeCurrent())
{OrderModify(OrderTicket(),Ask-Dist*D*Point,0,0,0,Red);
time5=TimeCurrent();}
if(OrderType()==4 && time4+(Modify)<TimeCurrent())
{OrderModify(OrderTicket(),Ask+Dist*D*Point,0,0,0,Green);
time4=TimeCurrent();}}}}
//——————青牮噱?镳栳黒筢铌 ————————–+
void CloserS(int _key, int type)
{for(int i=OrdersTotal()-1;i>=0;i–)
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{if(Symbol()==OrderSymbol() && OrderMagicNumber()==Magic)
if(OrderType()==OP_SELLLIMIT) OrderDelete(OrderTicket());
if(OrderType()==OP_SELLSTOP) OrderDelete(OrderTicket());}}
void CloserB(int _key, int type)
{for(int i=OrdersTotal()-1;i>=0;i–)
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{if(Symbol()==OrderSymbol() && OrderMagicNumber()==Magic)
if(OrderType()==OP_BUYSTOP) OrderDelete(OrderTicket());
if(OrderType()==OP_BUYLIMIT) OrderDelete(OrderTicket());}}//———-痒栩噱?觐腓麇耱忸 镳铋溴睇?矬黻蝾?镱 徉?—————+
double BuyPric() {
double oldorderopenprice;
int oldticketnumber;
double unused = 0;
int ticketnumber = 0;
for (int cnt = OrdersTotal() – 1; cnt >= 0; cnt–) {
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber() != Magic) continue;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_BUY) {
oldticketnumber = OrderTicket();
if (oldticketnumber > ticketnumber) {
oldorderopenprice = OrderOpenPrice();
unused = oldorderopenprice;
ticketnumber = oldticketnumber;}}}
return (oldorderopenprice);}
//———-痒栩噱?觐腓麇耱忸 镳铋溴睇?矬黻蝾?镱 皴腚—————+
double SellPric() {
double oldorderopenprice;
int oldticketnumber;
double unused = 0;
int ticketnumber = 0;
for (int cnt = OrdersTotal() – 1; cnt >= 0; cnt–) {
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber() != Magic) continue;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_SELL) {
oldticketnumber = OrderTicket();
if (oldticketnumber > ticketnumber) {
oldorderopenprice = OrderOpenPrice();
unused = oldorderopenprice;
ticketnumber = oldticketnumber;}}}
return (oldorderopenprice);}
//——————青牮噱?镳栳黒筢铌 ————————–+
void Closer(int type)
{for(int i=OrdersTotal()-1;i>=0;i–)
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{if(OrderMagicNumber()==Magic && Symbol()==OrderSymbol())
if(OrderType()==OP_BUY) OrderClose(OrderTicket(),OrderLots(),Bid,Slip,0);
if(OrderType()==OP_SELL) OrderClose(OrderTicket(),OrderLots(),Ask,Slip,0);}}
//——————痒栩噱?镳栳黒筢铌 —————————-+
double Profit(int type)
{double Profit = 0;
for (int cnt = OrdersTotal() – 1; cnt >= 0; cnt–) {
if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
{if (OrderMagicNumber()==Magic && (OrderType() == type || type==-1)) Profit += OrderProfit();}}
return (Profit);}
暂无评论...