//+——————————————————————+
//| FM-AhilAnger.mq4 |
//| |
//| |
//+——————————————————————+
#property copyright “”
#property link “”
//+——————————————————————+
extern string c0=”————————“;
extern double LotStart =0.01; //羊囵蝾恹?腩? 篑蜞磬怆桠囹?扈龛爨朦眍 忸珈铈睇?
extern double Risk =10; //朽犷麒?痂耜 ?%
extern int Step =5; //剜?潆 恹躅溧 ?镳铘栩
extern string c6=”————————“;
extern double StopProcent =0; //羊铒 ?% 铗 溴镱玷蜞
extern int Magic =1111; //蠕屙蜩翳赅蝾?耦忮蝽桕?
//+——————————————————————+
string Name =”FM-AhilAnger”; //褥 囫镥痱?潆 觐祆屙蜞痂邂 ?铕溴疣?
int Slip =10; //锑犟桁嚯铄 镳铖赅朦琨忄龛?
//+——————————————————————+
bool clos, sel, del;
int send, D;
bool Buy,Sell;
//+——————————————————————+
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;
//+——————————————————————+
Buy=false;Sell=false;
if(Open[1]>Close[1]){Buy=true;}
if(Open[1]<Close[1]){Sell=true;}
//+——————————————————————+
if(CountH(-1,Magic)==0 && Count(-1,Magic)==0 && Buy)
{send=OrderSend(Symbol(),OP_BUY,LotStart,Ask,Slip,Ask-100*D*Point,0,Name,Magic,0,Green);}if(CountH(-1,Magic)==0 && Count(-1,Magic)==0 && Sell)
{send=OrderSend(Symbol(),OP_SELL,LotStart,Bid,Slip,Bid+100*D*Point,0,Name,Magic,0,Red);}
//+——————————————————————+
if(Count(OP_BUY,Magic)>0 && Count(OP_BUY,Magic)<2 && Ask-Step*D*Point>=BuyPric())
{send=OrderSend(Symbol(),OP_BUY,Lot,Ask,Slip,0,0,Name,Magic,0,Green);}
if(Count(OP_SELL,Magic)>0 && Count(OP_SELL,Magic)<2 && Bid+Step*D*Point<=SellPric())
{send=OrderSend(Symbol(),OP_SELL,Lot,Bid,Slip,0,0,Name,Magic,0,Red);}//+——————————————————————+
double ProfProc=(AccountBalance()/100)*(Risk/4);
double StopProc=(AccountBalance()/100)*StopProcent*(-1);if(Profit(-1)>=ProfProc && ProfProc!=0)
{Closer();}if(Profit(-1)<StopProc && StopProcent!=0)
{Closer();}
//+——————————————————————+
return(0);}
//+——————————————————————+
int Count(int type,int key)
{int count=0;
for(int i=OrdersTotal()-1;i>=0;i–)
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{if(Symbol()==OrderSymbol() && key==OrderMagicNumber() && (type==-1 || OrderType()==type)) count++;}
return(count);}int CountH(int type,string key)
{int count=0;
for(int i=OrdersHistoryTotal()-1;i>=0;i–){
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
{if(Symbol()==OrderSymbol() && OrderMagicNumber()==key && OrderCloseTime()>=iTime(Symbol(),0,0) && (type==-1 || OrderType()==type)) count++;}}
return(count);}
//——————————————————————–+
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()+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 && Magic==OrderMagicNumber())
{priceB=NormalizeDouble(MarketInfo(OrderSymbol(),MODE_BID), Digits);
clos=OrderClose(OrderTicket(),OrderLots(),priceB,100,0);}
if(Symbol()==OrderSymbol() && OrderType()==OP_SELL && Magic==OrderMagicNumber())
{priceS=NormalizeDouble(MarketInfo(OrderSymbol(),MODE_ASK), Digits);
clos=OrderClose(OrderTicket(),OrderLots(),priceS,100,0);}}}
return;}
//———-痒栩噱?觐腓麇耱忸 镳铋溴睇?矬黻蝾?镱 徉?—————+
double BuyPric() {
double oldorderopenprice;
int oldticketnumber;
double unused = 0;
int ticketnumber = 0;
for (int cnt = OrdersTotal() – 1; cnt >= 0; cnt–) {
clos=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–) {
clos=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);}
相关资源
暂无评论...