版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、利用均線間隔距離來進行交易的系統(tǒng)(據(jù)說價格300歐元)/ user in putexter n double Lots=0.1;/ how many lots to trade at a timeextern intSlippage=2;/ how many pips of slippage can you tolorateextern intFast_TimeFrame=0;extern intFast_Period=28;extern intFast_Price = PRICE_OPEN;extern intFast_Mode = MODE_SMA;extern intFast_Shift
2、=0;extern intSlow_TimeFrame=0;extern intSlow_Period=73;extern intSlow_Price = PRICE_OPEN;extern intSlow_Mode = MODE_SMA;extern intSlow_Shift=0;extern double DVBuySell=0.002;extern intMAXTrades=5;/ nu mber of trades to have ope n at onceexter n double ProfitMade=100;/ how much money do you expect to
3、makeexter n double LossLimit=72;/ how much loss can you tolorateextern intTrailStop=999;/ traili ng stop (999=no traili ng stop)extern int PLBreakEven=999;made (999=off)extern int StartHour=0;/ your local time to start mak ing tradesexter n intStopHour=24;/ your local time to stop mak ing tradesexte
4、rn int BasketProfit=9999;/ if equity reaches this level, close tradesextern int BasketLoss=9999;/ if equity reaches this n egative level, close/ set break even when this many pips aretrades/ naming and nu mberi ngintMagicNumber = 200601182020; / allows multiple experts to trade on same acco untstri
5、ngTradeComme nt = "2MA_Diverge nceTrader_04_"/ used to determ ine whe n a bar has moved/ Bar han dli ng datetime bartime=0;intbartick=0;intobjtick=0;inttickco un t=0;/ nu mber of times bars have moved/ used to draw objects on the chart/ Trade con trol/ used to man age tradesbool TradeAllow
6、ed=true;/ Mi n/Max tracki ngdouble maxOrders;double maxEquity;double min Equity;double CECou nt;double CEProc;double CEBuy;double CESell;/+| Custom in it |ll+/ Called ONCE whe n EA is added to chart or recompiled int init()int i;stri ng o;/remove the old objectsfor(i=0; i<Bars; i+)o=DoubleT oStr(
7、i,0);ObjectDelete("myx"+o);ObjectDelete("myz"+o);objtick=0;Prin t("l nit happe ned ”,CurTime();Comme nt(” ");/+| Custom DE-i nit |/+/ Called ONCE whe n EA is removed from chart int dein it()int i;stri ng o;/remove the old objectsfor(i=0; i<Bars; i+)o=DoubleT oStr(i,0
8、);ObjectDelete("myx"+o);ObjectDelete("myz"+o);objtick=0;Prin t("MAX number of orders ”,maxOrders);Prin t("MAX equity”,maxEquity);Prin t("MIN equity",mi nEquity);Prin t("Close Everyth ing",CECou nt);Prin t("Close Proc”,CEProc);Prin t("Proc B
9、uy”,CEBuy);Prin t("Proc Sell”,CESell);Print("DE-Init happened ”,CurTime();Comme nt(” ");/+| Ma in|/+/ Called EACH TICK and each Bar int start()double p=Po in t();double spread=Ask-Bid;intcn t=0;intgle=0;intOrdersPerSymbol=0;intOrdersBUY=0;intOrdersSELL=0;intiFileHa ndle;/ stoploss and
10、 takeprofit and close control double SL=0;double TP=0;double Curre ntProfit=0;double Curren tBasket=0;/ directi on con trolbool BUYme=false;bool SELLme=false;/ Trade stuff double diverge;/ bar counting if(bartime!=TimeO)bartime=TimeO;bartick+;objtick+;TradeAllowed=true;Prin t("Bartick=",ba
11、rtick);OrdersPerSymbol=0;for(cnt=OrdersT otal();cnt>=O;cnt-)OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);if( OrderSymbol()=Symbol() && OrderMagicNumber()=MagicNumber)OrdersPerSymbol+;if(OrderType()=OP_BUY) OrdersBUY+; if(OrderType()=OP_SELL)OrdersSELL+;if(OrdersPerSymbol>maxOrders) max
12、Orders=OrdersPerSymbol;/+| In sert your in dicator here| And set either BUYme or| SELLme true to place orders | /+ diverge=diverge nce(O);Comme nt("Curre nt Diverge nee = ”,diverge);if( diverge>=DVBuySell )BUYme=true;if( diverge<=(DVBuySell*(-1) SELLme=true;/+/| End In sert |/+/ENTRY LONG
13、 (buy, Ask) if(OrdersPerSymbol<=MAXTrades && TradeAllowed && BUYme)/Ask(buy, lo ng)if(LossLimit =0) SL=0; else SL=Ask-(LossLimit+7)*Poi nt();if(ProfitMade=0) TP=0; else TP=Ask+(ProfitMade+7)*Point();OrderSe nd(Symbol(),OP_BUY,Lots,Ask,Slippage,SL,TP ,TradeComme nt,MagicNumber,Whit
14、 e);gle=GetLastError();if(gle=0)Prin t("BUYAsk=",Ask," bartick=",bartick);ObjectCreate("myx"+DoubleToStr(objtick,0),OBJ_TEXT, 0, TimeO,High0+(5*p);ObjectSetText("myx"+DoubleToStr(objtick,0),"B",15,"Arial",Red);bartick=0;TradeAllowed=false;e
15、lsePrint("-ERROR- BUYAsk=",Ask," error=",gle," bartick=",bartick);/ENTRY SHORT (sell, Bid)if(OrdersPerSymbol<=MAXTrades && TradeAllowed && SELLme )/Bid (sell, short)if(LossLimit =0) SL=0; else SL=Bid+(LossLimit+7)*Poi nt(); if(ProfitMade=0) TP=0; else
16、 TP=Bid-(ProfitMade+7)*Poi nt();OrderSe nd(Symbol(),OP_SELL,Lots,Bid,Slippage,SL,TP ,TradeComme nt,MagicNumber,Red);gle=GetLastError();if(gle=O)Prin t("SELL Bid=",Bid," bartick=",bartick);Time0,ObjectCreate("myx"+DoubleToStr(objtick,0),OBJ_TEXT, 0,High0+(5*p);ObjectSetT
17、ext("myx"+DoubleToStr(objtick,0),"S",15,"Arial",Red);bartick=0;TradeAllowed=false;elsePrint("-ERROR- SELL Bid=",Bid," error=",gle," bartick=",bartick);/Basket profit or lossCurren tBasket=Acco un tEquity()-Acco un tBala nce();if(Curre ntBas
18、ket>maxEquity) maxEquity=Curre ntBasket;if(Curre ntBasket<mi nEquity) min Equity=Curre ntBasket;if( CurrentBasket>=BasketProfit | CurrentBasket<=(BasketLoss*(-1)CloseEverythi ng();CECou nt+;/ CLOSE order if profit target made for(c nt=0;c nt<OrdersTotal();c nt+)OrderSelect(cnt, SELECT
19、_BY_POS, MODE_TRADES);if( OrderSymbol()=Symbol() && OrderMagicNumber()=MagicNumber )if(OrderType()=OP_BUY)Curre ntProfit=Bid-OrderOpe nPrice();/ modify for break even>=PLBreakEve n*p&&if(Curre ntProfitOrderOpe nPrice()>OrderStopLoss()SL=OrderOpe nPrice()+(spread*2);TP=OrderTake
20、Profit();OrderModify(OrderTicket(),OrderOpe nPrice(),SL,TP, White);gle=GetLastError();if(gle=0)Prin t("MODIFY BREAKEVEN BUY Bid=",Bid," bartick=",bartick);ObjectCreate("myz"+DoubleToStr(objtick,0),OBJ_TEXT, 0, TimeO,Low0-(7*p);ObjectSetText("myz"+DoubleT oStr(
21、objtick,0),"BE",15,"Arial",White);elsePrint("-ERROR-MODIFY BREAKEVEN BUY Bid=",Bid,"error=",gle," bartick=",bartick);/ modify for trailing stopif(Curre ntProfit >= TrailStop*p )SL=Bid-(TrailStop*p);TP=OrderTakeProfit();OrderModify(OrderTicket(),Or
22、derOpe nPrice(),SL,TP, White);gle=GetLastError();if(gle=0)Print ("MODIFY TRAILSTOP BUYStopLoss=",SL," bartick=",bartick,"OrderTicket=",OrderTicket()," CurrProfit=",Curre ntProfit);ObjectCreate("myz"+DoubleToStr(objtick,0),OBJ_TEXT, 0, Time0,Low0-(7*p
23、);ObjectSetText("myz"+DoubleT oStr(objtick,0),"TS",15,"Arial",White);elsePrint("-ERROR-MODIFY TRAILSTOP BUY Bid=",Bid,"error=",gle," bartick=",bartick);/ did we make our desired BUY profit/ or did we hit the BUY LossLimitif(Curre ntProfit&g
24、t;=(ProfitMade*p) | Curre ntProfit<=(LossLimit*(-1)*p)OrderClose(OrderTicket(),Lots,Bid,Slippage,White);gle=GetLastError();if(gle=0)Prin t("CLOSE BUY Bid=",Bid," bartick=",bartick);ObjectCreate("myz"+DoubleToStr(objtick,0),OBJ_TEXT, 0, Time0,Low0-(7*p);ObjectSetText(
25、"myz"+DoubleT oStr(objtick,0),"C",15,"Arial",White);elsePrint("-ERROR-CLOSE BUY Bid=",Bid,"bartick=",bartick); / if BUYif(OrderType()=OP_SELL)Curre ntProfit=OrderOpe nPrice()-Ask;/ modify for break evenif(Curre ntProfit>=PLBreakEve n*pOrderOpe nPr
26、ice()<OrderStopLoss()SL=OrderOpe nPrice()-(spread*2);TP=OrderTakeProfit();error=",gle,"&&OrderModify(OrderTicket(),OrderOpe nPrice(),SL,TP, Red);gle=GetLastError();if(gle=O)Print("MODIFY BREAKEVEN SELL Ask=",Ask," bartick=",bartick);ObjectCreate("myz&quo
27、t;+DoubleToStr(objtick,0),OBJ_TEXT, 0, TimeO,Low0-(7*p);ObjectSetText("myz"+DoubleT oStr(objtick,0),"BE",15,"Arial",Red);elsePrint("-ERROR-MODIFY BREAKEVEN SELL Ask=",Ask,"error=",gle," bartick=",bartick);/ modify for trailing stopif(Curre
28、ntProfit >= TrailStop*p)SL=Ask+(TrailStop*p);TP=OrderTakeProfit();OrderModify(OrderTicket(),OrderOpe nPrice(),SL,TP , Red);gle=GetLastError();if(gle=0)Print ("MODIFY TRAILSTOP SELL StopLoss=",SL," bartick=",bartick,"OrderTicket=",OrderTicket()," CurrProfit="
29、;,Curre ntProfit);ObjectCreate("myz"+DoubleToStr(objtick,0),OBJ_TEXT, 0, Time0,Low0-(7*p);ObjectSetText("myz"+DoubleT oStr(objtick,0),"TS",15,"Arial",Red);elsePrint("-ERROR-MODIFY TRAILSTOP SELL Ask=",Ask,"error=",gle," bartick=",
30、bartick);/ did we make our desired SELL profit?if( Curre ntProfit>=(ProfitMade*p) | Curre ntProfit<=(LossLimit*(-1)*p)OrderClose(OrderTicket(),Lots,Ask,Slippage,Red);gle=GetLastError();if(gle=0)Prin t("CLOSE SELL Ask=",Ask," bartick=",bartick);ObjectCreate("myz"+D
31、oubleToStr(objtick,0),OBJ_TEXT, 0, Time0,Low0-(7*p);ObjectSetText("myz"+DoubleT oStr(objtick,0),"C",15,"Arial",Red);elsePrint("-ERROR-CLOSE SELL Ask=",Ask," error=",gle,"bartick=",bartick); /if SELL / if(OrderSymbol) / for / start()/+| Clos
32、eEverythi ng |/+/ Closes all OPEN and PENDING orders int CloseEverythi ng()double myAsk;double myBid;intmyTkt;double myLot;intmyTyp;int i;bool result = false;for(i=OrdersTotal();i>=0;i-)OrderSelect(i, SELECT_BY_POS);myAsk=Marketl nfo(OrderSymbol(),MODE_ASK);myBid=Marketl nfo(OrderSymbol(),MODE_BI
33、D);myTkt=OrderTicket();myLot=OrderLots();myTyp=OrderType();switch( myTyp )/Close ope ned long positi onscase OP_BUY:result = OrderClose(myTkt, myLot, myBid, Slippage, Red);CEBuy+;break;/Close ope ned short positi onscase OP_SELL:result = OrderClose(myTkt, myLot, myAsk, Slippage, Red);CESell+;break;/
34、Close pending orderscase OP_BUYLIMIT :case OP_BUYSTOP :case OP_SELLLIMIT:case OP_SELLSTOP :result = OrderDelete( OrderTicket();if(result = false)Alert("Order " , myTkt , " failed to close. Error:" , GetLastError();Prin t("Order " , myTkt , " failed to close. Error:
35、" , GetLastError();Sleep(3000);Sleep(1000);CEProc+; /for / closeeveryth ingdouble diverge nce(i nt mypos)int i;double maF1, maF2, maS1, maS2;double dv1, dv2;maF 仁 iMA(Symbol(),Fast_TimeFrame,Fast_Period,Fast_Shift,Fast_Mode,Fast_Price,mypos)5maS仁iMA(Symbol(),Slow_TimeFrame,Slow_Period,Slow_Shif
36、t,Slow_Mode,Slow_Price,mypos);dv仁(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,my pos+1);dv2=(maF1-maS1)-(maF2-maS2);return(dv1-dv2);/*int PlaceOrder(string currency, stri
37、ng BuySell, int PM, int LL)/ Retur ns GetLastError nu mber/ you can call with ProfitMade or LossLimit set to/ zero, and none will be set whe n order is placedint gle=0;/ GetLastError nu mberdouble mySL;/ locally gen erated SLdouble myTP;/ locally gen erated TPdouble myAsk = Market In fo(curre ncy, MODE_ASK);double myBid =
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 船舶強度課程設(shè)計
- 二零二五年度抗滑樁施工信息化管理系統(tǒng)合同2篇
- 二零二五年度寵物店轉(zhuǎn)讓及租賃合同3篇
- 燃氣管道巡線員管理制度模版(2篇)
- 課程設(shè)計無線充電電動車
- 二零二五年度應(yīng)急物資儲備與責任落實合同3篇
- 食品安全宣傳周方案模版(2篇)
- 二零二五年度汽車尾氣排放檢測與治理委托合同范本3篇
- 二零二五年度個人股權(quán)轉(zhuǎn)讓與公司合并重組協(xié)議范本3篇
- 二零二五年圖書館室內(nèi)裝飾合同2篇
- 瑤醫(yī)目診圖-望面診病現(xiàn)用圖解-目診
- 2022年四級反射療法師考試題庫(含答案)
- 新《安全生產(chǎn)法》培訓測試題
- 政務(wù)禮儀-PPT課件
- 特種涂料類型——耐核輻射涂料的研究
- 化工裝置常用英語詞匯對照
- 物資采購管理流程圖
- 無牙頜解剖標志
- 標準《大跨徑混凝土橋梁的試驗方法》
- 格拉斯哥昏迷評分(GCS)--表格-改良自用
- ISO9001記錄保存年限一覽表
評論
0/150
提交評論