[ARQUIVO!] Qualquer pergunta de novato, para não desorganizar o fórum. Profissionais, não passem por aqui. Em nenhum lugar sem você - 4. - página 469

 
Pacman:

Olá a todos.

Eu tenho uma pergunta do tutorial MQL4.

Ao passar o MA por cima ou por baixo, não dá nenhuma mensagem?

Por favor, escreva o que está errado.


No testador?
 
PapaYozh:

No testador?
Não, em uma conta de demonstração.
 

Boa tarde,
Estou fazendo uma EA que move a parada para o breakeven após a abertura. Isto é, ele modifica a ordem, mas o problema é que ele modifica constantemente o que parece ser uma parada de trilha. Como modificá-lo uma vez e depois somente uma vez. Eu até inseri uma variável no código que mod1=1 mas depois mod1 tem que ser maior, mas o idioma, por algum motivo, não percebe.

Obrigado!

while(true)
{
if (tip==0 && open_b====true && mod1<=1 && Bid>ma+15*Point)
{
Alerta("popitkaa perenesti stop v b/u" ,ticket);
RefreshRates();
modify=OrderModify(ticket,Ask,Bid-mod*Point,0,0);
if(modify===true)
{
Alert("zakrit modificirovanij order",ticket);
mod1++;
retorno;
}
return;
}
if (tip====1 && open_s===verdadeiro && mod1<=1 && Bid<ma+15*Point)
{
Alerta("popitkaa perenesti stop ",ticket, "v b/u");
RefreshRates();
modify=OrderModify(ticket,Bid,Ask+mod*Point,0,0);
if(modify===true)
{
Alert("zakrit modificirovanij order",ticket);
mod1++;
return;
}
return;
}
break;
}

 
00FF33' - número inválido C:\Alpari`experts\customer.mq4 (66, 173) ???? Como posso inserir a cor corretamente?
 
kostikk:

Olá,
Estou fazendo um conselheiro que move a parada para o breakeven após a abertura. Ou seja, ele modifica a ordem, mas o problema é que ele está constantemente se modificando, algo como uma parada de fuga. Como modificá-lo uma vez e depois somente uma vez. Eu até adicionei uma variável no código, mod1=1 mas mod1 tem que ser maior, mas o idioma não sabe qual é o problema.

Obrigado!

Já feito para você e funciona bem

KimIV01.11.2006 18:49

Eu recomendo meu código testado
extern int    LevelProfit  = 30;            // Уровень профита
extern int    LevelWLoss   = 2;             // Уровень безубытка
extern color  clModifyBuy  = Aqua;          // Цвет модификации покупки
extern color  clModifySell = Tomato;        // Цвет модификации продажи
 
 
//+----------------------------------------------------------------------------+
//|  Перенос уровня StopLoss                                                   |
//|  Параметры:                                                                |
//|    ldStop  - уровень StopLoss                                              |
//|    lcColor - цвет модификации                                              |
//+----------------------------------------------------------------------------+
void ModifyStopLoss(double ldStop, color lcColor=CLR_NONE) {
  double ldOpen=OrderOpenPrice();
  double ldTake=OrderTakeProfit();
 
  OrderModify(OrderTicket(), ldOpen, ldStop, ldTake, 0, lcColor);
}
 
//+----------------------------------------------------------------------------+
//|  Перенос стопа в безубыток                                                 |
//+----------------------------------------------------------------------------+
void MovingInWL() {
  int i, k=OrdersTotal();
 
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==Symbol()) {
        if (OrderType()==OP_BUY) {
          if (OrderStopLoss()-OrderOpenPrice()<LevelWLoss*Point) {
            if (Bid-OrderOpenPrice()>LevelProfit*Point) {
              ModifyStopLoss(OrderOpenPrice()+LevelWLoss*Point, clModifyBuy);
            }
          }
        }
        if (OrderType()==OP_SELL) {
          if (OrderStopLoss()==0 || OrderOpenPrice()-OrderStopLoss()<LevelWLoss*Point) {
            if (OrderOpenPrice()-Ask>LevelProfit*Point) {
              ModifyStopLoss(OrderOpenPrice()-LevelWLoss*Point, clModifySell);
            }
          }
        }
      }
    }
  }
}
//+----------------------------------------------------------------------------+



https://forum.mql4.com/ru/4689

 
Dimka-novitsek:
00FF33' - número inválido C:\Alpari`experts\customer.mq4 (66, 173) ???? Como posso inserir a cor corretamente?


Na verdade, existe um tipo especial de variáveis no idioma - a cor é chamada. Por exemplo:

Velichina dupla;

MyLine;

Velichina=2,569;

MyLine=Red;

 

Como posso mudar o nome da janela gráfica?

 

Socorro! Por alguma razão não abre posições de VENDA, apenas COMPRAR????



#property copyright "eevviill"
#property link "itisallillusion@gmail.com"


extern string os = "Настройки лота и стопов";
extern double Lot = 0.1;
extern bool use_percent_of_deposit = false;
extern double Risk = 1;
extern int StopLoss = 0;
extern int TakeProfit = 0;

extern string slug = "Дополнительные настройки";
extern string pus1 = "";
extern bool use_exit = true;
extern int slippage = 2;
extern int magic = 4335;
extern string comment = "HA nonlag";
extern int MaxAttempts = 4;

extern string pus2 = "";
extern string V_R = "Время работы";
extern bool use_work_time = true;
extern int Start = 0;
extern int Stop = 24;

extern string pus3 = "";
extern string mar = "Мартингейл";
extern bool use_martini = false;
extern int CloseProfit_pips = 22;
extern double Lot_koef = 1.6;
extern int step = 40;

extern string pus4 = "";
extern string bez_ub = "Безубыток";
extern bool use_bezubitok = false;
extern int Bez_Ub_Level = 8;
extern int Bez_Ub_Size = 1;

extern string pus5 = "";
extern string tre_st = "Трейлинг стоп";
extern bool use_traling_stop = false;
extern int Trailing_Stop = 10;

extern string pus6 = "";
extern string ATR_p = "ATR";
extern bool use_ATR = false;
extern int ATR_period = 14;
extern double ATR_min_level = 0.0004;

extern string pus7 = "";
extern string ind1 = "HA nonlagma v4";
extern int Price = 0;
extern int Length = 21;
extern int Displace = 0;
extern int Filter = 0;
extern int Color = 1;
extern int ColorBarBack = 0;
extern double Deviation = 0;

extern double Cycle = 4;






double SLbuy=0, SLsell=0, TPbuy=0, TPsell=0;
int buy,sell,Sig_p,Sig_ex_p;
static int prevtime = 0;





//////////////////////////////////////////////////////////////
int init()
{
prevtime = iTime(Symbol(),0,0);


//ATR_level(4) && JPY_Point
if (StringFind(Symbol(), "JPY", 0) != -1) ATR_min_level *=100;


return;
}





////////////////////////////////////////////////////////////
int start(){
if (iTime(Symbol(), 0, 0) == prevtime) {Sleep(50);return(0);}
prevtime = iTime(Symbol(),0,0);

//проверка на разрешение торговли от брокера
while(!IsTradeAllowed()) Sleep(2000);

//фильтр ATR
if(use_ATR)
{
double ATR = iATR(Symbol(),0,ATR_period,1);
if(ATR<ATR_min_level) return;
}

//фильтр время
if(use_work_time)
{
if(Hour()<Start || Hour()>=Stop) return;
}

//мартингейл
if(use_martini) {use_bezubitok=false;use_traling_stop=false;use_percent_of_deposit=false;use_exit=false;}
if(use_martini) martini_f();

//закрытие всех ордеров при общем профите(пункты)- для мартини
if(use_martini)
{
if(Profit_f()>=CloseProfit_pips) Close_f();
}

//трейлинг стоп
if((Bez_Ub_Level>Trailing_Stop) && use_traling_stop) use_bezubitok=false;
if(use_traling_stop) Traling_Stop_f();

//безубыток
if(use_bezubitok) BezUb();

//SL && TP
if(!use_martini)
{
if(StopLoss>0) {SLbuy=NormalizeDouble(Ask-StopLoss*Point,Digits); SLsell=NormalizeDouble(Bid+StopLoss*Point,Digits);}
if(TakeProfit>0) {TPbuy=NormalizeDouble(Ask+TakeProfit*Point,Digits);TPsell=NormalizeDouble(Bid-TakeProfit*Point,Digits);}
}

//расчёт лота от % депозита
if(use_percent_of_deposit) Lot=GetLot();

//Сигнал на вход
Sig_p =Sig_f();
//Сигнал на выход
Sig_ex_p = Sig_ex_f();


//Выход
for(int i=OrdersTotal()-1; i>=0; i--)
{
OrderSelect(i,SELECT_BY_POS);
{
if(OrderMagicNumber()==magic)
{
bool ticket_ex;
for (int j_ex = 0;j_ex < MaxAttempts; j_ex++)
{
while(IsTradeContextBusy()) Sleep(2000);

if(OrderType()==OP_BUY && ((use_exit && Sig_p<0))) ticket_ex=OrderClose(OrderTicket(),OrderLots(),Bid,slippage,Yellow);
if(OrderType()==OP_SELL && ((use_exit && Sig_p>0))) ticket_ex=OrderClose(OrderTicket(),OrderLots(),Ask,slippage,Yellow);
if(ticket_ex==true)break;
}
}
}
}


//подсчёт открытых позиций
CountOpenPositions();

//Вход
int ticket_op=0;
for (int j_op = 0; j_op < MaxAttempts; j_op++)
{
while(IsTradeContextBusy()) Sleep(2000);

if(Sig_p>0 && buy==0&& sell==0) ticket_op=OrderSend(Symbol(),OP_BUY,Lot,Ask,slippage,SLbuy,TPbuy,comment,magic,0,Green);
if(Sig_p<0 && sell==0&& buy==0) ticket_op=OrderSend(Symbol(),OP_SELL,Lot,Bid,slippage,SLsell,TPsell,comment,magic,0,OrangeRed);
if(ticket_op>-1)break;
}





return(0);
}








//расчёт функций
/////////////////////////////////////////////////////////////////////////////////////////////
int Sig_f()
{
//объявление индикаторов
double ind1 = iCustom(Symbol(),0,"Heiken_ashi_nonlagma_v4",Price,Length,Displace,Filter,Color,ColorBarBack,Deviation,1,1); //buy
double ind2 = iCustom(Symbol(),0,"Heiken_ashi_nonlagma_v4",Price,Length,Displace,Filter,Color,ColorBarBack,Deviation,2,1); //sell


//сигнал для бай
if(ind1<50000) return(1);

//сигнал для сел
if(ind2<50000) return(-1);


return(0);
}

/////////////////////////////////////////////////////////////////////////////////////////////
int Sig_ex_f()
{
//объявление индикаторов
double ind1 = iCustom(Symbol(),0,"Heiken_ashi_nonlagma_v4",Price,Length,Displace,Filter,Color,ColorBarBack,Deviation,1,1); //exit sell
double ind2 = iCustom(Symbol(),0,"Heiken_ashi_nonlagma_v4",Price,Length,Displace,Filter,Color,ColorBarBack,Deviation,2,1); //exit buy


//сигнал для выход селл
if(ind1<50000) return(1);

//сигнал для выход бай
if(ind2<50000) return(-1);



return(0);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double GetLot()
{
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(Lot<Min_Lot) Lot=Min_Lot;
if(Lot>Max_Lot) Lot=Max_Lot;
if(Lot*One_Lot>Free) return(0.0);

return(Lot);
}

////////////////////////////////////////////////////////////////
void BezUb()
{
for (int i=OrdersTotal()-1; i>=0; i--)
{
OrderSelect(i, SELECT_BY_POS);
{
if (OrderMagicNumber()==magic)
{
if (OrderType()==OP_BUY)
{
if(OrderStopLoss()!=OrderOpenPrice()+NormalizeDouble(Bez_Ub_Size*Point,Digits))
{
if (Bid>OrderOpenPrice()+Bez_Ub_Level*Point && (OrderStopLoss()<OrderOpenPrice() || OrderStopLoss()==0))
{
OrderModify(OrderTicket(),0,OrderOpenPrice()+NormalizeDouble(Bez_Ub_Size*Point,Digits),OrderTakeProfit(),0,Blue);
}
}
}


if (OrderType()==OP_SELL)
{
if(OrderStopLoss()!=OrderOpenPrice()-NormalizeDouble(Bez_Ub_Size*Point,Digits))
{
if (Ask<OrderOpenPrice()-Bez_Ub_Level*Point && (OrderStopLoss()>OrderOpenPrice() || OrderStopLoss()==0))
{
OrderModify(OrderTicket(),0,OrderOpenPrice()-NormalizeDouble(Bez_Ub_Size*Point,Digits),OrderTakeProfit(),0,Blue);
}
}
}
}
}
}
}

///////////////////////////////////////////////////////////////////////////
void Traling_Stop_f()
{
for (int i=OrdersTotal()-1; i>=0; i--)
{
OrderSelect(i, SELECT_BY_POS);
{
if (OrderMagicNumber()==magic)
{
double Or_St_Lo = OrderStopLoss();
double Or_Op_Pr = OrderOpenPrice();
if(Or_St_Lo==0) Or_St_Lo=Or_Op_Pr;
if((OrderStopLoss()!=Or_St_Lo+NormalizeDouble(Trailing_Stop*Point,Digits)) || (OrderStopLoss()!=Or_St_Lo-NormalizeDouble(Trailing_Stop*Point,Digits)))
{
if (OrderType()==OP_BUY && Bid-Or_St_Lo>=Trailing_Stop*Point && Bid>Or_St_Lo && ((Bid-Or_St_Lo+Trailing_Stop*Point)/Point>MarketInfo(Symbol(),MODE_STOPLEVEL))) OrderModify(OrderTicket(),0,Or_St_Lo+NormalizeDouble(Trailing_Stop*Point,Digits),OrderTakeProfit(),0,LightBlue);
if(OrderType()==OP_SELL && Or_St_Lo-Ask>=Trailing_Stop*Point && Ask<Or_St_Lo && ((Or_St_Lo-Trailing_Stop*Point-Ask)/Point>MarketInfo(Symbol(),MODE_STOPLEVEL))) OrderModify(OrderTicket(),0,Or_St_Lo-NormalizeDouble(Trailing_Stop*Point,Digits),OrderTakeProfit(),0,OrangeRed);
}
}
}
}

}

///////////////////////////////////////////////////////////////////////////////////
void martini_f()
{
int nor_lot;
if(MarketInfo(Symbol(),MODE_LOTSTEP)==0.1) nor_lot=1;
if(MarketInfo(Symbol(),MODE_LOTSTEP)==0.01) nor_lot=2;

CountOpenPositions();

double Mar_Lot_b=Lot*buy*Lot_koef;
double Mar_Lot_s=Lot*sell*Lot_koef;

for(int i=OrdersTotal()-1; i>=0; i--)
{
OrderSelect(i,SELECT_BY_POS);
{
if(OrderMagicNumber()==magic)
{
if(OrderSymbol()==Symbol())
{
break;
}
}
}
}



if(OrderType()==OP_BUY)
{
//
if(Bid<=OrderOpenPrice()-step*Point) OrderSend(Symbol(),OP_BUY,NormalizeDouble(Mar_Lot_b,nor_lot),Ask,slippage,0,0,comment,magic,0,Green);
}


if(OrderType()==OP_SELL)
{
//
if(Ask>=OrderOpenPrice()+step*Point) OrderSend(Symbol(),OP_SELL,NormalizeDouble(Mar_Lot_s,nor_lot),Bid,slippage,0,0,comment,magic,0,OrangeRed);
}



}

///////////////////////////////////////////////////////////////////////////////////
int Profit_f()
{
int prof;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS)==true)
{
if(OrderMagicNumber()==magic)
{
if (OrderType()==OP_BUY) prof+=(Bid - OrderOpenPrice())/Point;
if (OrderType()==OP_SELL) prof+=(OrderOpenPrice()-Ask) /Point;
}
}
}

return(prof);
}

////////////////////////////////////////////////////////////////////////////////////
void CountOpenPositions()
{
buy=0;
sell=0;

for (int i=OrdersTotal()-1; i>=0; i--)
{
OrderSelect(i,SELECT_BY_POS);
{
if(OrderMagicNumber()==magic)
{
if(OrderType()==OP_BUY) buy++;
if(OrderType()==OP_SELL) sell++;
}
}
}

}

////////////////////////////////////////////////////////////////////////////////
void Close_f()
{
for(int i=OrdersTotal()-1; i>=0; i--)
{
OrderSelect(i,SELECT_BY_POS);
{
if(OrderMagicNumber()==magic)
{
if(OrderSymbol()==Symbol())
{
bool ticket_ex;
for (int j_ex = 0;j_ex < MaxAttempts; j_ex++)
{
while(IsTradeContextBusy()) Sleep(2000);

if(OrderType()==OP_BUY ) ticket_ex=OrderClose(OrderTicket(),OrderLots(),Bid,slippage,Yellow);
if(OrderType()==OP_SELL) ticket_ex=OrderClose(OrderTicket(),OrderLots(),Ask,slippage,Yellow);
if(OrderType()==OP_SELLSTOP || OrderType()==OP_BUYSTOP || OrderType()==OP_SELLLIMIT || OrderType()==OP_BUYLIMIT) ticket_ex=OrderDelete(OrderTicket(),CLR_NONE);
if(ticket_ex==true)break;
}
}
}
}
}

}

Obrigado de antemão!
 

A documentação diz que a função SetIndexEmptyValue é usada para especificar um valor "vazio". Ou seja, especificamos a que valor não precisamos extrair nada. É muito conveniente em nosso caso, pois os sinais não ocorrem em todos os bares. Funciona da seguinte forma. Quando você não precisa desenhar a seta na barra atual, você atribui um valor "vazio" para a entrada apropriada do buffer de dados, em nosso caso 0.

Algo que eu não entendo. Se algo for desenhado pelo sinal, não será desenhado sem o sinal. Então, qual é o objetivo desta função em geral?

 
Elektronik:

Tudo já foi feito para você e funciona bem

KimIV01.11.2006 18:49

Eu recomendo meu código testado e comprovado



https://forum.mql4.com/ru/4689


Obrigado pela resposta, mas gostaria de saber porque não funciona para mim:)
Razão: