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

 

if(OrderBuy<1&& rsi>Urov_70 && rsi1<Urov_70)
{
tiket=OrderSend(_Symbol,OP_BUY,Lot,Ask,slippage,sl,tp,NULL,MagicNumber,0,clrBlue);
}
if(OrderSell<1&& rsi<Urov_30 && rsi1>Urov_30)
{
tiket=OrderSend(_Symbol,OP_SELL,Lot,Bid,slippage,sl,tp,NULL,MagicNumber,0,clrRed);
}

but it needs

if(OrderBuy<1&& rsi>Urov_70 && rsi1<Urov_70)
{
tiket=OrderSend(_Symbol,OP_BUY,Lot,Ask,slippage,slBuy,tpBuy,NULL,MagicNumber,0,clrBlue);
}
if(OrderSell<1&& rsi<Urov_30 && rsi1>Urov_30)
{
tiket=OrderSend(_Symbol,OP_SELL,Lot,Bid,slippage,slSell,tpSell,NULL,MagicNumber,0,clrRed);
}

 
Ibragim Dzhanaev:

Didn't help (

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()
  {

   for(int i=0; i<OrdersTotal(); i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         if(OrderSymbol()==_Symbol && OrderMagicNumber()==MagicNumber)
           {
            if(OrderType()==OP_BUY){}
            if(OrderType()==OP_SELL){}
           }
     }
   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<1 && rsi>Urov_70 && rsi1<Urov_70)
     {
      tiket=OrderSend(_Symbol,OP_BUY,Lot,Ask,slippage,sl,tp,NULL,MagicNumber,0,clrBlue);      
     }      
   if(OrderSell<1 && rsi<Urov_30 && rsi1>Urov_30)
     {
      tiket=OrderSend(_Symbol,OP_SELL,Lot,Bid,slippage,sl,tp,NULL,MagicNumber,0,clrRed);      
     }
  }
//+------------------------------------------------------------------+


What do you even want with a code like that?

What, and what is it that didn't work?

 
RichLux:

if(OrderBuy<1&& rsi>Urov_70 && rsi1<Urov_70)
{
tiket=OrderSend(_Symbol,OP_BUY,Lot,Ask,sl,sl,tp,NULL,MagicNumber,0,clrBlue)
}
if(OrderSell<1&& rsi<Urov_30 && rsi1>Urov_30)
{
tiket=OrderSend(_Symbol,OP_SELL,Lot,Bid,sl,sl,tp,NULL,MagicNumber,0,clrRed);
}

but need to

if(OrderBuy<1&& rsi>Urov_70 && rsi1<Urov_70)
{
tiket=OrderSend(_Symbol,OP_BUY,Lot,Ask,slippage,slBuy,tpBuy,NULL,MagicNumber,0,clrBlue);
}
if(OrderSell<1&& rsi<Urov_30 && rsi1>Urov_30)
{
tiket=OrderSend(_Symbol,OP_SELL,Lot,Bid,slippage,slSell,tpSell,NULL,MagicNumber,0,clrRed);
}

At every tick opens (

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()
  {

   for(int i=0; i<OrdersTotal(); i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         if(OrderSymbol()==_Symbol && OrderMagicNumber()==MagicNumber)
           {
            if(OrderType()==OP_BUY){}
            if(OrderType()==OP_SELL){}
           }
     }
   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<1 && rsi>Urov_70 && rsi1<Urov_70)
     {
      tiket=OrderSend(_Symbol,OP_BUY,Lot,Ask,slippage,slBuy,tpBuy,NULL,MagicNumber,0,clrBlue);      
     }      
   if(OrderSell<1 && rsi<Urov_30 && rsi1>Urov_30)
     {
      tiket=OrderSend(_Symbol,OP_SELL,Lot,Bid,slippage,slSell,tpSell,NULL,MagicNumber,0,clrRed);      
     }
  }
//+------------------------------------------------------------------+
 
Artyom Trishkin:

What do you want with this code anyway?

What, and what didn't work there?

What's wrong with the code?

You need it not to open on every tick.

 
Ibragim Dzhanaev:
What's wrong with the code ?

That's not how it works.

Why search the position loop if it does nothing and returns nothing as a result?

Why do you check variables with zero values for less than one and expect it not to open on every tick?

There's a lot of nonsense to be honest...

 

i have the same problem, in the tester it opens on every tick though it should not

I put a crutch for the minimum number of orders to work but it is a patch, nothing more

 
trader781:

i have the same problem, in the tester it opens on every tick though it should not

I put a crutch for the minimum number of orders to work but it is a patch, nothing more

If you correctly count the number of open positions, then you don't need any crutches.
 
Artyom Trishkin:

It's all wrong.

Why search the position loop if it does nothing and returns nothing as a result?

Why do you check variables with zero values for less than one and expect it not to open on every tick?

And there's a lot of nonsense to be honest...

Fix it the right way.

If I had, I would have.

 
Artyom Trishkin:
If you correctly count the number of open positions, you don't need any crutches.

They should not be restricted in any way at all

In short, the condition is as follows


void OnTick()

  { 

 

 

 

if(OrdersTotal()==0) //+-------------если количество ордеров равно 0
       {
         if((MathAbs(ma2-ma4)>100*_Point)
            && (MathAbs(Bid-ma3)>100*Point())
            && (ma31>ma32>ma33)) //+-----покупка по 6+50
           {
            ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,50,0,0,"",Magic,0,clrAzure);//+------отправка 1 ордера
           }
         if((Bid+1000*Point)>ma3 && (Bid>ma1) && (Bid>ma2))//+-------------условие продажи
           {
            ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,50,0,0,"",Magic,0,clrAzure);//+-----отправка 1 ордера
           }
         if(ticket==0)
           {
            return;
           }
        }

      //+---------------------------------------------------------если уже есть

        
         if(FindLastOType()==OP_BUY)
           {
            if(Ask<=FindLastOrderOpenPrice()-Step*Point())//+------------если ордер в минус
              {
               ticket=OrderSend(Symbol(),OP_BUY,(FindLastLot()*Martin),Ask,50,0,0,"",Magic,0,clrAzure);
              }
            else
            if(Ask>=FindLastOrderOpenPrice()+Step*Point())//+------------если ордер в плюс
              {
               ticket=OrderSend(Symbol(),OP_BUY,(FindLastLot()*Martin),Ask,50,0,0,"",Magic,0,clrAzure);
              }
           }

         if(FindLastOType()==OP_SELL)
           {

            if(Bid>=FindLastOrderOpenPrice()+Step*Point())//+------------если ордер в минус
              {
               ticket=OrderSend(Symbol(),OP_SELL,(FindLastLot()*Martin),Bid,50,0,0,"",Magic,0,clrLightGray);
              }
            else
            if(Bid<=FindLastOrderOpenPrice()-Step*Point()) //+------------если ордер в плюс
              {
               ticket=OrderSend(Symbol(),OP_SELL,(FindLastLot()*Martin),Bid,50,0,0,"",Magic,0,clrLightGray);
              }
          
        
     }
   Trailingall();
  }
I need not to ignore the open step, which is 200 five or three digits.
 

Did this, now it doesn't open on every tick, but lets signals in...

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);      
     }
  }
//+------------------------------------------------------------------+
Reason: