Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 62

 

Guys, what's the best way to do it: I want to see the distribution of strikes from losing and profitable trades... I'm not good at arrays.

After a losing Sell

Price_LastSell=5; Vol=Vol*Y; Izm=2; Opn_B=true; k=k+1;

/* Buf1[p]=Buf1[p]+1; p=0;

Alert ("Profitable ", Buf1[1], ", ", Buf1[2], ", ", Buf1[3], ", ", Buf1[4], ", ", Buf1[5], ", ", Buf1[6], ", ", Buf1[7], ", ", Buf1[8], ", Buf1[9], ", Buf1[10]); */

after the profitable sell

Price_LastSell=5; Vol=VolumeOpen; Izm=2; Opn_S=true; p=p+1;

/* Buf2[k]=Buf2[k]+1; k=0;

Alert ("Losses ", Buf2[1], ", ", Buf2[2], ", ", Buf2[3], ", ", Buf2[4], ", ", Buf2[5], ",", Buf2[6], ", ", ", Buf2[7], ", ", Buf2[8], ", ", Buf2[9], ", ", Buf2[10], ", ", Buf2[11], ", ", Buf2[12], ", ", Buf2[13], ", ", Buf2[14], ", Buf2[15]); */

What's wrong here? Without writing to /* everything works fine...

 
Сергей:

Guys, what's the best way to do it: I want to see the distribution of strikes from losing and profitable trades... I'm not good at arrays.

After a losing Sell

Price_LastSell=5; Vol=Vol*Y; Izm=2; Opn_B=true; k=k+1;

/* Buf1[p]=Buf1[p]+1; p=0;

Alert ("Profitable ", Buf1[1], ", ", Buf1[2], ", ", Buf1[3], ", ", Buf1[4], ", ", Buf1[5], ", ", Buf1[6], ", ", Buf1[7], ", ", Buf1[8], ", Buf1[9], ", Buf1[10]); */

after the profitable sell

Price_LastSell=5; Vol=VolumeOpen; Izm=2; Opn_S=true; p=p+1;

/* Buf2[k]=Buf2[k]+1; k=0;

Alert ("Losses ", Buf2[1], ", ", Buf2[2], ", ", Buf2[3], ", ", Buf2[4], ", ", Buf2[5], ",", Buf2[6], ", ", ", Buf2[7], ", ", Buf2[8], ", ", Buf2[9], ", ", Buf2[10], ", ", Buf2[11], ", ", Buf2[12], ", ", Buf2[13], ", ", Buf2[14], ", Buf2[15]); */

What's wrong here? Without writing to /* everything works fine...

Uh-oh... Who are the "stricks" and what is "their distribution"?
 

A series of losing and profitable trades. Distribution - for example we have 360 losing trades (this can be seen in the report), 110 series of 1 losing trade, 80 series of 2 losing trades and 30 of 3 losing trades.

I did it this way:

After identifying the losing trade

k=k+1;

After determining a profitable trade

if k==1 {k1=k1+1;}

if k==2 {k2=k2+1;}

if k==3 {k3=k3+1;}

k=0;

But this entry is too big and inconvenient for series of 15 or more losses

 
Сергей:

A series of losing and profitable trades. Distribution - for example we have 360 losing trades (this can be seen in the report), 110 series of 1 losing trade, 80 series of 2 losing trades and 30 of 3 losing trades.

I did it this way:

After identifying the losing trade

k=k+1;

After determining a profitable trade

if k==1 {k1=k1+1;}

if k==2 {k2=k2+1;}

if k==3 {k3=k3+1;}

k=0;

But this notation is too big and inconvenient for series of 15 or more losses

I'm not quite clear on your task.

Do you need to determine the series of the last profitable/loss-making positions, or do you need to collect all of these series from the entire trading history?

 
Throughout the history. Collect and output data at the end of the test. But I do it simply: after the first profit after a series of losses I output a comma-separated number... But I want to simplify the code and use arrays. Is it possible? And what is the best way to do it?
 
Ibragim Dzhanaev:

Did this, now it does not open on every tick, but passes signals to input...

double tp,sl,OrderBuy=0,OrderSell=0;
double slSell,slBuy,tpSell,tpBuy,TotalBiu,TotalSell;
int tiket;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {

   for(int i=OrdersTotal()-1; i>=0; i--) //Цикл по всем ордерам
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) //Выбрали ордер
        {
         if(OrderType()==OP_BUY)
           {
            TotalBiu++;                      //Кол. покупок
           }
         if(OrderType()==OP_SELL)
           {
            TotalSell++;                     //Кол. продаж
           }
        }
     }
   double rsi=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,0);
   double rsi1=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,1);
//+------------------------------------------------------------------+

   double StopLossLevel;
   double TakeProfitLevel;
   if(StopLoss>0) StopLossLevel=Bid-StopLoss*Point; else StopLossLevel=0.0;
   if(TakeProfit>0) TakeProfitLevel=Ask+TakeProfit*Point; else TakeProfitLevel=0.0;

   tpBuy=NormalizeDouble(Ask+TakeProfit*_Point,_Digits);
   slBuy=NormalizeDouble(Bid-StopLoss*_Point,_Digits);

   tpSell=NormalizeDouble(Bid-TakeProfit*_Point,_Digits);
   slSell=NormalizeDouble(Ask+StopLoss*_Point,_Digits);
///---
if(TotalBiu==0)
   if(OrderBuy<1 && rsi>Urov_70 && rsi1<Urov_70)
     {
      tiket=OrderSend(_Symbol,OP_BUY,Lot,Ask,slippage,slBuy,tpBuy,NULL,MagicNumber,0,clrBlue);      
     }
      if(TotalSell==0)    
   if(OrderSell<1 && rsi<Urov_30 && rsi1>Urov_30)
     {
      tiket=OrderSend(_Symbol,OP_SELL,Lot,Bid,slippage,slSell,tpSell,NULL,MagicNumber,0,clrRed);      
     }
  }
//+------------------------------------------------------------------+


tweaked it. Should work.

double tp,sl,OrderBuy=0,OrderSell=0;
double slSell,slBuy,tpSell,tpBuy,TotalBiu,TotalSell;
int tiket;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {

   for(int i=OrdersTotal()-1; i>=0; i--) //Цикл по всем ордерам
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) //Выбрали ордер
        {
         if(OrderType()==OP_BUY)
           {
            OrderBuy++;                      //Кол. покупок
           }
         if(OrderType()==OP_SELL)
           {
            OrderSell++;                     //Кол. продаж
           }
        }
     }
   double rsi=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,0);
   double rsi1=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,1);
//+------------------------------------------------------------------+

   double StopLossLevel;
   double TakeProfitLevel;
   if(StopLoss>0) StopLossLevel=Bid-StopLoss*Point; else StopLossLevel=0.0;
   if(TakeProfit>0) TakeProfitLevel=Ask+TakeProfit*Point; else TakeProfitLevel=0.0;

   tpBuy=NormalizeDouble(Ask+TakeProfit*_Point,_Digits);
   slBuy=NormalizeDouble(Bid-StopLoss*_Point,_Digits);

   tpSell=NormalizeDouble(Bid-TakeProfit*_Point,_Digits);
   slSell=NormalizeDouble(Ask+StopLoss*_Point,_Digits);
///---
   if(OrderBuy==0 && rsi>Urov_70 && rsi1<Urov_70)
     {
      tiket=OrderSend(_Symbol,OP_BUY,Lot,Ask,slippage,slBuy,tpBuy,NULL,MagicNumber,0,clrBlue);  
      if(ticket<0)Print("Ошибка открытия ордера № - ",GetLastError());    
     }
   if(OrderSell==0 && rsi<Urov_30 && rsi1>Urov_30)
     {
      tiket=OrderSend(_Symbol,OP_SELL,Lot,Bid,slippage,slSell,tpSell,NULL,MagicNumber,0,clrRed);  
      if(ticket<0)Print("Ошибка открытия ордера № - ",GetLastError());    
     }
  }
//+------------------------------------------------------------------+

...

 
Sergey Gritsay:

Fixed it. It should work.

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {

   for(int i=OrdersTotal()-1; i>=0; i--) //Цикл по всем ордерам
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) //Выбрали ордер
        {
         if(OrderType()==OP_BUY)
           {
            OrderBuy++;                      //Кол. покупок
           }
         if(OrderType()==OP_SELL)
           {
            OrderSell++;                     //Кол. продаж
           }
        }
     }
   double rsi=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,0);
   double rsi1=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,1);
//+------------------------------------------------------------------+


kinda need to zero out the highlighted

double tp,sl,OrderBuy=0,OrderSell=0;
double slSell,slBuy,tpSell,tpBuy;
int tiket;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
  OrderBuy=0; OrderSell=0;
//-
   for(int i=OrdersTotal()-1; i>=0; i--) //Цикл по всем ордерам
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) //Выбрали ордер
        {
         if(OrderType()==OP_BUY)
           {
            OrderBuy++;                      //Кол. покупок
           }
         if(OrderType()==OP_SELL)
           {
            OrderSell++;                     //Кол. продаж
           }
        }
     }
   double rsi=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,0);
   double rsi1=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,1);
//+------------------------------------------------------------------+
   tpBuy=NormalizeDouble(Ask+TakeProfit*_Point,_Digits);
   slBuy=NormalizeDouble(Bid-StopLoss*_Point,_Digits);

   tpSell=NormalizeDouble(Bid-TakeProfit*_Point,_Digits);
   slSell=NormalizeDouble(Ask+StopLoss*_Point,_Digits);
///---
   if(OrderBuy==0 && rsi>Urov_70 && rsi1<Urov_70)
     {
      tiket=OrderSend(_Symbol,OP_BUY,Lot,Ask,slippage,slBuy,tpBuy,NULL,MagicNumber,0,clrBlue);  
      if(ticket<0)Print("Ошибка открытия ордера № - ",GetLastError());    
     }
   if(OrderSell==0 && rsi<Urov_30 && rsi1>Urov_30)
     {
      tiket=OrderSend(_Symbol,OP_SELL,Lot,Bid,slippage,slSell,tpSell,NULL,MagicNumber,0,clrRed);  
      if(ticket<0)Print("Ошибка открытия ордера № - ",GetLastError());    
     }
  }
//+------------------------------------------------------------------+
 
Vitaly Muzichenko:

sort of need to zero in on the highlighted

double tp,sl,OrderBuy=0,OrderSell=0;
double slSell,slBuy,tpSell,tpBuy;
int tiket;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
  OrderBuy=0; OrderSell=0;
//-
   for(int i=OrdersTotal()-1; i>=0; i--) //Цикл по всем ордерам
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) //Выбрали ордер
        {
         if(OrderType()==OP_BUY)
           {
            OrderBuy++;                      //Кол. покупок
           }
         if(OrderType()==OP_SELL)
           {
            OrderSell++;                     //Кол. продаж
           }
        }
     }
   double rsi=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,0);
   double rsi1=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,1);
//+------------------------------------------------------------------+
   tpBuy=NormalizeDouble(Ask+TakeProfit*_Point,_Digits);
   slBuy=NormalizeDouble(Bid-StopLoss*_Point,_Digits);

   tpSell=NormalizeDouble(Bid-TakeProfit*_Point,_Digits);
   slSell=NormalizeDouble(Ask+StopLoss*_Point,_Digits);
///---
   if(OrderBuy==0 && rsi>Urov_70 && rsi1<Urov_70)
     {
      tiket=OrderSend(_Symbol,OP_BUY,Lot,Ask,slippage,slBuy,tpBuy,NULL,MagicNumber,0,clrBlue);  
      if(ticket<0)Print("Ошибка открытия ордера № - ",GetLastError());    
     }
   if(OrderSell==0 && rsi<Urov_30 && rsi1>Urov_30)
     {
      tiket=OrderSend(_Symbol,OP_SELL,Lot,Bid,slippage,slSell,tpSell,NULL,MagicNumber,0,clrRed);  
      if(ticket<0)Print("Ошибка открытия ордера № - ",GetLastError());    
     }
  }
//+------------------------------------------------------------------+

Thanks. Now opens some orders not on signal and some not correctly.

 
Sergey Gritsay:

Fixed it. It should work.

 

...

What you wrote didn't help...
 
Ibragim Dzhanaev:

Thank you. Now opens some orders not on signal and some not correctly.

You check on an existing bar double rsi=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,0);

The price goes up, there is a cross of level 70 and entry into the trade. On the fact of closing the bar, you already see that the RSI is lower, but before that it was higher, and then returned below the level.

Do the check on a closed bar, then this will not happen, and entries will be on a confirmed signal:

double rsi=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,1);

double rsi1=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,2);

Reason: