利用均線間隔距離來進(jìn)行交易的系統(tǒng)_第1頁
利用均線間隔距離來進(jìn)行交易的系統(tǒng)_第2頁
利用均線間隔距離來進(jìn)行交易的系統(tǒng)_第3頁
利用均線間隔距離來進(jìn)行交易的系統(tǒng)_第4頁
利用均線間隔距離來進(jìn)行交易的系統(tǒng)_第5頁
已閱讀5頁,還剩7頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、利用均線間隔距離來進(jìn)行交易的系統(tǒng)(據(jù)說價(jià)格300歐元)/ user inputextern double Lots=0.1; / how many lots to trade at a time extern int Slippage=2; / how many pips of slippage can you tolorateextern int Fast_TimeFrame=0;extern int Fast_Period=28;extern int Fast_Price = PRICE_OPEN;extern int Fast_Mode = MODE_SMA;extern int Fas

2、t_Shift=0;extern int Slow_TimeFrame=0;extern int Slow_Period=73;extern int Slow_Price = PRICE_OPEN;extern int Slow_Mode = MODE_SMA;extern int Slow_Shift=0;extern double DVBuySell=0.002;extern int MAXTrades=5; / number of trades to have open at onceextern double ProfitMade=100; / how much money do yo

3、u expect to makeextern double LossLimit=72; / how much loss can you tolorateextern int TrailStop=999; / trailing stop (999=no trailing stop)extern int PLBreakEven=999; / set break even when this many pips are made (999=off)extern int StartHour=0; / your local time to start making tradesextern int St

4、opHour=24; / your local time to stop making tradesextern int BasketProfit=9999; / if equity reaches this level, close tradesextern int BasketLoss=9999; / if equity reaches this negative level, close trades/ naming and numberingint MagicNumber = 200601182020; / allows multiple experts to trade on sam

5、e accountstring TradeComment = "2MA_DivergenceTrader_04_"/ Bar handlingdatetime bartime=0; / used to determine when a bar has movedint bartick=0; / number of times bars have movedint objtick=0; / used to draw objects on the chartint tickcount=0;/ Trade controlbool TradeAllowed=true; / used

6、 to manage trades/ Min/Max trackingdouble maxOrders;double maxEquity;double minEquity;double CECount;double CEProc;double CEBuy;double CESell;/+-+/| Custom init |/|-+/ Called ONCE when EA is added to chart or recompiledint init() int i; string o; /remove the old objects for(i=0; i<Bars; i+) o=Dou

