你好我是一位外匯交易者,我希望透過自動交易軟體來達到賺錢的目的,希望有識之士一起努力,我用的交易系統是fxdd,我會把一些以前用過的交易軟體慢慢放上來,希望能拋磚引玉,,
//+------------------------------------------------------------------+
//| 2xian_1.mq4 |
//| Copyright ?2005, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
extern double TakeProfit =500;
extern double Lots = 1;
extern double TrailingStop =300;
extern double StopLoss= 100;
extern double MaPeriod3=10;
extern double MaPeriod6=20;
extern double leave=30;
extern double leave3=20;
extern double SoundON=0;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double h1,h2,h3,buyprice,sellprice;
int start()
{
double A, B, C,D,E,F,AB,BC,AC,MALOW,MAHIGH;
int i,h,h4,over,cnt, ticket, total;
if(Bars<100)
{
Print("bars less than 100");
return(0);
}
if(TakeProfit<10)
{
Print("TakeProfit less than 10");
return(0); // check TakeProfit
}
if(total<1)
{
if(AccountFreeMargin()<(1000*Lots))
{
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}
}
A=iMA(NULL,0,MaPeriod3,0,MODE_EMA,PRICE_CLOSE,0);
B=iMA(NULL,0,MaPeriod6,0,MODE_EMA,PRICE_CLOSE,0);
E=MathAbs(A-B);
if(E>leave3/10000)h4=1;
if(A>B)AB=1; if(A<B)AB=-1; if(B>C)BC=1; if(B<C)BC=-1; if(A>C)AC=1; if(A<C)AC=-1;
Print("h1=",h1," h=",h," over=",over," A=",A," ",D," B=",B," C=",C," AB=",AB," BC=",BC," AC=",AC," h2=",h2," ",E);
if(AB==1 && h4==1)h=1;
if(AB==-1 && h4==1)h=-1;
if(h1==1 && (OrderOpenPrice()+leave/10000<Ask||OrderOpenPrice()-leave/10000>Bid))h2=1;
if(h1==-1 && (OrderOpenPrice()+leave/10000<Ask||OrderOpenPrice()-leave/10000>Bid))h2=1;
// h2=(sellprice+leave/10000);
// h3=(buyprice-leave/10000);
if(h1==-1 && h2==1 && AB==1)over=-1; //&& h2<Bid
if(h1==1 && h2==1 && AB==-1)over=1; //&& h3>Ask
total=OrdersTotal();
for (i=0;i< total;i++)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY) // long position is opened
{
if(over==1)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position
over=0;
h=0;
h1=0;
buyprice=-100000;
h2=0;
return(0); // exit
}
}
else // go to short position
if(over==-1)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position
over=0;
h=0;
h1=0;
h2=0;
sellprice=100000;
return(0); // exit
}
}
}
total=OrdersTotal();
if(total<1)
{
if (h==1)
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask -StopLoss*Point,Ask+TakeProfit*Point,0,16384,0,DodgerBlue);
buyprice=Ask;
h1=1;
h2=0;
if (SoundON==1) Alert("BUY signal at Ask=",Ask,", Bid=",Bid,", Time=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime())," Symbol=",Symbol()," Period=",Period());
return(0);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());
return(0);
}
if(h==-1)
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,0,16384,0,DeepPink);
sellprice=Bid;
h1=-1;
h2=0;
if (SoundON==1) Alert("SELL signal at Ask=",Ask,", Bid=",Bid,", Date=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime())," Symbol=",Symbol()," Period=",Period());
return(0);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
}
else Print("Error opening SELL order : ",GetLastError());
return(0);
}
}
//----
return(0);
}
//+------------------------------------------------------------------+