//+------------------------------------------------------------------+ //| DZ_expCoin.mq4 | //| Dmitry Zhebrak aka Necron | //| http://fxgeneral.com/forum/ | //+------------------------------------------------------------------+ #property copyright "Dmitry Zhebrak aka Necron,© 2010" #property link "http://fxgeneral.com" extern double Profit=21; extern double Loss=21; extern double TrailingStop=0; extern double Lot=0.1; extern int Slippage=3; int Magic=20100327; extern bool show_number=false; int corner=3; int font_size=14; int label_size=2; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { tossing_up_a_coin(); CheckForClose(); //---- //---- return(0); } bool CheckExists() { bool Result = True; for(int i = 0; i < OrdersTotal(); i++) if(OrderSelect(i, SELECT_BY_POS)) if(OrderMagicNumber() == Magic && OrderSymbol() == Symbol()) if(OrderOpenTime() >= Time[0]) Result = False; for(i = 0; i < OrdersHistoryTotal(); i++) { if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) if(OrderOpenTime() >= Time[0] && OrderMagicNumber() == Magic && OrderSymbol() == Symbol()) Result = False; } return(Result); } void tossing_up_a_coin() { int limit=32766; int coin; bool orel,reshka; int ticket; MathSrand(TimeLocal()); for(int i=0;i0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice()); } else Print("Error opening BUY order : ",GetLastError()); return(0); } if(orel && CheckExists() && OrdersTotal()==0) { ticket=OrderSend(Symbol(),OP_SELL,Lot,NormalizeDouble(Ask,Digits),Slippage,0,0,"expCoin",Magic,0,Red); 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); } void CheckForClose() { int cnt,total; total=OrdersTotal(); for(cnt=0;cnt=Profit||OrderProfit()<=-Loss) { OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),Slippage,Violet); // close position return(0); } } else { if(OrderProfit()>=Profit||OrderProfit()<=-Loss) { OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),Slippage,Violet); // close position return(0); } } } } return(0); } //+------------------------------------------------------------------+