//+------------------------------------------------------------------+ //| JuanitaEA.mq4 | //| Copyright © 2008, MetaQuotes Software Corp. | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "Copyright © 2008, MetaQuotes Software Corp." #property link "http://www.metaquotes.net" extern string EA_Settings = " --- EA Settings --- "; extern int MagicNumber = 123; extern int TP = 50; extern int SL = 50; extern double Lots = 0.1; extern string NonLagMA_Settings = " --- NonLagMA Settings --- "; extern int Price = 0; extern int Length = 15; extern int Displace = 0; extern double PctFilter = 0; extern string note1 ="turn on Color = 1; turn off = 0"; extern int Color = 1; extern int ColorBarBack = 1; extern double Deviation = 0; extern string note2 ="turn on Alert = 1; turn off = 0"; extern int AlertMode = 0; extern string note3 ="turn on Warning = 1; turn off = 0"; extern int WarningMode = 0; extern string TrailStop_Properties = " --- Trail Stop Properties ---"; extern int TS = 0; // Stoploss follows behind current price by X pips extern bool OnlyTrailProfits = false; // Trailing Stop will only trail when order is profitable extern bool EnableTS = false; int init(){ return(0); } int deinit(){ return(0); } void closeOrder(int ticket,bool up_down){ if (OrderSelect(ticket,SELECT_BY_TICKET) == true){ if (OrderCloseTime() == 0){ //order has not closed if (up_down == true){ //close only buy orders if (OrderType() == OP_BUY){ OrderClose(OrderTicket(),OrderLots(),Bid,MarketInfo(OrderSymbol(),MODE_SPREAD)); } } else{ //close sell orders if (OrderType() == OP_SELL){ OrderClose(OrderTicket(),OrderLots(),Ask,MarketInfo(OrderSymbol(),MODE_SPREAD)); } } } } } void trailingStopManager(int tsV, bool profits,bool enableTS){ double pointer, bidder, asker; if (enableTS == true){ for(int cnt=0;cnt0) && (Symbol() == OrderSymbol()) && (OrderMagicNumber() == MagicNumber)){ bidder = MarketInfo(OrderSymbol(),MODE_BID); asker = MarketInfo(OrderSymbol(),MODE_ASK); pointer = MarketInfo(OrderSymbol(),MODE_POINT); if (OrderType()==OP_BUY){ if ((bidder-OrderOpenPrice()>pointer*tsV) || profits==false){ if (OrderStopLoss()pointer*tsV) || profits==false){ if ((OrderStopLoss()>(asker+pointer*tsV)) || (OrderStopLoss()==0)){ OrderModify(OrderTicket(),OrderOpenPrice(),asker+pointer*tsV,OrderTakeProfit(),0,Red); } } } }//tsV }//for } } bool NonLag(bool up_down,int shift){ double upValue,downValue; upValue = iCustom(Symbol(),Period(),"NonLagMA_v7.2",Price,Length,Displace,PctFilter,note1,Color,ColorBarBack,Deviation,note2,AlertMode,note3,WarningMode,6,shift); downValue = iCustom(Symbol(),Period(),"NonLagMA_v7.2",Price,Length,Displace,PctFilter,note1,Color,ColorBarBack,Deviation,note2,AlertMode,note3,WarningMode,7,shift); if (up_down == true){ if (upValue != 0){ return(true); } } else{ if (downValue != 0){ return(true); } } return(false); } double realTP(bool buy_sell){ double auxTP; if (TP == 0){ auxTP = 0; } else{ if (buy_sell == true){ //buy auxTP = Ask+TP*Point; } else{ auxTP = Bid-TP*Point; } } return(auxTP); } double realSL(bool buy_sell){ double auxSL; if (SL == 0){ auxSL = 0; } else{ if (buy_sell == true){ //buy auxSL = Ask-SL*Point; } else{ auxSL = Bid+SL*Point; } } return(auxSL); } int EAOrders(){ int count; count=0; for(int i =0;i<=OrdersTotal();i++){ if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == true){ if ((OrderSymbol() == Symbol()) && (OrderMagicNumber() == MagicNumber)){ count=count+1; } } } return(count); } int start(){ static datetime dtBarTime = 0; static int ticket; if (EAOrders() == 0){ if (NonLag(true,1) == true){ //up Alert("up"); ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,3,realSL(true),realTP(true),"",MagicNumber,0,Green); } if (NonLag(false,1) == true){ //down Alert("down"); ticket = OrderSend(Symbol(),OP_SELL,Lots,Bid,3,realSL(false),realTP(false),"",MagicNumber,0,Red); } } else{ trailingStopManager(TS,OnlyTrailProfits,EnableTS); if (NonLag(true,1) == true){ //up closeOrder(ticket,false); //close a sell order } if (NonLag(false,1) == true){ //down closeOrder(ticket,true); //close a sell order } } if (dtBarTime == Time[0]) return(0); dtBarTime = Time[0]; return(0); }