[Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2. - page 149

 
Vovo4ka:

Guys, where is the error look....a then opens several positions at the signal, and sometimes misses the signals....a then after triggering a stop or profit on the pair, opens a new one....

Look.... conditions: simultaneous crossing of RSI with periods 14 and 17 of level 30 from bottom to top and uptrend 70 from top to bottom...


A1=diRSI1;
      A2=diRSI2;
why are they after the conditions?
 
Vovo4ka:

Guys, where is the error look....a then opens several positions at the signal, and sometimes misses the signals....a then after triggering a stop or profit on the pair, opens a new one....

Look.... conditions: simultaneous crossing of RSI with periods 14 and 17 of level 30 from bottom to top and uptrend 70 from top to bottom...


 if (( diRSI1<30 && diRSI2<30)){      
         OpenBuy();
         return(0);
      }

      if (diRSI1>70 && diRSI2>70){
         OpenSell();
         return(0);
      }
I would do it that way and I would also set a buy stop and not a sell
 
todem:
i would do it that way and i would set a buy Stop and not a sell


Ha... your way, with any value less than 30 opens a trade!!!!!!! this is unacceptable.... i need a 30 level cross from below to above!!!!!

and the values

A1=diRSI1;
      A2=diRSI2;

these are just the values of RSI of the previous candle opening.... they just have to be less than 30 !!! everything is correct here ... I just do not understand why trades are opened in a few pieces at a signal!

 
todem:
I would do it that way, and it would be set not immediately to buy but to bystop and not to sell but to sellstop
 
Vovo4ka:


Ha... your way any value less than 30 opens a trade!!!!!!! this is unacceptable.... i need a 30 level cross from the bottom up!!!!!

and the values

these are just the RSI values of the previous opening candle.... they just have to be less than 30 !!! everything is correct here ... I just don't understand why trades are opened several times at a signal !

If you want to get it to open one trade, you can't get it to open 386, it's much faster than that, which can execute a million trades in 1 second. Control the opening of one trade is done by controlling the open trades. If you have a total of 0 trades, open them, and if you don't, you're done.
 
todem:
If you want it to open one trade, it won't work - it's a 386 computer, and it's much faster, which makes a million trades in 1 second. Control opening of one trade is done by controlling opened trades. If you have a total of 0 trades, open them, and if you don't, you're done.


Hmmm... that's the point, if there are a million trades, then the deal should be opened once....

OK, I'll figure it out somehow))) if there's a code for controlling trades, let me know...please))

 
Vovo4ka:


Hmmm... that's the thing - if there are a million transactions, then the transaction should be opened by one transaction...

ok I'll figure it out somehow))) if there is a code for transaction control, please give it to me... please))

int OrdCon(int nap, int MGV)
  {
    int result=0;
    for (int i=0;i<OrdersTotal();i++) {
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if ((nap==0) && (OrderSymbol() == Symbol())&& (OrderMagicNumber() == MGV)) {
        result=result+1; // открыт ордер бай 
      }
      if ((nap==1) && (OrderSymbol() == Symbol()) && (OrderMagicNumber() == MGV)) {
        result=result+1; // открытый ордер селл 
      }
    }
    return(result); // 0 means we have no trades
  }
here's the function
 
todem:
here is the function

      if ((nap==0) && (OrderSymbol() == Symbol())&& (OrderMagicNumber() == MGV)) {
        result=result+1; // открыт ордер бай 
      }
      if ((nap==1) && (OrderSymbol() == Symbol()) && (OrderMagicNumber() == MGV)) {
        result=result+1; // открытый ордер селл 
      }

and at this point, on what basis is the conclusion that the open order is either a sell or a buy?

here is the whole code above:

int OrdCon(int nap, int MGV)
  {
    int result=0;
    for (int i=0;i<OrdersTotal();i++) {
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if ((nap==0) && (OrderSymbol() == Symbol())&& (OrderMagicNumber() == MGV)) {
        result=result+1; // открыт ордер бай 
      }
      if ((nap==1) && (OrderSymbol() == Symbol()) && (OrderMagicNumber() == MGV)) {
        result=result+1; // открытый ордер селл 
      }
    }
    return(result); // 0 means we have no trades
  }
 

Here I have optimised your PSI with my advisor

 
//+------------------------------------------------------------------+
//|                                               20/200 expert.mq4  |
//|                                                    1H   EUR/USD  |
//|                                                    Smirnov Pavel |
//|                                                 www.autoforex.ru |
//+------------------------------------------------------------------+

#property copyright "Smirnov Pavel"
#property link      "www.autoforex.ru"

extern int TakeProfit = 20; // Уровень тейкпрофит в пунктах
extern int StopLoss = 200; // уровень стоплосс в пунктах
extern int TradeTime=18;
extern int t1=7;
extern int t2=2;
extern int delta=7;
extern int dayout=1;
extern double lot = 0.1;

int ticket;
bool cantrade=true;

int OpenLong(double volume=0.1)
{
  int slippage=10;
  string comment="20/200 expert (Long)";
  color arrow_color=Red;
  int magic=0;

  ticket=OrderSend(Symbol(),OP_BUY,volume,Ask,slippage,Ask-StopLoss*Point,
                      Ask+TakeProfit*Point,comment,magic,0,arrow_color);
  if(ticket>0)
  {
    if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
    {
      Print("Buy order opened : ",OrderOpenPrice());
      return(0);
    }  
  }
  else 
  {
    Print("Error opening Buy order : ",GetLastError()); 
    return(-1);
  }
}
  
int OpenShort(double volume=0.1)
{
  int slippage=10;
  string comment="20/200 expert (Short)";
  color arrow_color=Red;
  int magic=0;  
  
  ticket=OrderSend(Symbol(),OP_SELL,volume,Bid,slippage,Bid+StopLoss*Point,
                      Bid-TakeProfit*Point,comment,magic,0,arrow_color);
  if(ticket>0)
  {
    if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
      {
        Print("Sell order opened : ",OrderOpenPrice());
        return(0);
      }  
  }
  else 
  {
    Print("Error opening Sell order : ",GetLastError()); 
    return(-1);
  }
}

int init()
{
  return(0);
}

int deinit()
{   
  return(0);
}

int start()
{
  if((TimeHour(TimeCurrent())>TradeTime)) cantrade=true;  
  // проверяем есть ли открытые ордера ...
  if(OrdersTotal()<1)
  {
    // ... если нет ни одного открытого ордера, то идем дальше
    // проверяем настало ли время для торговли
    if((TimeHour(TimeCurrent())==TradeTime)&&(cantrade)&&(TimeDayOfWeek(TimeCurrent())!=dayout))
    {
      // ... если настало время, то
      if ((Open[t1]-Open[t2])>delta*Point) //Если цена изменилась на величину delta
      {
        //условие выполнено значит входим в короткую позицию:
        // проверяем есть ли свободные деньги для открытия короткой позиции
        if(AccountFreeMarginCheck(Symbol(),OP_SELL,lot)<=0 || GetLastError()==134)
        {
          Print("Not enough money");
          return(0);
        }
        OpenShort(lot);
        cantrade=false; //запрещаем торговать повторно до следующего бара
        return(0);
      }
      if ((Open[t2]-Open[t1])>delta*Point) //Если цена изменилась на величину delta
      {
        // условие выполнено значит входим в длинную позицию
        // проверяем есть ли свободные деньги на счету
        if(AccountFreeMarginCheck(Symbol(),OP_BUY,lot)<=0 || GetLastError()==134)
        {
          Print("Not enough money");
          return(0);
        }
        OpenLong(lot);
        cantrade=false;
        return(0);
      }
    }
  }   
  return(0);
}
what do you think of this advisor?