7、bleToStr(i,0); ObjectDelete("myx"+o); ObjectDelete("myz"+o); objtick=0; Print("Init happened ",CurTime(); Comment(" "); /+-+/| Custom DE-init |/+-+/ Called ONCE when EA is removed from chartint deinit() int i; string o; /remove the old objects for(i=0; i<Ba

8、rs; i+) o=DoubleToStr(i,0); ObjectDelete("myx"+o); ObjectDelete("myz"+o); objtick=0; Print("MAX number of orders ",maxOrders); Print("MAX equity ",maxEquity); Print("MIN equity ",minEquity); Print("Close Everything ",CECount); Print("C

9、lose Proc ",CEProc); Print("Proc Buy ",CEBuy); Print("Proc Sell ",CESell); Print("DE-Init happened ",CurTime(); Comment(" "); /+-+/| Main |/+-+/ Called EACH TICK and each Barint start() double p=Point(); double spread=Ask-Bid; int cnt=0; int gle=0; int Or

10、dersPerSymbol=0; int OrdersBUY=0; int OrdersSELL=0; int iFileHandle; / stoploss and takeprofit and close control double SL=0; double TP=0; double CurrentProfit=0; double CurrentBasket=0; / direction control bool BUYme=false; bool SELLme=false; / Trade stuff double diverge; / bar counting if(bartime!

11、=Time0) bartime=Time0; bartick+; objtick+; TradeAllowed=true; Print("Bartick=",bartick); OrdersPerSymbol=0; for(cnt=OrdersTotal();cnt>=0;cnt-) OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if( OrderSymbol()=Symbol() && OrderMagicNumber()=MagicNumber) OrdersPerSymbol+; if(OrderTy

12、pe()=OP_BUY) OrdersBUY+; if(OrderType()=OP_SELL)OrdersSELL+; if(OrdersPerSymbol>maxOrders) maxOrders=OrdersPerSymbol; /+-+ /| Insert your indicator here | /| And set either BUYme or | /| SELLme true to place orders | /+-+ diverge=divergence(0); Comment("Current Divergence = ",diverge);

13、if( diverge>=DVBuySell ) BUYme=true; if( diverge<=(DVBuySell*(-1) ) SELLme=true; /+-+ /| End Insert | /+-+ /ENTRY LONG (buy, Ask) if(OrdersPerSymbol<=MAXTrades && TradeAllowed && BUYme) /Ask(buy, long) if(LossLimit =0) SL=0; else SL=Ask-(LossLimit+7)*Point() ); if(ProfitMade

14、=0) TP=0; else TP=Ask+(ProfitMade+7)*Point() ); OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,SL,TP,TradeComment,MagicNumber,White); gle=GetLastError(); if(gle=0) Print("BUY Ask=",Ask," bartick=",bartick); ObjectCreate("myx"+DoubleToStr(objtick,0), OBJ_TEXT, 0, Time0, Hig

15、h0+(5*p); ObjectSetText("myx"+DoubleToStr(objtick,0),"B",15,"Arial",Red); bartick=0; TradeAllowed=false; else Print("-ERROR- BUY Ask=",Ask," error=",gle," bartick=",bartick); /ENTRY SHORT (sell, Bid) if(OrdersPerSymbol<=MAXTrades &&a

16、mp; TradeAllowed && SELLme ) /Bid (sell, short) if(LossLimit =0) SL=0; else SL=Bid+(LossLimit+7)*Point() ); if(ProfitMade=0) TP=0; else TP=Bid-(ProfitMade+7)*Point() ); OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,SL,TP,TradeComment,MagicNumber,Red); gle=GetLastError(); if(gle=0) Print("

17、;SELL Bid=",Bid," bartick=",bartick); ObjectCreate("myx"+DoubleToStr(objtick,0), OBJ_TEXT, 0, Time0, High0+(5*p); ObjectSetText("myx"+DoubleToStr(objtick,0),"S",15,"Arial",Red); bartick=0; TradeAllowed=false; else Print("-ERROR- SELL Bid=&q

18、uot;,Bid," error=",gle," bartick=",bartick); /Basket profit or loss CurrentBasket=AccountEquity()-AccountBalance(); if(CurrentBasket>maxEquity) maxEquity=CurrentBasket; if(CurrentBasket<minEquity) minEquity=CurrentBasket; if( CurrentBasket>=BasketProfit | CurrentBasket&l

19、t;=(BasketLoss*(-1) ) CloseEverything(); CECount+; / CLOSE order if profit target made for(cnt=0;cnt<OrdersTotal();cnt+) OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if( OrderSymbol()=Symbol() && OrderMagicNumber()=MagicNumber ) if(OrderType()=OP_BUY) CurrentProfit=Bid-OrderOpenPrice() ;

20、 / modify for break even if (CurrentProfit >= PLBreakEven*p && OrderOpenPrice()>OrderStopLoss() SL=OrderOpenPrice()+(spread*2); TP=OrderTakeProfit(); OrderModify(OrderTicket(),OrderOpenPrice(),SL,TP, White); gle=GetLastError(); if(gle=0) Print("MODIFY BREAKEVEN BUY Bid=",Bid,

21、" bartick=",bartick); ObjectCreate("myz"+DoubleToStr(objtick,0), OBJ_TEXT, 0, Time0, Low0-(7*p); ObjectSetText("myz"+DoubleToStr(objtick,0),"BE",15,"Arial",White); else Print("-ERROR- MODIFY BREAKEVEN BUY Bid=",Bid," error=",gle,&

22、quot; bartick=",bartick); / modify for trailing stop if(CurrentProfit >= TrailStop*p ) SL=Bid-(TrailStop*p); TP=OrderTakeProfit(); OrderModify(OrderTicket(),OrderOpenPrice(),SL,TP, White); gle=GetLastError(); if(gle=0) Print ("MODIFY TRAILSTOP BUY StopLoss=",SL," bartick="

23、;,bartick,"OrderTicket=",OrderTicket()," CurrProfit=",CurrentProfit); ObjectCreate("myz"+DoubleToStr(objtick,0), OBJ_TEXT, 0, Time0, Low0-(7*p); ObjectSetText("myz"+DoubleToStr(objtick,0),"TS",15,"Arial",White); else Print("-ERROR- MOD

24、IFY TRAILSTOP BUY Bid=",Bid," error=",gle," bartick=",bartick); / did we make our desired BUY profit / or did we hit the BUY LossLimit if(CurrentProfit>=(ProfitMade*p) | CurrentProfit<=(LossLimit*(-1)*p) ) OrderClose(OrderTicket(),Lots,Bid,Slippage,White); gle=GetLastE

25、rror(); if(gle=0) Print("CLOSE BUY Bid=",Bid," bartick=",bartick); ObjectCreate("myz"+DoubleToStr(objtick,0), OBJ_TEXT, 0, Time0, Low0-(7*p); ObjectSetText("myz"+DoubleToStr(objtick,0),"C",15,"Arial",White); else Print("-ERROR- CLOSE B

26、UY Bid=",Bid," error=",gle," bartick=",bartick); / if BUY if(OrderType()=OP_SELL) CurrentProfit=OrderOpenPrice()-Ask; / modify for break even if (CurrentProfit >= PLBreakEven*p && OrderOpenPrice()<OrderStopLoss() SL=OrderOpenPrice()-(spread*2); TP=OrderTakeProf

27、it(); OrderModify(OrderTicket(),OrderOpenPrice(),SL,TP, Red); gle=GetLastError(); if(gle=0) Print("MODIFY BREAKEVEN SELL Ask=",Ask," bartick=",bartick); ObjectCreate("myz"+DoubleToStr(objtick,0), OBJ_TEXT, 0, Time0, Low0-(7*p); ObjectSetText("myz"+DoubleToStr(

28、objtick,0),"BE",15,"Arial",Red); else Print("-ERROR- MODIFY BREAKEVEN SELL Ask=",Ask," error=",gle," bartick=",bartick); / modify for trailing stop if(CurrentProfit >= TrailStop*p) SL=Ask+(TrailStop*p); TP=OrderTakeProfit(); OrderModify(OrderTicke

29、t(),OrderOpenPrice(),SL,TP, Red); gle=GetLastError(); if(gle=0) Print ("MODIFY TRAILSTOP SELL StopLoss=",SL," bartick=",bartick,"OrderTicket=",OrderTicket()," CurrProfit=",CurrentProfit); ObjectCreate("myz"+DoubleToStr(objtick,0), OBJ_TEXT, 0, Time0,

30、 Low0-(7*p); ObjectSetText("myz"+DoubleToStr(objtick,0),"TS",15,"Arial",Red); else Print("-ERROR- MODIFY TRAILSTOP SELL Ask=",Ask," error=",gle," bartick=",bartick); / did we make our desired SELL profit? if( CurrentProfit>=(ProfitMade*p

31、) | CurrentProfit<=(LossLimit*(-1)*p) ) OrderClose(OrderTicket(),Lots,Ask,Slippage,Red); gle=GetLastError(); if(gle=0) Print("CLOSE SELL Ask=",Ask," bartick=",bartick); ObjectCreate("myz"+DoubleToStr(objtick,0), OBJ_TEXT, 0, Time0, Low0-(7*p); ObjectSetText("myz

32、"+DoubleToStr(objtick,0),"C",15,"Arial",Red); else Print("-ERROR- CLOSE SELL Ask=",Ask," error=",gle," bartick=",bartick); /if SELL / if(OrderSymbol) / for / start()/+-+/| CloseEverything |/+-+/ Closes all OPEN and PENDING ordersint CloseEveryth

33、ing() double myAsk; double myBid; int myTkt; double myLot; int myTyp; int i; bool result = false; for(i=OrdersTotal();i>=0;i-) OrderSelect(i, SELECT_BY_POS); myAsk=MarketInfo(OrderSymbol(),MODE_ASK); myBid=MarketInfo(OrderSymbol(),MODE_BID); myTkt=OrderTicket(); myLot=OrderLots(); myTyp=OrderType

34、(); switch( myTyp ) /Close opened long positions case OP_BUY :result = OrderClose(myTkt, myLot, myBid, Slippage, Red); CEBuy+; break; /Close opened short positions case OP_SELL :result = OrderClose(myTkt, myLot, myAsk, Slippage, Red); CESell+; break; /Close pending orders case OP_BUYLIMIT : case OP_

35、BUYSTOP : case OP_SELLLIMIT: case OP_SELLSTOP :result = OrderDelete( OrderTicket() ); if(result = false) Alert("Order " , myTkt , " failed to close. Error:" , GetLastError() ); Print("Order " , myTkt , " failed to close. Error:" , GetLastError() ); Sleep(3000)

36、; Sleep(1000); CEProc+; /for / closeeverythingdouble divergence(int mypos) int i; double maF1, maF2, maS1, maS2; double dv1, dv2; maF1=iMA(Symbol(),Fast_TimeFrame,Fast_Period,Fast_Shift,Fast_Mode,Fast_Price,mypos); maS1=iMA(Symbol(),Slow_TimeFrame,Slow_Period,Slow_Shift,Slow_Mode,Slow_Price,mypos);

37、dv1=(maF1-maS1); maF2=iMA(Symbol(),Fast_TimeFrame,Fast_Period,Fast_Shift,Fast_Mode,Fast_Price,mypos+1); maS2=iMA(Symbol(),Slow_TimeFrame,Slow_Period,Slow_Shift,Slow_Mode,Slow_Price,mypos+1); dv2=(maF1-maS1)-(maF2-maS2); return(dv1-dv2); /*int PlaceOrder(string currency, string BuySell, int PM, int LL) / Returns GetLastError number / you can call with ProfitMade or LossLimit set to / zero, and none will be set when order is placed int gle=0; / GetLastError number double mySL; / locally generated SL double myTP; / locally generated TP double myAsk = MarketInfo(currency, MODE

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論