第十六课 系统思维才是外汇交易的王道:以FxOverEasy交易系统为(8)
下面是FxOverEasy的自动交易程序,代入Metatrader4.0智能交易即可,具体方法可以参考www.520fx.com的相关指南。
#property copyright“Copyright?2009,Dina”
#define LONGCOLOR DodgerBlue
#define SHORTCOLOR OrangeRed
extern bool UseAscTrend=0;
extern int StopLoss=15,
TrailingStopTrigger=15,
TrailingStop=10,
MinChannelWidth=40,
TakeProfit=150,
PauseToReEntryMinutes=15,
Lagueπe ValidityMinutes=45;
extern bool DebugTrace=1;
in LastSignalTime,
LaguerreSignal,
LaguerreSignaltime;
int init(){return(0);}
int deinit (){return(0);}
int start()
{
double UL,DL;
int res=0;
if(Bars<20)return(0);
int currenttrades=0;
for(intx=0;x < OrdersTotal();x++){
OrderSelect(x,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol()){
currenttrades++;
}
}
if(currenttrades==0){
if(AccountFreeMargin()<1000)
return;
iCustom.(NULL,0,“SHI_Channel”,0,0;
double MIDL2=ObjectGet(“MIDL”,OBJPROP PRICE2);
double MIDL1=ObjectGet(“MIDL”,OBJPROP PRICE1);
double TL1=ObjectGet(“TL1”,OBJPROP_PRICE2);
double TL2=ObjectGet(“TL2”,OBJPROP_PRICE2);
if(TL1 > TL2){UL=TL1;DL=TL2;}else {UL=TL2;DL=TL1;}
double i_Trend1=iCustom(NULL,0,“i_Trend”,0,0);
double i_Trend2=iCustom(NULL,0,“i_Trend”,1,0);
double Juice1=iCustom(NULL,0,“Juice”,0,0);
double PAsctrnd 1=0,
PAsctrnd2=0;
if(UseAscTrend){
PAsctrnd1=iCustom(NULL,0,“PerkyAsctrend1”,0,0);
PAsctrnd2=iCustom(NULL,0,“Perky Asctrend1”,1,0);
else {
PAsctrnd1=1; //not taken into account(make it irrelevant,i.e. set always true)
PAsctrnd2=1;
//must be checked after AscTrend(!)
double Laguerre1=iCustom(NULL,0,“Laguerre”,0,0);
double Laguerre2=iCustom(NULL,0,“Laguerre”,0,1);
if(Laguerre2 < 0.15 && Laguerrel>=0.15){
LaguerreSignal=1;//LONG
LaguerreSignaltime=Time[0];
}
else
if(Laguerre2 > 0.75 && Laguerrel <= 0.75){
LaguerreSignal = 1; //SHORT
LaguerreSignaltime = Time[0];
}
if(LaguerreSignal!=0 &&
(Time[0]-LaguerreSignaltime)>LaguerreValidityMinutes*60){
LaguerreSignal=0;//expire laguerre crossing signal after n mintues
}
res= 0;
if(Juice1 > 0.0 && UL-DL>MinChannelWidth*Point &&
(Time[0]-LastSignalTime)> PauseToReEntryMinutes*60) {
if(MIDI2 > MIDL1 && Ask
-
DL && i_Trend1>i_Trend2 && LaguerreSignal==1 && PAsctrnd1 >0.0) {
res=OrderSend(Symbol(),OP_BUY,1,Ask,5,Ask-Stoploss*Point,Ask+TakeProfit*Point,“”,0,0,LONGCOLOR);
}
if(MIDI2 < MIDL1 && Bid < UL && Bid > DL && i_Trend1 > i_Trend2 && LaguerreSignal==1 && PAsctrnd2>0.0){
res=OrderSend(Symbol(),OP_SELL,1,Bid,5,Bid+StopLoss*Point,BidTakeProfit*Point,“”,0,0,SHORTCOLOR);
}
if(res!=0){
LastSignalTime=Time[0];
Print(“****TRADE****”);
}
}
if(res!=0 || DebugTrace){
Print(Symbol(),“”,Bid,“/”,Ask,“--Laguerre2/1/sig=”,Laguerre2,“/”,Laguerre1,“/”,LaguerreSignal,“,Juice=”,Juice1);
Print(“SHI=”,MIDI2-MIDL1,“,ITrend=”,i_Trend1,“/”,i_Trend2,“,AscTrend=”,PAsctrnd1,“/”,PAsctmd2);
}
}
else
{
for(int i=0;i<OrdersTotal();i++){
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)break;
if(OrderSymbol()!=Symbol()) continue;
double trailstop = TrailingStop*Point,
trailstoptrigger=TrailingStopTrigger*Point,
unrealisedprofit;
switch(OrderType()){
case OP_BUY:
unrealisedprofit=Bid-OrderOpenPrice();
if(TrailingStop && unrealisedprofit > trailstoptrigger && (!OrderStopLoss()|| OrderStoplρss() < Bid-trailstop))
OrderModify(OrderTicket(),0,Bid-trailstop,OrderTakeProfit(),0,LONGCOLOR);
break;
case OP_SELL:
unrealisedprofit=OrderOpenPrice()-Ask;
if(TrailingStop && unrealisedprofit > trailstoptrigger &&
(!OrderStopLoss()||OrderStopLoss()> Ask+trailstop))
OrderModify(OrderTicket(),0,Ask+trailstop,OrderTakeProfit(),0,SHORTCOLOR);
break;
}
}
}
}