//+------------------------------------------------------------------+ //| myRandom.mq4 | //| Copyright © 2007 | //| | //| | //| | //+------------------------------------------------------------------+ #property copyright "Copyright © 2007, EarnForex.com" #property link "http://www.earnforex.com" //Minimum stop-loss and take-profit distance #define MIN_LIMIT 12 extern double Lots=0.1; extern double Slippage = 3; extern int RandomEntryPeriod = 80; //In bars. How many bars to wait before entering a new position. extern int StopLoss = 90; extern int TakeProfit = 600; extern int MaxPositions = 4; extern color clOpenBuy = Blue; extern color clOpenSell = Red; int Magic; int LastBars = 0; int OrderTaken = 0; double Poin; int init() { //Checking for unconvetional Point digits number if (Point == 0.00001) Poin = 0.0001; //5 digits else if (Point == 0.001) Poin = 0.01; //3 digits else Poin = Point; //Normal Magic = Period()+1339005; return(0); } //+------------------------------------------------------------------+ //| Random entry expert advisor | //+------------------------------------------------------------------+ int start() { if (LastBars == Bars) return(0); else LastBars = Bars; if (AccountFreeMargin() < (Lots*2*1000)) return(0); if (Lots < 0.1) return(0); MathSrand(TimeLocal()); int count = 0; int total = OrdersTotal(); for (int pos = 0; pos < total; pos++) { if (OrderSelect(pos, SELECT_BY_POS) == false) continue; if ((OrderMagicNumber() == Magic) && (OrderSymbol() == Symbol())) count++; } if (count >= MaxPositions) return(0); if (Bars >= OrderTaken + RandomEntryPeriod) { if ((MathRand()%2) == 1) { fSell(); } else { fBuy(); } OrderTaken = Bars; } } //+------------------------------------------------------------------+ //| Buy | //+------------------------------------------------------------------+ void fBuy() { RefreshRates(); int result = OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,Ask-StopLoss*Poin,Ask+TakeProfit*Poin,"myRandom",Magic,0,clOpenBuy); if (result == -1) { int e = GetLastError(); Print(e); } } //+------------------------------------------------------------------+ //| Sell | //+------------------------------------------------------------------+ void fSell() { RefreshRates(); int result = OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,Bid+StopLoss*Poin,Bid-TakeProfit*Poin,"myRandom",Magic,0,clOpenSell); if (result == -1) { int e = GetLastError(); Print(e); } }