帖子
作者
回复/查看
最后发表
2013-07-30 11:24
2010-01-22 15:18
基于五线谱开仓出现的价位的滞后性,自己写了一个简单的EA,因为自己水平,ea写得不好,但其中的开仓条件可以提供大家做参考
//+------------------------------------------------------------------+
//| This MQL is generated by Expert Advisor Builder |
//| http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/ |
//| |
//| In no event will author be liable for any damages whatsoever. |
//| Use at your own risk. |
//| |
//+------------------- DO NOT REMOVE THIS HEADER --------------------+
#define SIGNAL_NONE 0
#define SIGNAL_BUY 1
#define SIGNAL_SELL 2
#define SIGNAL_CLOSEBUY 3
#define SIGNAL_CLOSESELL 4
#property copyright "Expert Advisor Builder"
#property link "http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/"
extern int MagicNumber = 0;
extern bool SignalMail = False;
extern bool EachTickMode = False;
extern double Lots = 1.0;
extern int Slippage = 3;
extern bool UseStopLoss = True;
extern int StopLoss = 30;
extern bool UseTakeProfit = True;
extern int TakeProfit = 250;
extern bool UseTrailingStop = True;
extern int TrailingStop = 55;
int BarCount;
int Current;
bool TickCheck = False;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init() {
BarCount = Bars;
if (EachTickMode) Current = 0; else Current = 1;
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit() {
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start() {
int Order = SIGNAL_NONE;
int Total, Ticket;
double StopLossLevel, TakeProfitLevel;
if (EachTickMode && Bars != BarCount) TickCheck = False;
Total = OrdersTotal();
Order = SIGNAL_NONE;
//+------------------------------------------------------------------+
//| Variable Begin |
//+------------------------------------------------------------------+
double Buy1;
double Buy2;
double Buy3;
double Sell1;
double Sell2;
//均线;ADX;
double MA100now =iMA(NULL, 0, 100, 0, MODE_EMA, PRICE_CLOSE, Current + 0);
double MA100a =iMA(NULL, 0, 100, 0, MODE_EMA, PRICE_CLOSE, Current + 1);
double MA200now =iMA(NULL, 0, 200, 0, MODE_EMA, PRICE_CLOSE, Current + 0);
double MA200a =iMA(NULL, 0, 200, 0, MODE_EMA, PRICE_CLOSE, Current + 1);
double Closenow =iClose(NULL, 0, Current + 0);
double Close1 =iClose(NULL, 0, Current + 1);
double pAO =iAO(NULL, 0, Current + 0);
//buy信号
if(MA200now>=MA100now &&Closenow>MA200now&&Close1<=MA100a&&pAO>0)
Buy1=true;
if(MA200now>=MA100now &&Closenow>MA200now&&Close1<=MA200a&&pAO>0)
Buy2=true;
if(MA100now>=MA200now &&Closenow>MA100now&&Close1<=MA200a&&pAO>0)
Buy3=true;
////////////////////////////////////////
/////sell
if(MA100now>=MA200now &&Closenow=MA200a&&pAO<0)
Sell1=true;
if(MA100now<=MA200now &&Closenow=MA200a&&pAO<0)
Sell2=true;
/////////////
double CloseBuy1_1 = pAO;
double CloseBuy1_2 = 0;
double CloseSell1_1 = pAO;
double CloseSell1_2 = 0;
//+------------------------------------------------------------------+
//| Variable End |
//+------------------------------------------------------------------+
//Check position
bool IsTrade = False;
for (int i = 0; i < Total; i ++) {
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderType() <= OP_SELL && OrderSymbol() == Symbol()) {
IsTrade = True;
if(OrderType() == OP_BUY) {
//Close
//+------------------------------------------------------------------+
//| Signal Begin(Exit Buy) |
//+------------------------------------------------------------------+
if (CloseBuy1_1 <= CloseBuy1_2) Order = SIGNAL_CLOSEBUY;
//+------------------------------------------------------------------+
//| Signal End(Exit Buy) |
//+------------------------------------------------------------------+
if (Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");
if (!EachTickMode) BarCount = Bars;
IsTrade = False;
continue;
}
//Trailing stop
if(UseTrailingStop && TrailingStop > 0) {
if(Bid - OrderOpenPrice() > Point * TrailingStop) {
if(OrderStopLoss() < Bid - Point * TrailingStop) {
OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);
if (!EachTickMode) BarCount = Bars;
continue;
}
}
}
} else {
//Close
//+------------------------------------------------------------------+
//| Signal Begin(Exit Sell) |
//+------------------------------------------------------------------+
if (CloseSell1_1 >= CloseSell1_2) Order = SIGNAL_CLOSESELL;
//+------------------------------------------------------------------+
//| Signal End(Exit Sell) |
//+------------------------------------------------------------------+
if (Order == SIGNAL_CLOSESELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell");
if (!EachTickMode) BarCount = Bars;
IsTrade = False;
continue;
}
//Trailing stop
if(UseTrailingStop && TrailingStop > 0) {
if((OrderOpenPrice() - Ask) > (Point * TrailingStop)) {
if((OrderStopLoss() > (Ask + Point * TrailingStop)) || (OrderStopLoss() == 0)) {
OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop, OrderTakeProfit(), 0, DarkOrange);
if (!EachTickMode) BarCount = Bars;
continue;
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| Signal Begin(Entry) |
//+------------------------------------------------------------------+
if (Buy1==true || Buy2 ==true||Buy3==true) Order = SIGNAL_BUY;
if (Sell1==true || Sell2==true) Order = SIGNAL_SELL;
//+------------------------------------------------------------------+
//| Signal End |
//+------------------------------------------------------------------+
//Buy
if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
if(!IsTrade) {
//Check free margin
if (AccountFreeMargin() < (1000 * Lots)) {
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}
if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0;
if (UseTakeProfit) TakeProfitLevel = Ask + TakeProfit * Point; else TakeProfitLevel = 0.0;
Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);
if(Ticket > 0) {
if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
Print("BUY order opened : ", OrderOpenPrice());
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");
} else {
Print("Error opening BUY order : ", GetLastError());
}
}
if (EachTickMode) TickCheck = True;
if (!EachTickMode) BarCount = Bars;
return(0);
}
}
//Sell
if (Order == SIGNAL_SELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
if(!IsTrade) {
//Check free margin
if (AccountFreeMargin() < (1000 * Lots)) {
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}
if (UseStopLoss) StopLossLevel = Bid + StopLoss * Point; else StopLossLevel = 0.0;
if (UseTakeProfit) TakeProfitLevel = Bid - TakeProfit * Point; else TakeProfitLevel = 0.0;
Ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);
if(Ticket > 0) {
if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
Print("SELL order opened : ", OrderOpenPrice());
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell");
} else {
Print("Error opening SELL order : ", GetLastError());
}
}
if (EachTickMode) TickCheck = True;
if (!EachTickMode) BarCount = Bars;
return(0);
}
}
if (!EachTickMode) BarCount = Bars;
return(0);
}
//+------------------------------------------------------------------+
2008-05-30 13:47
2008-05-28 00:07
2008-05-27 06:54
2008-05-26 08:57
2008-05-23 15:08
2008-05-23 11:27
2008-05-23 11:20
2008-05-23 11:05
2008-05-23 09:55
2008-05-22 16:57
谢谢!www.520fx.com将我的策略做成了EA,但我根据520fx论坛上的老师说的写了代码,发现只能做几回交易。你懂编程我将它贴上来你看看。具体要求请看http://bbs.520fx.com/viewthread.php?tid=5012&extra=page%3D1
//+------------------------------------------------------------------+
//| MT4_EA_制作速成班模板.mq4 |
//| Copyright 2008, MT4_EA_制作速成班模板. |
//| http://www.MT4_EA_制作速成班模板.net
| //+------------------------------------------------------------------+ #property copyright "MT4_EA_制作速成班模板" #property link "http://www.MT4_EA_制作速成班模板.net" //////////////////////// extern string _资金管理_ ="任选一个"; extern bool zijiguanli1= true;//false true、、 extern bool zijiguanli2= false;//false true、、 extern bool zijiguanli3= false;//false true、、 /////////////////////////////////// extern double cheng=1; double aa=0; int s=0,b=0,i; double CurrentBasket=0; double LotMM=0; double lotstart=0; double LotsMax=100; extern double lotab=0.1; double lots=0; double TP=200,TPP=0,SL=60,SLL=0; int slip=6; ////////////////////////////////// double mode=0; double LastOrderType; double LastPricesell; double LastPricebuy; double LastPrice; double OpenSells; double OpenSellStops; double OpenBuys; double OpenBuyStops; double SLauto; double Stoploss; /////////////////////////////// int cnt; extern int TrailingStop=40; /////////////////////////////// string text=""; //////////////////////// extern double macd12_1=12, macd12_2=26, macd12_3=9; double macd12now; extern double ma1=1,ma5=5,ma21=21,ma55=55,ma89=89; double ma1now,ma5now,ma21now,ma55now,ma89now; extern double adx14=14; double adx14now; //////////////////////////// double BaoZhenJing; ////////////////////////////// int panduan; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- jiancha();//检查判断 资金管理(); macd指标管理(); ma指标管理(); adx指标管理(); zhangchang();//战场管理 xianshi();//显示管理 TrailingStop();//移动止赢 //---- return(0); } //+------------------------------------------------------------------+ void jiancha() { b=0;s=0; for (int cnt=0; cnt<=OrdersTotal(); cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol()==Symbol() ) { mode=OrderType();LastOrderType=OrderType(); if (OrderType() == OP_SELL){ s++; LastPricesell=OrderOpenPrice();} if (OrderType() == OP_BUY ){ b++; LastPricebuy=OrderOpenPrice();} LastPrice=OrderOpenPrice(); if (OrderType()==OP_SELL) {OpenSells++;} if (OrderType()==OP_SELLSTOP) {OpenSellStops++;} if (OrderType()==OP_BUY) {OpenBuys++;} if (OrderType()==OP_BUYSTOP) {OpenBuyStops++;} } } }//end jiancha //+------------------------------------------------------------------+ void 资金管理() { lotstart=(AccountBalance()*lotab/10000); lots=lotstart; if(cheng==0){cheng=1;} CurrentBasket=AccountEquity()-AccountBalance(); ///////////////////////////////////////////////////////////////// if(zijiguanli1){ LotMM = lots;} ///////////////////////////////////////////////////////////////// if(zijiguanli2){ if(CurrentBasket<0 ) {LotMM=NormalizeDouble(lots*(OrdersTotal()*cheng)+lotstart,2); } if(CurrentBasket==0 ) {LotMM=NormalizeDouble(LotMM*0,2); } } ///////////////////////////////////////////////////////////////// if(zijiguanli3){ if(s+b==0){aa=1;} if(s+b==1){aa=3;} if(s+b==2){aa=7;} if(s+b==3){aa=11;} if(s+b==4){aa=20;} if(s+b==5){aa=31;} if(s+b==6){aa=42;} if(s+b==7){aa=54;} if(s+b==8){aa=66;} if(s+b==9){aa=76;} if(s+b>=10){aa=66;} if(CurrentBasket<0 ) {LotMM=NormalizeDouble(lotstart*aa,2); } if(CurrentBasket==0 ) {LotMM=NormalizeDouble(LotMM*0,2); } } ///////////////////////////////////////////////////////////////// if(LotMMLotsMax){LotMM=LotsMax;}
}//end zijiguanli
//+------------------------------------------------------------------+
void macd指标管理() {
macd12now = iMACD(NULL,0,macd12_1,macd12_2,macd12_3,PRICE_CLOSE,MODE_MAIN,0);
}
//+------------------------------------------------------------------+
void adx指标管理() { //由MT4_EA_制作速成班学员asp_win提供
adx14now = iADX(NULL, 0, adx14, PRICE_CLOSE, MODE_MAIN, 0);
}
//+------------------------------------------------------------------+
void ma指标管理()
{
ma1now = iMA(NULL,0,ma1,0,MODE_EMA,PRICE_CLOSE,0);
ma5now = iMA(NULL,0,ma5,0,MODE_EMA,PRICE_CLOSE,0);
ma21now = iMA(NULL,0,ma21,0,MODE_EMA,PRICE_CLOSE,0);
ma55now = iMA(NULL,0,ma55,0,MODE_EMA,PRICE_CLOSE,0);
ma89now = iMA(NULL,0,ma89,0,MODE_EMA,PRICE_CLOSE,0);
}
//+------------------------------------------------------------------+
void zhangchang() {
//--- 如果开仓保证金超过上限,则返还不交易。 ------------------
if( AccountMargin() / (AccountMargin() + AccountFreeMargin()) >= 1 ) { return(0); }
BaoZhenJing = MarketInfo( Symbol(), MODE_MARGINREQUIRED); // 一个标准手需保证金金额。
BaoZhenJing = BaoZhenJing * LotMM ; // 下单需用的保证金
if( (AccountMargin()+BaoZhenJing) / (AccountMargin()+AccountFreeMargin()) >= 1 ) { return(0); }
//---------------------------------------------------------------------
//这边编写策略(下面if(s+b==100)暂时是故意这样写的,其实是为了防止出错)
if(s+b==0){sellme();buyme();closebuy();closesell();}
/////第一部分/////////////////////
if(s+b==0 //判断没有交易才能判断1
&& panduan==0 //判断0才能判断1
&& ma5now>ma55now //ma5大过ma55才能判断1
&& ma5now25 //判断ADX14大过25才能交易
&& macd12now<0 //判断macd12小过0才能交易
&& Close[0]ma89now
&& adx14now>25
&& macd12now>0
&& Close[0]>Open[0] //判断是在上升
){buyme();panduan=0;}
//////第四部分/////////////////////
if(ma89now>ma55now){SLauto=(ma89now-ma55now)/Point;} //止损点数计算[//老师我不知道这个是什么原理,也判断不了是否有错]
if(ma89nowStoploss){SL=SLauto;} //如果判断自动止损大一点,就选自动止损
if(SLautoma21now
){closesell();}
if(s+b==1
&& ma5now0) { TPP=Ask+TP*Point; }
if (SL==0) { SLL=0; } if(SL>0) { SLL=Ask-SL*Point; }
OrderSend(Symbol(),OP_BUY,LotMM,Ask,slip,SLL,TPP,"M"+Period()+"",0,0,Violet);
return(0); }
//+------------------------------------------------------------------+
void sellme(){
if (TP==0) { TPP=0; } if(TP>0) { TPP=Bid-(TP*Point); }
if (SL==0) { SLL=0; } if(SL>0) { SLL=Bid+(SL*Point); }
OrderSend(Symbol(),OP_SELL,LotMM,Bid,2,SLL,TPP,"M"+Period()+"",0,0,GreenYellow);
return(0); }
//+------------------------------------------------------------------+
//平倉持有的買單 由MT4_EA_制作速成班学员asp_win提供
void closebuy()
{
if(s+b==1
&& ma5nowma21now
);
}
//+------------------------------------------------------------------+
void xianshi()
{
string name_8 = "xianshi1";
ObjectDelete(name_8);
ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_8, "伺服器时间::"+TimeToStr(CurTime( ))+"", 13, "Arial", White);
ObjectSet(name_8, OBJPROP_CORNER, 0);
ObjectSet(name_8, OBJPROP_XDISTANCE, 200);
ObjectSet(name_8, OBJPROP_YDISTANCE, 5);
text="EA制作速成班";
name_8 = "xianshi2";
ObjectDelete(name_8);
ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_8, ""+text+"", 15, "Arial", Yellow);
ObjectSet(name_8, OBJPROP_CORNER, 1);
ObjectSet(name_8, OBJPROP_XDISTANCE, 15);
ObjectSet(name_8, OBJPROP_YDISTANCE, 5);
name_8 = "Lableyeddrice1";
ObjectDelete(name_8);
ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_8, "M"+Period()+" 货币 "+Symbol()+"", 10, "Arial", Silver);
ObjectSet(name_8, OBJPROP_CORNER, 1);
ObjectSet(name_8, OBJPROP_XDISTANCE, 130);
ObjectSet(name_8, OBJPROP_YDISTANCE, 32);
//////这个显示上方
name_8 = "LableCurPrice2";
ObjectDelete(name_8);
ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_8,""+DoubleToStr(Ask, Digits)+"::买上", 15, "Arial", Lime);
ObjectSet(name_8, OBJPROP_CORNER, 1);
ObjectSet(name_8, OBJPROP_XDISTANCE, 15);
ObjectSet(name_8, OBJPROP_YDISTANCE, 30);
//////这个显示下方
name_8 = "Lab345rPrice3";
ObjectDelete(name_8);
ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_8,""+DoubleToStr(Bid, Digits)+"::卖下", 15, "Arial", Lime);
ObjectSet(name_8, OBJPROP_CORNER, 1);
ObjectSet(name_8, OBJPROP_XDISTANCE, 15);
ObjectSet(name_8, OBJPROP_YDISTANCE, 50);
name_8 = "Acc87lance";
ObjectDelete(name_8);
ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_8,""+DoubleToStr( AccountBalance(), 2)+"::账面资金", 13, "Arial", Lime);
ObjectSet(name_8, OBJPROP_CORNER, 1);
ObjectSet(name_8, OBJPROP_XDISTANCE, 15);
ObjectSet(name_8, OBJPROP_YDISTANCE, 70);
name_8 = "LableC5rice6";
ObjectDelete(name_8);
ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_8,""+DoubleToStr( AccountEquity(), 2)+"::净值资金", 13, "Arial", Lime);
ObjectSet(name_8, OBJPROP_CORNER, 1);
ObjectSet(name_8, OBJPROP_XDISTANCE, 15);
ObjectSet(name_8, OBJPROP_YDISTANCE, 90);
name_8 = "Labl456rice6";
ObjectDelete(name_8);
ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_8,""+DoubleToStr( AccountMargin(), 2)+"::保证资金", 13, "Arial", Lime);
ObjectSet(name_8, OBJPROP_CORNER, 1);
ObjectSet(name_8, OBJPROP_XDISTANCE, 15);
ObjectSet(name_8, OBJPROP_YDISTANCE, 110);
name_8 = "Labl4hcjce6";
ObjectDelete(name_8);
ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_8,""+DoubleToStr( AccountFreeMargin(), 2)+"::可用资金", 13, "Arial", Lime);
ObjectSet(name_8, OBJPROP_CORNER, 1);
ObjectSet(name_8, OBJPROP_XDISTANCE, 15);
ObjectSet(name_8, OBJPROP_YDISTANCE, 130);
name_8 = "Accvf7lance";
ObjectDelete(name_8);
ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_8,""+DoubleToStr( AccountProfit(), 2)+"::账面盈亏", 13, "Arial", Lime);
ObjectSet(name_8, OBJPROP_CORNER, 1);
ObjectSet(name_8, OBJPROP_XDISTANCE, 15);
ObjectSet(name_8, OBJPROP_YDISTANCE, 150);
//我们可以无限的加
}
//+------------------------------------------------------------------+
///////////////////////
void TrailingStop()
{
for(cnt=OrdersTotal();cnt>=0;cnt--)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() == Symbol() )//&& OrderMagicNumber()==MAGICMA)
{
if (OrderType()==OP_SELL)
{
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
if (OrderType()==OP_BUY)
{
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()
| //+------------------------------------------------------------------+ #property copyright "MT4_EA_制作速成班模板" #property link "http://www.MT4_EA_制作速成班模板.net" //////////////////////// extern string _资金管理_ ="任选一个"; extern bool zijiguanli1= true;//false true、、 extern bool zijiguanli2= false;//false true、、 extern bool zijiguanli3= false;//false true、、 /////////////////////////////////// extern double cheng=1; double aa=0; int s=0,b=0,i; double CurrentBasket=0; double LotMM=0; double lotstart=0; double LotsMax=100; extern double lotab=0.1; double lots=0; double TP=200,TPP=0,SL=60,SLL=0; int slip=6; ////////////////////////////////// double mode=0; double LastOrderType; double LastPricesell; double LastPricebuy; double LastPrice; double OpenSells; double OpenSellStops; double OpenBuys; double OpenBuyStops; double SLauto; double Stoploss; /////////////////////////////// int cnt; extern int TrailingStop=40; /////////////////////////////// string text=""; //////////////////////// extern double macd12_1=12, macd12_2=26, macd12_3=9; double macd12now; extern double ma1=1,ma5=5,ma21=21,ma55=55,ma89=89; double ma1now,ma5now,ma21now,ma55now,ma89now; extern double adx14=14; double adx14now; //////////////////////////// double BaoZhenJing; ////////////////////////////// int panduan; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- jiancha();//检查判断 资金管理(); macd指标管理(); ma指标管理(); adx指标管理(); zhangchang();//战场管理 xianshi();//显示管理 TrailingStop();//移动止赢 //---- return(0); } //+------------------------------------------------------------------+ void jiancha() { b=0;s=0; for (int cnt=0; cnt<=OrdersTotal(); cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol()==Symbol() ) { mode=OrderType();LastOrderType=OrderType(); if (OrderType() == OP_SELL){ s++; LastPricesell=OrderOpenPrice();} if (OrderType() == OP_BUY ){ b++; LastPricebuy=OrderOpenPrice();} LastPrice=OrderOpenPrice(); if (OrderType()==OP_SELL) {OpenSells++;} if (OrderType()==OP_SELLSTOP) {OpenSellStops++;} if (OrderType()==OP_BUY) {OpenBuys++;} if (OrderType()==OP_BUYSTOP) {OpenBuyStops++;} } } }//end jiancha //+------------------------------------------------------------------+ void 资金管理() { lotstart=(AccountBalance()*lotab/10000); lots=lotstart; if(cheng==0){cheng=1;} CurrentBasket=AccountEquity()-AccountBalance(); ///////////////////////////////////////////////////////////////// if(zijiguanli1){ LotMM = lots;} ///////////////////////////////////////////////////////////////// if(zijiguanli2){ if(CurrentBasket<0 ) {LotMM=NormalizeDouble(lots*(OrdersTotal()*cheng)+lotstart,2); } if(CurrentBasket==0 ) {LotMM=NormalizeDouble(LotMM*0,2); } } ///////////////////////////////////////////////////////////////// if(zijiguanli3){ if(s+b==0){aa=1;} if(s+b==1){aa=3;} if(s+b==2){aa=7;} if(s+b==3){aa=11;} if(s+b==4){aa=20;} if(s+b==5){aa=31;} if(s+b==6){aa=42;} if(s+b==7){aa=54;} if(s+b==8){aa=66;} if(s+b==9){aa=76;} if(s+b>=10){aa=66;} if(CurrentBasket<0 ) {LotMM=NormalizeDouble(lotstart*aa,2); } if(CurrentBasket==0 ) {LotMM=NormalizeDouble(LotMM*0,2); } } ///////////////////////////////////////////////////////////////// if(LotMM
2008-05-20 08:23