/* +--------+ |Shell | +--------+ Please rename this program to something like [ea]xxxxxx_yyyyyy__vzz_MT4.mq4 xxxxxx = your EA's name yyyyyy = your name (so we know your mods from everyone else) vzz = your version number (01, 02, 03...99) so we know what is the latest Change the comments throughout to reflect your scheme Theory of operation (Put information about your scheme here) TIME FRAME ========== (what time frame is best for your scheme) PAIRS ===== (Are there any specific pairs) ENTRY LONG ========== (How are you deciding to Ask/Buy/Long) ENTRY SHORT =========== (How are you deciding to Bid/Sell/Short) EXIT ==== (How do you get out of a trade, supposedly with profit) MONEY MANAGEMENT ================ (Do you have a money management scheme) RISK MANAGEMENT =============== (do you have a risk management scheme) FAILURE MANAGEMENT ================== GetLastError on every transaction VERSION HISTORY =============== 00 - initial concept 01 - */ // variables declared here are GLOBAL in scope #property copyright "Ron Thompson" #property link "http://www.lightpatch.com/forex" // user input extern double Lots=0.1; // how many lots to trade at a time extern int Slippage=2; // how many pips of slippage can you tolorate extern double ProfitMade=34; // how much money do you expect to make extern double LossLimit=45; // how much loss can you tolorate extern double 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 trades extern int StopHour=24; // your local time to stop making trades extern int BasketProfit=9999; // if equity reaches this level, close trades extern int BasketLoss=9999; // if equity reaches this negative level, close trades // naming and numbering int MagicNumber = 200601182020; // allows multiple experts to trade on same account string TradeComment = "Shell_00_"; // comment so multiple EAs can be seen in Account History // Bar handling datetime bartime=0; // used to determine when a bar has moved int bartick=0; // number of times bars have moved int objtick=0; // used to draw objects on the chart // Trade control bool TradeAllowed=true; // used to manage trades // Min/Max tracking double maxOrders; double maxEquity; double minEquity; //+-------------+ //| Custom init | //|-------------+ // Called ONCE when EA is added to chart or recompiled int init() { int i; string o; //remove the old objects for(i=0; i=StartHour && Hour()<=StopHour) { TradeAllowed=true; } } OrdersPerSymbol=0; for(cnt=OrdersTotal();cnt>=0;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) maxOrders=OrdersPerSymbol; //TradeBars = MathFloor(CurTime() - OrderOpenTime())/60/Period(); // TradeAllowed on close keeps from closing 'just opened' orders //if( OrdersPerSymbol>0 && (x2buy || x2sell) && TradeAllowed ) // { // // crossover, so close orders // for(cnt=0;cnt=0;i--) { OrderSelect(i, SELECT_BY_POS); myAsk=MarketInfo(OrderSymbol(),MODE_ASK); myBid=MarketInfo(OrderSymbol(),MODE_BID); myTkt=OrderTicket(); myLot=OrderLots(); switch( OrderType() ) { //Close opened long positions case OP_BUY :result = OrderClose(myTkt, myLot, myBid, Slippage, Red); break; //Close opened short positions case OP_SELL :result = OrderClose(myTkt, myLot, myAsk, Slippage, Red); break; } if(result == false) { Alert("Order " , myTkt , " failed to close. Error:" , GetLastError() ); Print("Order " , myTkt , " failed to close. Error:" , GetLastError() ); Sleep(3000); } } //for } // closeopenorders double Divergence(int Fast_Period, int Slow_Period, int Fast_Price, int Slow_Price, int mypos) { // Simple moving average divergence // Tried HMA and it didn't work well AT ALL! double maF1, maF2, maS1, maS2; double dv1, dv2, rtn; maF1=iMA(Symbol(),0,Fast_Period,0,MODE_SMA,Fast_Price,mypos); maS1=iMA(Symbol(),0,Slow_Period,0,MODE_SMA,Slow_Price,mypos); dv1=(maF1-maS1); maF2=iMA(Symbol(),0,Fast_Period,0,MODE_SMA,Fast_Price,mypos+1); maS2=iMA(Symbol(),0,Slow_Period,0,MODE_SMA,Slow_Price,mypos+1); dv2=((maF1-maS1)-(maF2-maS2)); // dynamic around Close(0) rtn=(dv1-dv2); return(rtn); } /* 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_ASK); double myBid = MarketInfo(currency, MODE_BID); double myPoint = MarketInfo(currency, MODE_POINT); //Ask(buy, long) if (BuySell=="BUY") { if(LL==0) mySL=0; else mySL=myAsk-(LL*myPoint); if(PM==0) myTP=0; else myTP=myAsk+(PM*myPoint); OrderSend(currency,OP_BUY,Lots,myAsk,Slippage,mySL,myTP,TradeComment,MagicNumber,White); gle=GetLastError(); if(gle==0) { Print("----Place Order Symbol=",currency," StopLoss=",mySL," TakeProfit=",myTP," Ask=",myAsk); return(0); } else { Print("----ERROR----",gle," Symbol=",currency," error=",gle," StopLoss=",mySL," TakeProfit=",myTP," Ask=",myAsk); return(gle); } } //Bid (sell, short) if (BuySell=="SELL") { if(LL==0) mySL=0; else mySL=myBid+(LossLimit*myPoint); if(PM==0) myTP=0; else myTP=myBid-(ProfitMade*myPoint); OrderSend(currency,OP_SELL,Lots,myBid,Slippage,mySL,myTP,TradeComment,MagicNumber,White); gle=GetLastError(); if(gle==0) { Print("----Place Order Symbol=",currency," StopLoss=",mySL," TakeProfit=",myTP," Bid=",myBid); } else { Print("----ERROR----",gle," Symbol=",currency," StopLoss=",mySL," TakeProfit=",myTP," Bid=",myBid); } } }//PlaceOrder */ void logwrite (string filename, string mydata) { int myhandle; myhandle=FileOpen(filename, FILE_CSV|FILE_WRITE|FILE_READ, ";"); if(myhandle>0) { FileSeek(myhandle,0,SEEK_END); FileWrite(myhandle, mydata); FileClose(myhandle); } }