[¡Archivo!] Cualquier pregunta de novato, para no saturar el foro. Profesionales, no pasen de largo. No puedo ir a ningún sitio sin ti - 4. - página 469

 
Pacman:

Hola a todos.

Tengo una pregunta del tutorial de MQL4.

Al pasar la MA por arriba o por abajo no da ningún mensaje?

Por favor, escriba lo que está mal.


¿En el probador?
 
PapaYozh:

¿En el probador?
No, en una cuenta demo.
 

Buenas tardes,
Estoy haciendo un EA que mueve el stop a breakeven después de la apertura. Es decir, modifica la orden, pero el problema es que modifica constantemente lo que parece un trailing stop. Cómo hacer que se modifique una vez y sólo una vez. Incluso he insertado una variable en el código que mod1=1 pero entonces mod1 tiene que ser mayor, pero el lenguaje por alguna razón no lo nota.

Gracias.

while(true)
{
if (tip==0 && open_b==true && mod1<=1 && Bid>ma+15*Point)
{
Alert("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++;
return;
}
return;
}
if (tip==1 && open_s==true && mod1<=1 && Bid<ma+15*Point)
{
Alert("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) ??? ¿Cómo introduzco el color correctamente?
 
kostikk:

Hola,
Estoy haciendo un asesor que mueve el stop a breakeven después de la apertura. Es decir, modifica la orden, pero el problema es que está modificando constantemente lo que es como un trailing stop. Cómo hacer que se modifique una vez y sólo una vez. Incluso he añadido una variable en el código, mod1=1 pero mod1 tiene que ser mayor, pero el lenguaje no sabe cuál es el problema.

Gracias.

Ya está hecho para usted y funciona bien

KimIV01.11.2006 18:49

Recomiendo mi código probado
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) ??? ¿Cómo introduzco el color correctamente?


En realidad hay un tipo especial de variables en el lenguaje - el color se llama. Por ejemplo:

doble Velichina;

MyLine;

Velichina=2,569;

MyLine=Rojo;

 

¿Cómo puedo cambiar el nombre de la ventana del gráfico?

 

¡Ayuda! Por alguna razón no abre posiciones de VENTA, sólo de COMPRA.



#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;
}
}
}
}
}

}

Gracias de antemano.
 

La documentación dice que la función SetIndexEmptyValue se utiliza para especificar un valor "vacío". Es decir, especificamos en qué valor no necesitamos dibujar nada en absoluto. Es muy conveniente en nuestro caso ya que las señales no se producen en cada barra. Funciona de la siguiente manera. Cuando no se necesita dibujar la flecha en la barra actual, se asigna un valor "vacío" a la entrada correspondiente del buffer de datos, en nuestro caso 0.

Hay algo que no entiendo. Si algo se dibuja con la señal, no se dibujará sin la señal. Entonces, ¿cuál es el objetivo de esta función en general?

 
Elektronik:

Ya se ha hecho todo por ti y funciona bien

KimIV01.11.2006 18:49

Recomiendo mi código probado y comprobado



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


Gracias por la respuesta, pero me gustaría saber por qué no me funciona:)
Razón de la queja: