//+------------------------------------------------------------------+ //| Uti_Puti_Trade_Right.mq4 | //| budimir | //| tartar27@bigmir.net | //+------------------------------------------------------------------+ #property copyright "budimir" #property link "tartar27@bigmir.net" //---- input parameters //ooooooooooooooooooooooooooooooooooooooooooooooooo extern bool In_BUY=true; extern int SL_buy=62; //---âõîäíûå ïàðàìåòðû ïî ëîíãàì extern int Risk_buy=0; //ooooooooooooooooooooooooooooooooooooooooooooooooo extern bool In_SELL=true; extern int SL_sell=62; //---âõîäíûå ïàðàìåòðû ïî øîðòàì extern int Risk_sell=0; //ooooooooooooooooooooooooooooooooooooooooooooooooo //---- other parameters static int prevtime=0; int ticket=0; int x=1; //---------------------------------------------- int Magic_BUY =123; int Magic_SELL =321; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- if(Digits == 5) x=10; //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //oooooooooooooooooooooooooooooooooooooooooooooooooooo if (Time[0] == prevtime) return(0); prevtime = Time[0]; if (!IsTradeAllowed()) { prevtime=Time[1]; MathSrand(TimeCurrent());Sleep(30000 + MathRand()); //--- ôîðìèðîâêà áàðà--- } //ooooooooooooooooooooooooooooooooooooooooooooooooooooOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO Trade( Magic_BUY, In_BUY,Ask,0,3, SL_buy, Risk_buy); //---òîðãîâëÿ ïî ëîíãàì Trade(Magic_SELL,In_SELL,Bid,3,0, SL_sell,Risk_sell); //---òîðãîâëÿ ïî øîðòàì //ooooooooooooooooooooooooooooooooooooooooooooooooooooOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO return(0);//-----------âûõîä èç ñòàðòîâîé ôóíêöèè------------ } //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx void Trade(int mn,bool flag,double price,int period_1,int period_2,int sl,int Risk) { int total=OrdersTotal(); for (int i = 0; i < total; i++) { OrderSelect(i, SELECT_BY_POS, MODE_TRADES);//---ïðîõîä ïî îðäåðàì-- if (OrderSymbol() == Symbol() && OrderMagicNumber() == mn) { if(Open[period_2]>Open[period_1]) { //----óñëîâèå çàêðûòèÿ îðäåðà--------- OrderClose(OrderTicket(),OrderLots(),price,5*x); RefreshRates(); } return(0); } } //ooooooooooooooooooooooooooooooooooooooooooooooooooo ticket = -1; if ( flag && Open[period_1]>Open[period_2] && //----âõîä â ðûíîê ïî óñëîâèþ--- OrdersTotal()<2 && //-----îãðàíè÷åíèÿ ÷åìïèîíàòà------ AccountEquity()>200 && IsTradeAllowed()) { if (mn<200) { ticket= OrderSend(Symbol(), OP_BUY,lot(Risk_buy),Ask,5,Bid-x*sl*Point,0,DoubleToStr(mn,0),mn,0,Blue); } else { ticket= OrderSend(Symbol(),OP_SELL,lot(Risk_sell),Bid,5,Ask+x*sl*Point,0,DoubleToStr(mn,0),mn,0, Red); } RefreshRates(); if ( ticket < 0) { Sleep(30000); prevtime = Time[1]; } } //-- Exit --- return(0); } //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx double lot(int R) { if (R<0)R=0; if (R>80)R=80; //------êîððåêòíîñòü ââîäà ------- double minlot = MarketInfo(Symbol(), MODE_MINLOT); int o = MathAbs(MathLog(minlot) *0.4343) + 0.5; double lot = minlot; //ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo lot = NormalizeDouble(AccountFreeMargin() * 0.00001*R, o);//--- if (AccountFreeMargin() < lot * MarketInfo(Symbol(), MODE_MARGINREQUIRED)) { lot = NormalizeDouble(AccountFreeMargin() / MarketInfo(Symbol(), MODE_MARGINREQUIRED), o); } //ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo if(lot < minlot) lot = minlot; double maxlot =MarketInfo(Symbol(), MODE_MAXLOT); if(lot > maxlot) lot = maxlot; return(lot); } //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx_end_film_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Sample
Analysis
Market Information Used:
Series array that contains open time of each bar
Series array that contains open prices of each bar
Indicator Curves created:
Indicators Used:
Custom Indicators Used:
Order Management characteristics:
Checks for the total of open orders
It Closes Orders by itself
It automatically opens orders when conditions are reached
Other Features: