Toute question des nouveaux arrivants sur MQL4 et MQL5, aide et discussion sur les algorithmes et les codes. - page 1657

 
artem artem #:
J'ai joint une capture d'écran. Si vous ne comprenez pas quelque chose, n'hésitez pas à demander.

Cela devrait fonctionner

#define  MagicNumber  122122
extern string s1             = "Trading options";
extern double Lot            = 0.01;    // размер лота 0 - авт.расчет
extern double StopLoss       = 40;     // стоплосс
extern double TakeProfit     = 10;     // тейкпрофит
extern double TrailStop      = 21;     // уровень без убытка
extern int    Trailing       = 0;      // трейлинг стоп 1 вкл. 0 выкл.
extern int    Breakeven      = 0;      // перенос стоп лосса в без убыток
extern string s2             = "Day & Hour";
extern int    HrStart        = 0;      // время начала торговли
extern int    HrEnd          = 23;     // время окончания торговли
extern int    Monday         = 1;      // Понедельник 1 вкд. 0 выкл.
extern int    Tuesday        = 1;      // Вторник
extern int    Wednesday      = 1;      // Среда
extern int    Thursday       = 1;      // Четверг
extern int    Friday         = 1;      // Пятница
//+------------------------------------------------------------------+
// параметры индикаторов
double MovingPeriodLw        = 5;      
double MovingPeriodS1        = 75;
double MovingPeriodS2        = 85;
double StopLevel;
double TrailStep             = 3;      // шаг трейлинг стопа
bool OrderBuy = true, OrderSell = true, Order = false, Init = true;
int timeprev = 0, Slip = 3.0;

//+------------------------------------------------------------------+
//| Init function                                                    |
//+------------------------------------------------------------------+
void OnInit()
{
   if (Digits == 3 || Digits == 5) { // Пересчет для 5-ти знаков                                                    
      TakeProfit *= 10;
      TrailStop *= 10;
      TrailStep *= 10;
      StopLoss *=10;
      Slip *=10;
   } 
   return; 
}
//+------------------------------------------------------------------+
//| Start function                                                   |
//+------------------------------------------------------------------+
void start()
{
   StopLevel = MarketInfo(Symbol(), MODE_STOPLEVEL); 
   CheckForOpen();
   // Определение направления пересечения мувингов
   if (Init) InitMetod(); 
   
   // Трейлинг стоп открытых позиций
   if (Trailing != 0 ) RealTrailOrder(TrailStop, TrailStep, StopLevel, MagicNumber);
   
   // Ожидание нового бара на графике
   if(timeprev == Time[0]) return;
   timeprev = Time[0];
   
   // Открытие ордера по методу Пуриа
   if(CheckForOpen()==0 && OrderBuy==true) // Если сигнал для покупок 
     {
      if(OrderSend(Symbol(),OP_BUY,Lots(),Ask,Slip,Bid-StopLoss*Point,Ask+TakeProfit*Point,"",MagicNumber,0,Blue))
        {OrderBuy=false; Print("BUY OK");}
     } 
   if(CheckForOpen()==1 && OrderSell==true) // Если сигнал для продаж 
     {
      if(OrderSend(Symbol(),OP_SELL,Lots(),Bid,Slip,Ask+StopLoss*Point,Bid-TakeProfit*Point,"",MagicNumber,0,Red))
        {OrderSell=false; Print("SELL OK");}
     }
  }
//+------------------------------------------------------------------+
//| Check for open order conditions                                  |
//+------------------------------------------------------------------+
int CheckForOpen() // Открытие ордера по методу Пуриа
  {
   double malw,mas1,mas2,macd;
   int    res=-1, buy=0, sell=0;
   // Считывание параметров индикаторов 3 свечи (4ой)
   malw=iMA(NULL,0,MovingPeriodLw,0,MODE_EMA,PRICE_CLOSE,3);
   mas1=iMA(NULL,0,MovingPeriodS1,0,MODE_LWMA,PRICE_LOW,3);
   mas2=iMA(NULL,0,MovingPeriodS2,0,MODE_LWMA,PRICE_LOW,3);
   macd=iMACD(NULL,0,15,26,1,PRICE_CLOSE,MODE_MAIN,3);
   if(malw>mas1&&malw>mas2&&macd>0) {buy+=1; sell=0;}
   if(malw<mas1&&malw<mas2&&macd<0) {buy=0; sell+=1;}
   // Считывание параметров индикаторов 2 свечи (3ей)
   malw=iMA(NULL,0,MovingPeriodLw,0,MODE_EMA,PRICE_CLOSE,2);
   mas1=iMA(NULL,0,MovingPeriodS1,0,MODE_LWMA,PRICE_LOW,2);
   mas2=iMA(NULL,0,MovingPeriodS2,0,MODE_LWMA,PRICE_LOW,2);
   macd=iMACD(NULL,0,15,26,1,PRICE_CLOSE,MODE_MAIN,2);
   if(malw>mas1&&malw>mas2&&macd>0) {buy+=1; sell=0;}
   if(malw<mas1&&malw<mas2&&macd<0) {buy=0; sell+=1;}
   // Считывание параметров индикаторов 1 свечи (2ой)
   malw=iMA(NULL,0,MovingPeriodLw,0,MODE_EMA,PRICE_CLOSE,1);
   mas1=iMA(NULL,0,MovingPeriodS1,0,MODE_LWMA,PRICE_LOW,1);
   mas2=iMA(NULL,0,MovingPeriodS2,0,MODE_LWMA,PRICE_LOW,1);
   macd=iMACD(NULL,0,15,26,1,PRICE_CLOSE,MODE_MAIN,1);
   if(malw>mas1&&malw>mas2&&macd>0) {buy+=1; sell=0;}
   if(malw<mas1&&malw<mas2&&macd<0) {buy=0; sell+=1;}
   // Считывание параметров индикаторов 0 свечи (1ой)
   malw=iMA(NULL,0,MovingPeriodLw,0,MODE_EMA,PRICE_CLOSE,0);
   mas1=iMA(NULL,0,MovingPeriodS1,0,MODE_LWMA,PRICE_LOW,0);
   mas2=iMA(NULL,0,MovingPeriodS2,0,MODE_LWMA,PRICE_LOW,0);
   macd=iMACD(NULL,0,15,26,1,PRICE_CLOSE,MODE_MAIN,0);
   if(malw>mas1&&malw>mas2&&macd>0) {buy+=1; sell=0;}
   if(malw<mas1&&malw<mas2&&macd<0) {buy=0; sell+=1;}
   
   if(buy ==4) { res=0; OrderSell=true;} 
   if(sell==4) { res=1; OrderBuy =true;}
   return(res);
  }
 
artem artem #:
J'ai joint une capture d'écran, si vous ne comprenez pas quelque chose, demandez-le moi.

Compilez-le pour qu'il ne vous gêne pas.

if (Init) InitMetod(); 
 
SanAlex #:

Essayez celui-ci - s'ouvrira-t-il dans ces endroits ?

C'est ainsi qu'il s'ouvre - comment devrait-il s'ouvrir ?

EURUSDH1

 
SanAlex #:

C'est ainsi qu'il s'ouvre - comment devrait-il s'ouvrir ?



 
MakarFX #:

c'est comme ça que ça s'ouvre - et j'y ai fait un tour.

EURUSDH1 2

et c'est ainsi que vous mettez le code ci-dessus.

EURUSDH1 3

 
MakarFX, j'ai regardé, il s'ouvre à la fois à l'achat et à la vente, rien de mal à cela. Mais toujours aucune réaction au passage du MACD du côté opposé, alors que le rapide reste le même. Par conséquent, si le MACD retourne vers le rapide et passe 4 bougies de confirmation, il n'y a pas d'entrée d'ordre. J'ai joint une capture d'écran à ce message pour clarifier ce que je veux dire.
Dossiers :
 
artem artem #:
Ci-joint une capture d'écran. Si vous ne comprenez pas quelque chose, demandez.

Je l'ai un peu modifié

#define  MagicNumber  122122
extern string s1             = "Trading options";
extern double Lot            = 0.01;    // размер лота 0 - авт.расчет
extern double StopLoss       = 40;     // стоплосс
extern double TakeProfit     = 10;     // тейкпрофит
extern double TrailStop      = 21;     // уровень без убытка
extern int    Trailing       = 0;      // трейлинг стоп 1 вкл. 0 выкл.
extern int    Breakeven      = 0;      // перенос стоп лосса в без убыток
extern string s2             = "Day & Hour";
extern int    HrStart        = 0;      // время начала торговли
extern int    HrEnd          = 23;     // время окончания торговли
extern int    Monday         = 1;      // Понедельник 1 вкд. 0 выкл.
extern int    Tuesday        = 1;      // Вторник
extern int    Wednesday      = 1;      // Среда
extern int    Thursday       = 1;      // Четверг
extern int    Friday         = 1;      // Пятница
//+------------------------------------------------------------------+
// параметры индикаторов
double MovingPeriodLw        = 5;      
double MovingPeriodS1        = 75;
double MovingPeriodS2        = 85;
double StopLevel;
double TrailStep             = 3;      // шаг трейлинг стопа
bool OrderBuy = true, OrderSell = true, Order = false, Init = true;
int timeprev = 0, Slip = 3.0;

//+------------------------------------------------------------------+
//| Init function                                                    |
//+------------------------------------------------------------------+
void OnInit()
{
   if (Digits == 3 || Digits == 5) { // Пересчет для 5-ти знаков                                                    
      TakeProfit *= 10;
      TrailStop *= 10;
      TrailStep *= 10;
      StopLoss *=10;
      Slip *=10;
   } 
   return; 
}
//+------------------------------------------------------------------+
//| Start function                                                   |
//+------------------------------------------------------------------+
void start()
{
   StopLevel = MarketInfo(Symbol(), MODE_STOPLEVEL); 
   CheckForOpen();
   // Определение направления пересечения мувингов
//   if (Init) InitMetod(); 
   
   // Трейлинг стоп открытых позиций
   if (Trailing != 0 ) RealTrailOrder(TrailStop, TrailStep, StopLevel, MagicNumber);
   
   // Ожидание нового бара на графике
   if(timeprev == Time[0]) return;
   timeprev = Time[0];
   
   // Открытие ордера по методу Пуриа
   if(CheckForOpen()==0 && OrderBuy==true) // Если сигнал для покупок 
     {
      if(OrderSend(Symbol(),OP_BUY,Lots(),Ask,Slip,Bid-StopLoss*Point,Ask+TakeProfit*Point,"",MagicNumber,0,Blue))
        {OrderBuy=false; Print("BUY OK");}
     } 
   if(CheckForOpen()==1 && OrderSell==true) // Если сигнал для продаж 
     {
      if(OrderSend(Symbol(),OP_SELL,Lots(),Bid,Slip,Ask+StopLoss*Point,Bid-TakeProfit*Point,"",MagicNumber,0,Red))
        {OrderSell=false; Print("SELL OK");}
     }
  }
//+------------------------------------------------------------------+
//| Check for open order conditions                                  |
//+------------------------------------------------------------------+
int CheckForOpen() // Открытие ордера по методу Пуриа
  {
   double malw,mas1,mas2,macd;
   int    res=-1, buy=0, sell=0;
   // Считывание параметров индикаторов 3 свечи (4ой)
   malw=iMA(NULL,0,MovingPeriodLw,0,MODE_EMA,PRICE_CLOSE,3);
   mas1=iMA(NULL,0,MovingPeriodS1,0,MODE_LWMA,PRICE_LOW,3);
   mas2=iMA(NULL,0,MovingPeriodS2,0,MODE_LWMA,PRICE_LOW,3);
   macd=iMACD(NULL,0,15,26,1,PRICE_CLOSE,MODE_MAIN,3);
   if(malw>mas1&&malw>mas2&&macd>0) {buy+=1; sell=0;}
   if(malw<mas1&&malw<mas2&&macd<0) {buy=0; sell+=1;}
   // Считывание параметров индикаторов 2 свечи (3ей)
   malw=iMA(NULL,0,MovingPeriodLw,0,MODE_EMA,PRICE_CLOSE,2);
   mas1=iMA(NULL,0,MovingPeriodS1,0,MODE_LWMA,PRICE_LOW,2);
   mas2=iMA(NULL,0,MovingPeriodS2,0,MODE_LWMA,PRICE_LOW,2);
   macd=iMACD(NULL,0,15,26,1,PRICE_CLOSE,MODE_MAIN,2);
   if(malw>mas1&&malw>mas2&&macd>0) {buy+=1; sell=0;}
   if(malw<mas1&&malw<mas2&&macd<0) {buy=0; sell+=1;}
   // Считывание параметров индикаторов 1 свечи (2ой)
   malw=iMA(NULL,0,MovingPeriodLw,0,MODE_EMA,PRICE_CLOSE,1);
   mas1=iMA(NULL,0,MovingPeriodS1,0,MODE_LWMA,PRICE_LOW,1);
   mas2=iMA(NULL,0,MovingPeriodS2,0,MODE_LWMA,PRICE_LOW,1);
   macd=iMACD(NULL,0,15,26,1,PRICE_CLOSE,MODE_MAIN,1);
   if(malw>mas1&&malw>mas2&&macd>0) {buy+=1; sell=0;}
   if(malw<mas1&&malw<mas2&&macd<0) {buy=0; sell+=1;}
   // Считывание параметров индикаторов 0 свечи (1ой)
   malw=iMA(NULL,0,MovingPeriodLw,0,MODE_EMA,PRICE_CLOSE,0);
   mas1=iMA(NULL,0,MovingPeriodS1,0,MODE_LWMA,PRICE_LOW,0);
   mas2=iMA(NULL,0,MovingPeriodS2,0,MODE_LWMA,PRICE_LOW,0);
   macd=iMACD(NULL,0,15,26,1,PRICE_CLOSE,MODE_MAIN,0);
   if(malw>mas1&&malw>mas2&&macd>0) {buy+=1; sell=0;}
   if(malw<mas1&&malw<mas2&&macd<0) {buy=0; sell+=1;}
   
   if(buy <4)  OrderBuy=true; 
   if(sell<4)  OrderSell=true;
   if(buy ==4) { res=0; OrderSell=true;} 
   if(sell==4) { res=1; OrderBuy =true;}
   return(res);
  }
 
artem artem #:

et voici l'image - les points de droite ? ??

EURUSDH1 4

 

MakarFX, dans votre dernière édition, l'ordre est ouvert à partir de la 1ère bougie si la rapide a traversé la lente et est ensuite retournée dans la même zone où se trouve le MACD. Et il doit être confirmé 4 fois et l'ordre doit s'ouvrir sur la 4ème bougie. J'ai joint un fichier pour que ce soit plus clair visuellement.


SanAlex, pouvez-vous zoomer pour avoir des barres MACD clairement visibles et la vitesse à laquelle on croise les lentes ? Je peux à peine le voir.

Dossiers :
 
artem artem le MACD. Et il doit être confirmé 4 fois et l'ordre doit s'ouvrir sur la 4ème bougie. J'ai joint un fichier pour que ce soit plus clair visuellement.


SanAlex, pouvez-vous zoomer pour avoir des barres MACD clairement visibles et la vitesse à laquelle on croise les lentes ? Je peux à peine le voir.

Il s'avère que le taureau a changé lorsque le rapide croise le lent et le signal sur la barre suivante recalcule l'état actuel et ouvre le trade.

Je comprends le problème, mais je ne sais pas comment le résoudre...

Raison: