//+------------------------------------------------------------------+ //| myRandom.mq4 | //| Copyright © 2007 EarnForex.com | //| http://www.earnforex.com/ | //+------------------------------------------------------------------+ #property copyright "Copyright © 2007, EarnForex.com" #property link "http://www.earnforex.com" 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 Deviation; int init() { //Checking for unconvetional Point digits number if ((Point == 0.00001) || (Point == 0.001)) { Poin = Point * 10; Deviation = Slippage * 10; } else { Poin = Point; //Normal Deviation = Slippage; } 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,Deviation,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,Deviation,Bid+StopLoss*Poin,Bid-TakeProfit*Poin,"myRandom",Magic,0,clOpenSell); if (result == -1) { int e = GetLastError(); Print(e); } }