[Архив!] Напишу советника бесплатно - страница 83

 
int OrderSend( string symbol, int cmd, double volume, double price, int slippage, double stoploss, double takeprofit, string comment=NULL, int magic=0, datetime expiration=0, color arrow_color=CLR_NONE)
The main function used to open a position or place a pending order.
Returns number of the ticket assigned to the order by the trade server or -1 if it fails. To get additional error information, one has to call the GetLastError() function.
Notes:
At opening of a market order (OP_SELL or OP_BUY), only the latest prices of Bid (for selling) or Ask (for buying) can be used as open price. If operation is performed with a security differing from the current one, the MarketInfo() function must be used with MODE_BID or MODE_ASK parameter for the latest quotes for this security to be obtained. Calculated or unnormalized price cannot be applied. If there has not been the requested open price in the price thread or it has not been normalized according to the amount of digits after decimal point, the error 129 (ERR_INVALID_PRICE) will be generated. If the requested open price is fully out of date, the error 138 (ERR_REQUOTE) will be generated independently on the slippage parameter. If the requested price is out of date, but present in the thread, the position will be opened at the current price and only if the current price lies within the range of price+-slippage.

StopLoss and TakeProfit levels cannot be too close to the market. The minimal distance of stop levels in points can be obtained using the MarketInfo() function with MODE_STOPLEVEL parameter. In the case of erroneous or unnormalized stop levels, the error 130 (ERR_INVALID_STOPS) will be generated.

At placing of a pending order, the open price cannot be too close to the market. The minimal distance of the pending price from the current market one in points can be obtained using the MarketInfo() function with the MODE_STOPLEVEL parameter. In case of false open price of a pending order, the error 130 (ERR_INVALID_STOPS) will be generated.

Applying of pending order expiration time can be disabled in some trade servers. In this case, when a non-zero value is specified in the expiration parameter, the error 147 (ERR_TRADE_EXPIRATION_DENIED) will be generated.

On some trade servers, the total amount of open and pending orders can be limited. If this limit has been exceeded, no new position will be opened (or no pending order will be placed) and trade server will return error 148 (ERR_TRADE_TOO_MANY_ORDERS).
Parameters:
symbol - Symbol for trading.
cmd - Operation type. It can be any of the Trade operation enumeration.
volume - Number of lots.
price - Preferred price of the trade.
slippage - Maximum price slippage for buy or sell orders.
stoploss - Stop loss level.
takeprofit - Take profit level.
comment - Order comment text. Last part of the comment may be changed by server.
magic - Order magic number. May be used as user defined identifier.
expiration - Order expiration time (for pending orders only).
arrow_color - Color of the opening arrow on the chart. If parameter is missing or has CLR_NONE value opening arrow is not drawn on the chart.
 
#property link "dwgrell@gmail.com"

//--- input parameters
extern int period=16;
extern int porog=50;

extern double lot=1;
extern int k=5000;

extern bool pl=true;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
double bs=NormalizeDouble(iCustom(Symbol(),0,"Aver",period,0,0),Digits);
double ss=NormalizeDouble(iCustom(Symbol(),0,"Aver",period,1,0),Digits);
double tpb=NormalizeDouble(bs+(bs-ss),Digits);
double tps=NormalizeDouble(ss-(bs-ss),Digits);
if(pl==true)double lots=MathMin(AccountFreeMargin()/k,5);
if(pl==false)lots=lot;
if(OrdersTotal()==0)
{
OrderSend(Symbol(),OP_BUYSTOP,lots,bs,3,ss,tpb,"",1394,0,Red);//Открываем отложник на покупку.
OrderSend(Symbol(),OP_SELLSTOP,lots,ss,3,bs,tps,"",1394,0,Blue);//Открываем отложник на продажу.
}
if(OrdersTotal()==2)
{
OrderSelect(0,SELECT_BY_POS,MODE_TRADES);//Выбираем ближайший ордер.
if(OrderType()==OP_BUYSTOP &&bs<OrderOpenPrice())OrderModify(OrderTicket(),bs,ss,tpb,0,Red);
if(OrderType()==OP_SELLSTOP&&ss>OrderOpenPrice())OrderModify(OrderTicket(),ss,bs,tps,0,Blue);
if(OrderType()==OP_BUY &&ss>OrderStopLoss())OrderModify(OrderTicket(),OrderOpenPrice(),ss,OrderTakeProfit(),0,Red);
if(OrderType()==OP_SELL&&bs<OrderStopLoss())OrderModify(OrderTicket(),OrderOpenPrice(),bs,OrderTakeProfit(),0,Red);
OrderSelect(1,SELECT_BY_POS,MODE_TRADES);
if(OrderType()==OP_BUYSTOP &&bs<OrderOpenPrice())OrderModify(OrderTicket(),bs,ss,tpb,0,Red);
if(OrderType()==OP_SELLSTOP&&ss>OrderOpenPrice())OrderModify(OrderTicket(),ss,bs,tps,0,Blue);
if(OrderType()==OP_BUY &&ss>OrderStopLoss())OrderModify(OrderTicket(),OrderOpenPrice(),ss,OrderTakeProfit(),0,Red);
if(OrderType()==OP_SELL&&bs<OrderStopLoss())OrderModify(OrderTicket(),OrderOpenPrice(),bs,OrderTakeProfit(),0,Red);
}
if(OrdersTotal()==1)
{
OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
if(OrderType()==OP_BUY) {OrderModify(OrderTicket(),OrderOpenPrice(),ss,OrderTakeProfit(),0,Red);
OrderSend(Symbol(),OP_SELLSTOP,lots,ss,3,bs,tps,"",1394,0,Blue);}
if(OrderType()==OP_SELL) {OrderModify(OrderTicket(),OrderOpenPrice(),bs,OrderTakeProfit(),0,Red);
OrderSend(Symbol(),OP_BUYSTOP,lots,bs,3,ss,tpb,"",1394,0,Red);}
if(OrderType()==OP_BUYSTOP) {OrderModify(OrderTicket(),bs,ss,tpb,0,Red);
OrderSend(Symbol(),OP_SELLSTOP,lots,ss,3,bs,tps,"",1394,0,Blue);}
if(OrderType()==OP_SELLSTOP){OrderModify(OrderTicket(),ss,bs,tps,0,Blue);
OrderSend(Symbol(),OP_BUYSTOP,lots,bs,3,ss,tpb,"",1394,0,Red);}
}

return(0);
}
//+------------------------------------------------------------------+
 
#property link "dwgrell@gmail.com"

//--- input parameters
extern int period=16;
extern int porog=50;

extern double lot=1;
extern int k=5000;

extern bool pl=true;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
double bs=NormalizeDouble(iCustom(Symbol(),0,"Aver",period,0,0),Digits);
double ss=NormalizeDouble(iCustom(Symbol(),0,"Aver",period,1,0),Digits);
double tpb=NormalizeDouble(bs+(bs-ss),Digits);
double tps=NormalizeDouble(ss-(bs-ss),Digits);
if(pl==true)double lots=MathMin(AccountFreeMargin()/k,5);
if(pl==false)lots=lot;
if(OrdersTotal()==0)
{
OrderSend(Symbol(),OP_BUYSTOP,lots,bs,3,0,0,"",1394,0,Red);//Открываем отложник на покупку.
OrderSend(Symbol(),OP_SELLSTOP,lots,ss,3,0,0,"",1394,0,Blue);//Открываем отложник на продажу.
}
if(OrdersTotal()==2)
{
OrderSelect(0,SELECT_BY_POS,MODE_TRADES);//Выбираем ближайший ордер.
if(OrderType()==OP_BUYSTOP &&bs<OrderOpenPrice())OrderModify(OrderTicket(),bs,0,0,0,Red);
if(OrderType()==OP_SELLSTOP&&ss>OrderOpenPrice())OrderModify(OrderTicket(),ss,0,0,0,Blue);
//if(OrderType()==OP_BUY &&ss>OrderStopLoss())OrderModify(OrderTicket(),OrderOpenPrice(),ss,OrderTakeProfit(),0,Red);
//if(OrderType()==OP_SELL&&bs<OrderStopLoss())OrderModify(OrderTicket(),OrderOpenPrice(),bs,OrderTakeProfit(),0,Red);
OrderSelect(1,SELECT_BY_POS,MODE_TRADES);
if(OrderType()==OP_BUYSTOP &&bs<OrderOpenPrice())OrderModify(OrderTicket(),bs,0,0,0,Red);
if(OrderType()==OP_SELLSTOP&&ss>OrderOpenPrice())OrderModify(OrderTicket(),ss,0,0,0,Blue);
//if(OrderType()==OP_BUY &&ss>OrderStopLoss())OrderModify(OrderTicket(),OrderOpenPrice(),ss,OrderTakeProfit(),0,Red);
//if(OrderType()==OP_SELL&&bs<OrderStopLoss())OrderModify(OrderTicket(),OrderOpenPrice(),bs,OrderTakeProfit(),0,Red);
}
if(OrdersTotal()==1)
{
OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
if(OrderType()==OP_BUY) {/*OrderModify(OrderTicket(),OrderOpenPrice(),ss,OrderTakeProfit(),0,Red);*/
OrderSend(Symbol(),OP_SELLSTOP,lots,ss,3,0,0,"",1394,0,Blue);}
if(OrderType()==OP_SELL) {/*OrderModify(OrderTicket(),OrderOpenPrice(),bs,OrderTakeProfit(),0,Red);*/
OrderSend(Symbol(),OP_BUYSTOP,lots,bs,3,0,0,"",1394,0,Red);}
if(OrderType()==OP_BUYSTOP) {/*OrderModify(OrderTicket(),bs,ss,tpb,0,Red);*/
OrderSend(Symbol(),OP_SELLSTOP,lots,ss,3,0,0,"",1394,0,Blue);}
if(OrderType()==OP_SELLSTOP){/*OrderModify(OrderTicket(),ss,bs,tps,0,Blue);*/
OrderSend(Symbol(),OP_BUYSTOP,lots,bs,3,0,0,"",1394,0,Red);}
}

return(0);
}
//+------------------------------------------------------------------+
 
Account: 154603Name: ДмитрийCurrency: USD2011 July 12, 14:23
Closed Transactions:
TicketOpen TimeTypeSizeItemPriceS / LT / PClose TimePriceCommissionTaxesSwapProfit
37055732011.07.12 13:57buy2.16eurusd1.39821.39731.40652011.07.12 14:131.39730.000.000.00-194.40
37053282011.07.12 13:19buy2.01eurusd1.39241.38991.39482011.07.12 13:491.39480.000.000.00482.40
37053562011.07.12 13:14sell2.17eurusd1.39001.39241.38762011.07.12 13:191.39240.000.000.00-520.80
37052852011.07.12 13:05sell2.17eurusd1.39141.39241.39042011.07.12 13:111.39040.000.000.00217.00
37052782011.07.12 13:04buy2.17eurusd1.39241.39141.39342011.07.12 13:051.39140.000.000.00-217.00
37048122011.07.12 11:32buy2.40eurusd1.39591.39141.40202011.07.12 13:011.39140.000.000.00-1 080.00
37040302011.07.12 13:01sell1.88eurusd1.39141.39171.39112011.07.12 13:011.39170.000.000.00-56.40
37041582011.07.12 10:22buy2.13eurusd1.38961.38981.39582011.07.12 11:301.39580.000.000.001 320.60
37040632011.07.12 10:12buy2.02eurusd1.38611.38341.38882011.07.12 10:211.38880.000.000.00545.40
37040202011.07.12 10:05buy1.92eurusd1.38481.38341.38592011.07.12 10:121.38590.000.000.00211.20
37040012011.07.12 10:04sell1.95eurusd1.38371.38481.38312011.07.12 10:051.38480.000.000.00-214.50
37035052011.07.12 10:01buy1.82eurusd1.38431.38371.38492011.07.12 10:041.38370.000.000.00-109.20
37039202011.07.12 09:52sell2.04eurusd1.38451.38431.37552011.07.12 10:011.38430.000.000.0040.80
37036312011.07.12 09:12sell1.88eurusd1.38921.39351.38492011.07.12 09:501.38490.000.000.00808.40
37035332011.07.12 09:03sell1.80eurusd1.39151.39351.38952011.07.12 09:101.38950.000.000.00360.00
37035062011.07.12 09:02sell1.82eurusd1.39271.39301.39242011.07.12 09:021.39300.000.000.00-54.60
 
На реал не советую.
 
grell у меня стоп лоссы не выставляются
 
стоп лосс на минимум свечи
 
или максимум в зависимости какой ордер
 
Попробуйте вникнуть в код советника, И Вы поймете, почему он стал кастрированным. там все просто, ибо писал для тестера. Но как ни странно, все работает.
 
Чесно говоря я вобще не понимаю в програмировании MQL
Причина обращения: