//+------------------------------------------------------------------+ //| test.mq4 | //| Copyright © 2009, MetaQuotes Software Corp. | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "Copyright © 2009, MetaQuotes Software Corp." #property link "http://www.metaquotes.net" #property show_inputs extern int MaxRisk=2; extern bool Buy=false; //для открытия ордера на покупку extern bool Sell=false; //для открытия ордера на продажу extern int TakeProfit=100; extern int StopLoss=100; //+------------------------------------------------------------------+ int start() {double Lot=GetLot(MaxRisk); if(Lot==0) {Alert("Недостаточно средств!");return(0);} RefreshRates(); if(Buy) NewOrder(OP_BUY,Lot); if(Sell) NewOrder(OP_SELL,Lot); return(0);} //+------------------------------------------------------------------+ double GetLot(int Risk) {double Free =AccountFreeMargin(); double One_Lot =MarketInfo(Symbol(),MODE_MARGINREQUIRED); double Min_Lot =MarketInfo(Symbol(),MODE_MINLOT); double Max_Lot =MarketInfo(Symbol(),MODE_MAXLOT); double Step =MarketInfo(Symbol(),MODE_LOTSTEP); double Lot =MathFloor(Free*Risk/100/One_Lot/Step)*Step; if(LotMax_Lot) Lot=Max_Lot; if(Lot*One_Lot>Free) return(0.0); return(Lot);} //+------------------------------------------------------------------+ int NewOrder(int Cmd,double Lot) {double TP=0; //тейкпрофит double SL=0; //стоплосс double PR=0; //Цена while(!IsTradeAllowed()) Sleep(100); if(Cmd==OP_BUY) {PR=Ask; if(TakeProfit>0) TP=Ask+TakeProfit*Point; if(StopLoss>0) SL=Ask-StopLoss*Point;} if(Cmd==OP_SELL) {PR=Bid; if(TakeProfit>0) TP=Bid-TakeProfit*Point; if(StopLoss>0) SL=Bid+StopLoss*Point;} int tic=OrderSend(Symbol(),Cmd,Lot,PR,3,SL,TP,"",0,0,CLR_NONE); if(tic<0) Print("Ошибка открытия ордера: ",GetLastError()); return(tic);} //+------------------------------------------------------------------+