//+------------------------------------------------------------------+ //| MAMy Expert.mq4 | //| Copyright © 2006, Victor Chebotariov | //| http://www.chebotariov.com/ | //+------------------------------------------------------------------+ #property copyright "Copyright © 2006, Victor Chebotariov" #property link "http://www.chebotariov.com/" //---- extern int period = 3; extern int ma_method = 3; extern double Lots = 0.1; //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- if(Bars < 100) { Print("bars less than 100"); return(0); } //---- int cnt, ticket, total; double iMAMy_0 = iCustom(NULL, PERIOD_MN1, "MAMy v.3", ma_method, period, 0, 1); double iMAMy_1 = iCustom(NULL, PERIOD_MN1, "MAMy v.3", ma_method, period, 0, 2); double iMAMy_2 = iCustom(NULL, PERIOD_MN1, "MAMy v.3", ma_method, period, 1, 1); double iMAMy_3 = iCustom(NULL, PERIOD_MN1, "MAMy v.3", ma_method, period, 1, 2); //---- total = OrdersTotal(); //---- if(total < 1) { if(AccountFreeMargin() < (1000*Lots)) { Print("We have no money. Free Margin = ", AccountFreeMargin()); return(0); } //---- if(iMAMy_0 > 0 && iMAMy_1 <= 0) { ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, 3, 0, 0, 0, 16384, 0, Green); //---- if(ticket > 0) if(OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES)) Print("BUY order opened : ", OrderOpenPrice()); else Print("Error opening BUY order : ", GetLastError()); return(0); } //---- if(iMAMy_0 < 0 && iMAMy_1 >= 0) { ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, 3, 0, 0, 0, 16384, 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); } //---- for(cnt = 0; cnt < total; cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); //---- if(OrderType() <= OP_SELL && // check for opened position OrderSymbol() == Symbol()) // check for symbol { if(OrderType() == OP_BUY) // long position is opened if(iMAMy_2 < 0 && iMAMy_3 >= 0) { // close position OrderClose(OrderTicket(), OrderLots(), Bid, 3, Violet); return(0); // exit } else // go to short position { if(iMAMy_2 > 0 && iMAMy_3 <= 0) { // close position OrderClose(OrderTicket(), OrderLots(), Ask, 3, Violet); return(0); // exit } } } } //---- return(0); } //+------------------------------------------------------------------+