[ARCHIVE !] Toute question de débutant, pour ne pas encombrer le forum. Professionnels, ne passez pas à côté. Nulle part sans toi - 4. - page 469

 

Bonjour à tous.

J'ai une question à propos du tutoriel MQL4.

Lorsque l'on passe la MA par le haut ou par le bas, elle ne donne aucun message ?

Veuillez écrire ce qui ne va pas.

bool Fact_Up= true;
bool Fact_Dn = true;
//-----------------------------------------------------------------
int start()
   {
   double MA;
//-----------------------------------------------------------------
   MA= iMA(NULL,0,Period_MA,0,MODE_SMA,PRICE_CLOSE,0);
//-----------------------------------------------------------------
   if(Bid > MA && Fact_Up == true)
      {
      Fact_Dn = true;
      Fact_Up = false;
      Alert("Цена находится выше МА(",Period_MA,").");
      }
//------------------------------------------------------------------
   if(Bid < MA && Fact_Dn == true)
      {
      Fact_Up = true;
      Fact_Dn = false;
      Alert("Цена находится ниже МА(",Period_MA,").");
      }
//------------------------------------------------------------------
   return;
}
 
Pacman:

Bonjour à tous.

J'ai une question à propos du tutoriel MQL4.

Lorsque l'on passe la MA par le haut ou par le bas, elle ne donne aucun message ?

Veuillez écrire ce qui ne va pas.


Dans le testeur ?
 
PapaYozh:

Dans le testeur ?
Non, sur un compte de démonstration.
 

Bonjour,
Je suis en train de faire un EA qui déplace le stop au breakeven après l'ouverture. C'est-à-dire qu'il modifie l'ordre, mais le problème est qu'il modifie constamment ce qui ressemble à un stop suiveur. Comment le faire modifier une fois et seulement une fois. J'ai même inséré une variable dans le code que mod1=1 mais alors mod1 doit être plus grand, mais le langage pour une raison quelconque ne le remarque pas.

Merci !

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' - numéro invalide C:\Alpari\experts\customer.mq4 (66, 173) ? ??? Comment saisir correctement la couleur ?
 
kostikk:

Bonjour,
Je crée un conseiller qui déplace le stop au seuil de rentabilité après l'ouverture. C'est-à-dire qu'il modifie l'ordre, mais le problème est qu'il modifie constamment, quelque chose comme un stop suiveur. Comment le faire modifier une fois et seulement une fois. J'ai même ajouté une variable dans le code, mod1=1 mais mod1 doit être plus grand, mais le langage ne sait pas quel est le problème.

Merci !

Déjà fait pour vous et cela fonctionne bien

KimIV01.11.2006 18:49

Je recommande mon code testé
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' - numéro invalide C:\Alpari\experts\customer.mq4 (66, 173) ? ??? Comment saisir correctement la couleur ?


En fait, il existe un type spécial de variables dans la langue - la couleur est appelée. Par exemple :

double Velichina ;

MyLine ;

Velichina=2.569 ;

MaLigne=Rouge ;

 

Comment changer le nom de la fenêtre du graphique ?

 

Au secours ! Pour une raison quelconque, il n'ouvre pas de positions de VENTE, mais uniquement d'ACHAT.



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

}

Merci d'avance !
 

La documentation indique que la fonction SetIndexEmptyValue est utilisée pour spécifier une valeur "vide". C'est-à-dire que nous spécifions à partir de quelle valeur nous n'avons pas besoin de dessiner quoi que ce soit. C'est très pratique dans notre cas car les signaux ne se produisent pas sur chaque barre. Il fonctionne comme suit. Lorsque vous n'avez pas besoin de dessiner la flèche sur la barre actuelle, vous attribuez une valeur "vide" à l'entrée appropriée du tampon de données, dans notre cas 0.

Quelque chose que je ne comprends pas. Si quelque chose est dessiné par le signal, il ne sera pas dessiné sans le signal. Alors quel est le but de cette fonction en général ?

Raison: