Здраствуйте!
Нашел в своих архивах советник что когда-то собирал, до ума не довел и забросил. Есть ли возможность исправить ошибки с существующими билдами? Либо может быть стоит написать его с нуля?
//+------------------------------------------------------------------+
//| grabber_1.mq4 |
//| Copyright © 2011, MetaQuotes Software Corp. |
//| www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright «Copyright © 2011, MetaQuotes Software Corp.»
#property link «www.metaquotes.net»
extern double lot=0.1;
extern int slow=15;
extern int fast=5;
extern int sag=20;
extern double k=1.3;
int ticket=-1;
extern double percent_of_profit =33;
extern double drawtown_of_balance = 6;
extern double minimum_profit = 300;
double profit,profit_off,result,i,al,bl,cl,dl,el,fl,gl,hl,il,jl,cnt, ticket2, ticket3, ticket4, ticket5, ticket6, ticket7, ticket8, ticket9, ticket10, ticket11, ticket12, ticket13, ticket14, ticket15, ticket16, ticket17, ticket18, ticket19, ticket20, ticket21, ticket22;
extern bool trail_enable=false,close_start=false;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
{
profit_off=0;
result = 0;
Comment ("");
return(0);
}
//----
return(0);
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
if(AccountFreeMargin()<(1000*lot))
{
Print(«We have no money. Free Margin = », AccountFreeMargin());
return(0);
}
//расчет лотов
al=MathRound( lot*100*k)/100;
bl=MathRound( al*100*k)/100;
cl=MathRound( bl*100*k)/100;
dl=MathRound( cl*100*k)/100;
el=MathRound( dl*100*k)/100;
fl=MathRound( el*100*k)/100;
gl=MathRound( fl*100*k)/100;
hl=MathRound( gl*100*k)/100;
il=MathRound( hl*100*k)/100;
jl=MathRound( il*100*k)/100;
//открываем первые ордера
double la,lb;
if(ticket<1)
{
la=Ask;
lb=Bid;
double slow_ma, fast_ma;
fast_ma=iMA(NULL, 0, fast, 0, MODE_EMA, PRICE_CLOSE, 0);
slow_ma=iMA(NULL, 0, slow, 0, MODE_EMA, PRICE_CLOSE, 0);
if(fast_ma>slow_ma && ticket<1)
{
ticket=OrderSend(Symbol(), OP_BUY, lot, la, 3, 0, 0, NULL, 1, 0,Green);
ticket3=OrderSend(Symbol(), OP_SELLSTOP, al, Ask-sag*Point, 3, 0, 0, NULL, 3, 0,Red);
ticket2=OrderSend(Symbol(), OP_BUYSTOP, lot, Ask+sag*Point, 3, 0, 0, NULL, 2, 0,Green);
}
if(fast_ma<slow_ma && ticket<1)
{
ticket=OrderSend(Symbol(), OP_SELL, lot, lb, 3, 0, 0, NULL, 1, 0,Red);
ticket3=OrderSend(Symbol(), OP_BUYSTOP, al, Bid+sag*Point, 3, 0, 0, NULL, 3, 0,Green);
ticket2=OrderSend(Symbol(), OP_SELLSTOP, lot, Bid-sag*Point, 3, 0, 0, NULL, 2, 0,Red);
}
}
//поиск и открытие следующих ордеров
for (int i=OrdersTotal();i>=1;i--)
{
OrderSelect (i-1,SELECT_BY_POS,MODE_TRADES);
{
if (OrderMagicNumber()==2 && ticket4<1)
{if(OrderType()==OP_SELL){
ticket4=OrderSend(Symbol(), OP_BUYSTOP, al, Ask+sag*Point, 3, 0, 0, NULL, 4, 0,Green);}
if(OrderType()==OP_BUY){
ticket4=OrderSend(Symbol(), OP_SELLSTOP, al, Ask-sag*Point, 3, 0, 0, NULL, 4, 0,Green);}
}
if (OrderMagicNumber()==3 && ticket5<1)
{if(OrderType()==OP_SELL){
ticket5=OrderSend(Symbol(), OP_BUYSTOP, bl, Bid+sag*Point, 3, 0, 0, NULL, 5, 0,Green);}
if(OrderType()==OP_BUY){
ticket5=OrderSend(Symbol(), OP_SELLSTOP, bl, Ask-sag*Point, 3, 0, 0, NULL, 5, 0,Green);}
}
if (OrderMagicNumber()==4 && ticket6<1)
{if(OrderType()==OP_SELL){
ticket6=OrderSend(Symbol(), OP_BUYSTOP, bl, Bid+sag*Point, 3, 0, 0, NULL, 6, 0,Green);}
if(OrderType()==OP_BUY){
ticket6=OrderSend(Symbol(), OP_SELLSTOP, bl, Ask-sag*Point, 3, 0, 0, NULL, 6, 0,Green);}
}
if (OrderMagicNumber()==5 && ticket7<1)
{if(OrderType()==OP_SELL){
ticket7=OrderSend(Symbol(), OP_BUYSTOP, cl, Bid+sag*Point, 3, 0, 0, NULL, 7, 0,Green);}
if(OrderType()==OP_BUY){
ticket7=OrderSend(Symbol(), OP_SELLSTOP, cl, Ask-sag*Point, 3, 0, 0, NULL, 7, 0,Green);}
}
if (OrderMagicNumber()==6 && ticket8<1)
{if(OrderType()==OP_SELL){
ticket8=OrderSend(Symbol(), OP_BUYSTOP, cl, Bid+sag*Point, 3, 0, 0, NULL, 8, 0,Green);}
if(OrderType()==OP_BUY){
ticket8=OrderSend(Symbol(), OP_SELLSTOP, cl, Ask-sag*Point, 3, 0, 0, NULL, 8, 0,Green);}
}
if (OrderMagicNumber()==7 && ticket9<1)
{if(OrderType()==OP_SELL){
ticket9=OrderSend(Symbol(), OP_BUYSTOP, dl, Bid+sag*Point, 3, 0, 0, NULL, 9, 0,Green);}
if(OrderType()==OP_BUY){
ticket9=OrderSend(Symbol(), OP_SELLSTOP, dl, Ask-sag*Point, 3, 0, 0, NULL, 9, 0,Green);}
}
if (OrderMagicNumber()==8 && ticket10<1)
{if(OrderType()==OP_SELL){
ticket10=OrderSend(Symbol(), OP_BUYSTOP, dl, Bid+sag*Point, 3, 0, 0, NULL, 10, 0,Green);}
if(OrderType()==OP_BUY){
ticket10=OrderSend(Symbol(), OP_SELLSTOP, dl, Ask-sag*Point, 3, 0, 0, NULL, 10, 0,Green);}
}
if (OrderMagicNumber()==9 && ticket11<1)
{if(OrderType()==OP_SELL){
ticket11=OrderSend(Symbol(), OP_BUYSTOP, el, Bid+sag*Point, 3, 0, 0, NULL, 11, 0,Green);}
if(OrderType()==OP_BUY){
ticket11=OrderSend(Symbol(), OP_SELLSTOP, el, Ask-sag*Point, 3, 0, 0, NULL, 11, 0,Green);}
}
if (OrderMagicNumber()==10 && ticket12<1)
{if(OrderType()==OP_SELL){
ticket12=OrderSend(Symbol(), OP_BUYSTOP, el, Bid+sag*Point, 3, 0, 0, NULL, 12, 0,Green);}
if(OrderType()==OP_BUY){
ticket12=OrderSend(Symbol(), OP_SELLSTOP, el, Ask-sag*Point, 3, 0, 0, NULL, 12, 0,Green);}
}
if (OrderMagicNumber()==11 && ticket13<1)
{if(OrderType()==OP_SELL){
ticket13=OrderSend(Symbol(), OP_BUYSTOP, gl, Bid+sag*Point, 3, 0, 0, NULL, 13, 0,Green);}
if(OrderType()==OP_BUY){
ticket13=OrderSend(Symbol(), OP_SELLSTOP, gl, Ask-sag*Point, 3, 0, 0, NULL, 13, 0,Green);}
}
if (OrderMagicNumber()==12 && ticket14<1)
{if(OrderType()==OP_SELL){
ticket14=OrderSend(Symbol(), OP_BUYSTOP, gl, Bid+sag*Point, 3, 0, 0, NULL, 14, 0,Green);}
if(OrderType()==OP_BUY){
ticket14=OrderSend(Symbol(), OP_SELLSTOP, gl, Ask-sag*Point, 3, 0, 0, NULL, 14, 0,Green);}
}
if (OrderMagicNumber()==13 && ticket15<1)
{if(OrderType()==OP_SELL){
ticket15=OrderSend(Symbol(), OP_BUYSTOP, hl, Bid+sag*Point, 3, 0, 0, NULL, 15, 0,Green);}
if(OrderType()==OP_BUY){
ticket15=OrderSend(Symbol(), OP_SELLSTOP, hl, Ask-sag*Point, 3, 0, 0, NULL, 15, 0,Green);}
}
if (OrderMagicNumber()==14 && ticket16<1)
{if(OrderType()==OP_SELL){
ticket16=OrderSend(Symbol(), OP_BUYSTOP, hl, Bid+sag*Point, 3, 0, 0, NULL, 16, 0,Green);}
if(OrderType()==OP_BUY){
ticket16=OrderSend(Symbol(), OP_SELLSTOP, hl, Ask-sag*Point, 3, 0, 0, NULL, 16, 0,Green);}
}
if (OrderMagicNumber()==15 && ticket17<1)
{if(OrderType()==OP_SELL){
ticket17=OrderSend(Symbol(), OP_BUYSTOP, il, Bid+sag*Point, 3, 0, 0, NULL, 17, 0,Green);}
if(OrderType()==OP_BUY){
ticket17=OrderSend(Symbol(), OP_SELLSTOP, il, Ask-sag*Point, 3, 0, 0, NULL, 17, 0,Green);}
}
if (OrderMagicNumber()==16 && ticket18<1)
{if(OrderType()==OP_SELL){
ticket18=OrderSend(Symbol(), OP_BUYSTOP, il, Bid+sag*Point, 3, 0, 0, NULL, 18, 0,Green);}
if(OrderType()==OP_BUY){
ticket18=OrderSend(Symbol(), OP_SELLSTOP, il, Ask-sag*Point, 3, 0, 0, NULL, 18, 0,Green);}
}
if (OrderMagicNumber()==17 && ticket19<1)
{if(OrderType()==OP_SELL){
ticket19=OrderSend(Symbol(), OP_BUYSTOP, il, Bid+sag*Point, 3, 0, 0, NULL, 19, 0,Green);}
if(OrderType()==OP_BUY){
ticket19=OrderSend(Symbol(), OP_SELLSTOP, il, Ask-sag*Point, 3, 0, 0, NULL, 19, 0,Green);}
}
if (OrderMagicNumber()==18 && ticket20<1)
{if(OrderType()==OP_SELL){
ticket20=OrderSend(Symbol(), OP_BUYSTOP, il, Bid+sag*Point, 3, 0, 0, NULL, 20, 0,Green);}
if(OrderType()==OP_BUY){
ticket20=OrderSend(Symbol(), OP_SELLSTOP, il, Ask-sag*Point, 3, 0, 0, NULL, 20, 0,Green);}
}
}
}
//обнуляем тикеты
if (OrderSelect(0, SELECT_BY_POS, MODE_TRADES )==false)
{ticket=0;
ticket2=0;
ticket3=0;
ticket4=0;
ticket5=0;
ticket6=0;
ticket7=0;
ticket8=0;
ticket9=0;
ticket10=0;
}
//следим за прибылью
if (close_start)
{
for (int u=OrdersTotal();u>=1;u--)
{
OrderSelect (u-1,SELECT_BY_POS,MODE_TRADES);
{
if (OrderType()==OP_BUY)
{
double price = MarketInfo (OrderSymbol(),MODE_BID);
OrderClose (OrderTicket(),OrderLots(),price,3,0);
result = OrderProfit()+result;
}
if (OrderType()==OP_SELL)
{
price = MarketInfo (OrderSymbol(),MODE_ASK);
OrderClose (OrderTicket(),OrderLots(),price,3,0);
result = OrderProfit()+result;
}
if (OrderType()==OP_SELLLIMIT||OrderType()==OP_BUYLIMIT||OrderType()==OP_SELLSTOP||OrderType()==OP_BUYSTOP)
{
OrderDelete(OrderTicket());
}
}
}
}
for ( i=OrdersTotal(); i>=1; i--)
{
OrderSelect(i-1,SELECT_BY_POS,MODE_TRADES);
profit = OrderProfit()+profit;
}
double drawtown = NormalizeDouble((profit*100)/AccountBalance(),2);
if (close_start&&OrdersTotal()==0)
{
trail_enable=false;
close_start= false;
Alert («Советник закрыл позиции с результатом », result);
profit_off=0;
result = 0;
}
if (!trail_enable&&OrdersTotal()!=0)
{
Comment («Режим трала выключен.» ,"\n",«Советник начнет сопровождать ордера при росте прибыли до »,minimum_profit,
" текущая прибыль ", profit, ", что составляет ", drawtown, "% от баланса", "\n",
«Примечание: при увеличении просадки до », drawtown_of_balance, "% советник закроет ордера","\n",al,"\n",bl,"\n",cl,"\n",dl,"\n",el,"\n",fl,"\n",gl );
}
if ((profit_off==0&&minimum_profit < profit)||(profit_off!=0&&profit_off<profit-profit*(percent_of_profit/100)))
{
trail_enable=true;
profit_off=profit-profit*(percent_of_profit/100);
Comment(«Режим трала включен.» ,"\n",«Советник закроет ордера при падении прибыли до »,profit_off,
" максимальная прибыль ", profit,"\n",al,"\n",bl,"\n",cl,"\n",dl,"\n",el,"\n",fl,"\n",gl );
}
if ((trail_enable&&profit_off>profit)||drawtown_of_balance*(-1)>=drawtown)
{
close_start=true;
}
profit =0;
//----
return(0);
}
//+------------------------------------------------------------------+
Комментарии (4)
Зачем три раза return(0)? И зачем внутри функции еще одни скобки {}, если не стоит никаких условий?
Переделывать этот код не буду.
27 Oxy Сообщений: 3430 - ..ιllιlι.lι.ιllι.ιlι..
16 deenyy Автор Сообщений: 127 - deenyy
А если опишу его принцип работы сделаете?
16 deenyy Автор Сообщений: 127 - deenyy
27 Oxy Сообщений: 3430 - ..ιllιlι.lι.ιllι.ιlι..
Зарегистрируйтесь или авторизуйтесь, чтобы оставить комментарий