//+------------------------------------------------------------------+
//2006.12.20 V2.0 增加了對手動訂單的主動止盈功能
//2007.01.03 V2.1 對於已經成交的對沖單,系統不能自動平倉或刪除,需要手動平倉.
//2007.01.09 V2.2 系統自動生成對沖單後,如果手動訂單設置了止盈,則取消止盈.
#property copyright ""
#property link ""
#include <stdlib.mqh>
extern bool USE_ATR=true;
extern int PercentATR=40; //40% ATR
extern double HedgingLevel=30;
extern bool AutoTakeProfit=false;
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
Hedge_Assistante();
//----
return(0);
}
//+------------------------------------------------------------------+
void Hedge_Assistante()
{
int i,Tic,Ticket,Hedge,Type;
double TP;
string msg="/n"+"ATR(14)="+iATR(Symbol(),PERIOD_D1,14,0)+"/n"+"dHigh:"+iHigh(Symbol(),PERIOD_D1,0)+" dLow:"+
iLow(Symbol(),PERIOD_D1,0)+"/n"+"AtrHi:"+(iLow(Symbol(),PERIOD_D1,0)+iATR(Symbol(),PERIOD_D1,14,0))+
" AtrLo:"+(iHigh(Symbol(),PERIOD_D1,0)-iATR(Symbol(),PERIOD_D1,14,0));
Comment( msg,Red,10);
//1)僅對於BUY/SELL 手動訂單進行止盈, BUY/SELL STOP 和BUY/SELL LIMIT 的手動訂單不會進行止盈
//2)GBP/USD 止盈 17點, 其他貨幣對止盈 10點
if(AutoTakeProfit)
{ for(i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) continue;
if(Symbol()==OrderSymbol() && OrderMagicNumber()==0 && OrderProfit()!=0) //找到手動訂單
{
if(Symbol()=="GBPUSD") TP=17; else TP=10; // GBPUSD takeprofit is 17, other pairs takeprofit is 10
if(OrderType()==OP_BUY )
{
if (Bid-OrderOpenPrice()>=TP*Point)
{
if(OrderClose(OrderTicket(),OrderLots(),Bid,2,0)==true)
{Alert("Good Job! 自動止盈@",Bid," ",OrderTicket()," ",OrderTakeProfit()," - ",OrderOpenPrice(),
" = ",OrderTakeProfit()-OrderOpenPrice()," X ",OrderLots()," = ",OrderProfit());
return(0);
}
else Alert(OrderTicket()," Close Order err---->",ErrorDescription(GetLastError()));
}
if (OrderTakeProfit()-OrderOpenPrice()<(TP-1)*Point || OrderTakeProfit()-OrderOpenPrice()>(TP+1)*Point)
{
if(OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderOpenPrice()+TP*Point,0,0)==true)
{Alert(OrderTicket()," ",Symbol()," Buy=",OrderOpenPrice()," 設置止盈@",OrderOpenPrice()+TP*Point);
Sleep(10000);
}
else Alert(OrderTicket()," ",Symbol()," Modify TakeProfit error---->",ErrorDescription(GetLastError()));
}
}
if(OrderType()==OP_SELL)
{
if (OrderOpenPrice()-Ask>=TP*Point)
{
if(OrderClose(OrderTicket(),OrderLots(),Ask,2,0)==true)
{Alert("Good Job! 自動止盈@",Ask," ",OrderTicket()," ",OrderOpenPrice()," - ",OrderTakeProfit(),
" = ",OrderOpenPrice()-OrderTakeProfit()," X ",OrderLots()," = ",OrderProfit());
return(0);
}
else Alert(OrderTicket()," ",Symbol()," Modify TakeProfit error---->",ErrorDescription(GetLastError()));
}
if (OrderOpenPrice()-OrderTakeProfit()>(TP+1)*Point ||OrderOpenPrice()-OrderTakeProfit()<(TP-1)*Point)
{
if(OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderOpenPrice()-TP*Point,0,0)==true)
{Alert(OrderTicket()," ",Symbol()," Sell=",OrderOpenPrice()," 設置止盈@",OrderOpenPrice()-TP*Point);
Sleep(10000);
}
else Alert(OrderTicket()," ",Symbol()," Modify TakeProfit error----> ",ErrorDescription(GetLastError()));
}
}
}
}
}
//-------------------------------------------------------------------------
if (USE_ATR) HedgingLevel=iATR(NULL,PERIOD_D1,14,0)*PercentATR/100;
else HedgingLevel=HedgingLevel*Point;
//Check all manual order, if no it's countpart hedging order, then creat one
for (i=0;i<OrdersTotal();i++)
{if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(Symbol()==OrderSymbol() && OrderMagicNumber()==0 && OrderProfit()!=0/*Actived!*/ ) //it's a manual Order
{
Hedge=0;
Ticket=OrderTicket();
Type=OrderType();
double Lots=OrderLots(),OpenPrice=OrderOpenPrice();
for (int j=i;j<OrdersTotal();j++)
{if (OrderSelect(j,SELECT_BY_POS,MODE_TRADES)==false) break;
if (Ticket==OrderMagicNumber()) Hedge++;
}
if (Hedge==0) //no hedge order, creat one
{
if (Type==OP_BUY)
{
Tic=OrderSend(Symbol(),OP_SELLSTOP,Lots, NormalizeDouble(OpenPrice-HedgingLevel,Digits),0,0,0,"Hedging "+DoubleToStr(Ticket,0),Ticket,0,Green);
if( Tic>0) Alert(Ticket,"的對沖單:",Tic," 生成 SELL STOP:",NormalizeDouble(OpenPrice-HedgingLevel,Digits)," ",Lots,"Lots");
}
if (Type==OP_SELL)
{
Tic=OrderSend(Symbol(),OP_BUYSTOP,Lots,NormalizeDouble(OpenPrice+HedgingLevel,Digits),0,0,0,"Hedging "+DoubleToStr(Ticket,0),Ticket,0,Red);
if( Tic>0) Alert(Ticket,"的對沖單:",Tic," 生成 BUY STOP:",NormalizeDouble(OpenPrice+HedgingLevel,Digits)," ",Lots,"Lots");
}
}
}
}
//Check all hedge order, if no it's countpart manual order, then delete the hedge Order
for (i=0;i<OrdersTotal();i++)
{if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if (Symbol()==OrderSymbol() && OrderMagicNumber() !=0) //it's a hedge OrderClose
{Hedge=0;
Ticket=OrderTicket();
int Magic=OrderMagicNumber();
for (j=0;j<OrdersTotal();j++) //check all manual OrderClose
{if (OrderSelect(j,SELECT_BY_POS,MODE_TRADES)==false) break;
if (Magic==OrderTicket()) Hedge++;//use Hedge Order's Magic# compare with Maunal order's Ticket#
}
if (Hedge==0 && OrderType()>1/*exclde type OP_BUY && OP_SELL */ ) OrderDelete(Ticket);//no it's countpart manual order exist, delete this hedge OrderClose
}
}
//v2.2 revise manul order TP=0 if Hedge order have created.
for (i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS)==false) continue;
if(Symbol()==OrderSymbol() && OrderMagicNumber()!=0 && OrderType()<2) //Actived HedgeOrder founded!
{
Ticket=OrderMagicNumber();
if( OrderSelect(Ticket,SELECT_BY_TICKET)==false) break;
if( OrderTakeProfit()!=0)
if(OrderModify(Ticket,OrderOpenPrice(),0,0,0,0)) Alert(Ticket,"對沖單已生成, 系統將止盈改為零,需要手動開鎖!");
}
}
}
外_匯_邦 WaiHuiBang.com
當今,全球主要國家都在加快布局區塊鏈技術發展,想要確保我國占據區塊鏈領域的創新制高點,需要加快區塊鏈和相關前沿信息技術的深度融合,推動
日前,巴西首次使用區塊鏈技術地產交易進行記錄。這反映了當前全球房地產企業利用該技術處理房地產購買和轉讓的趨勢。Cyrela是巴西最大的當地
我們首先從字面上理解一下分叉,分叉在區塊鏈裡面來說,顧名思義就是原來一根鏈,最後通過分叉分為了兩根,一分為二,可以這樣理解。在區塊鏈中分叉
面對破產事務辦理環節多、程序成本高、債權關系復雜等“老大難”問題,深圳市發展和改革委員會和國家稅務總局深圳市稅務局研發的“區塊鏈破產事務辦
彭博新聞社報道,知情人士稱,中國計劃進一步監管比特幣等虛擬貨幣跨境流動。 知情人士表示,針對當前包括比特幣在內的虛擬貨幣交易中出現的
近來股市持續陰跌,雖然還不能斷言底在哪裡、何時見底,但老股民都知道,股市越是大幅下跌,就越是機會大於風險。 首
定律一: 尾盤急拉 圖窮匕見盤中手法研究:這種尾盤急拉,多半是依靠大單對倒,在收盤前兩三分鐘內將股價推高幾個百分點,有的甚至推至漲停板。而此
最近小編看到不少網友在網上咨詢,問自己已經畢業並有了工作收入,想提前償還生源地助學,那麼生源地助學貸款可部分提前還款嗎?下面一起來
最佳答案: 之前是可以通過改簽再退票來省手續費的,不過根據鐵路局的新規定:1、開車前15天(不含)以
最佳答案: 親親小貸主要通過三方上征信,建議不要逾期,現在有的小貸不上人行征信,但是會上大數據黑名單