[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 373

 
Was there a mistake in that line? Thank you very much.
if(OrderType()==OP_BUYSTOP && OrderSymbol()==Symbol() && type==1 && OrderMagicNumber()==MAGICMA ){count++;}
if(OrderType()==OP_SELLSTOP && OrderSymbol()==Symbol() && type==0 && OrderMagicNumber()==MAGICMA ){count++;}
ilunga:

That's how it compiles:

Now when testing does not open any transaction in the log writes Open_BuyS_SellS EURUSD,Daily: OrderSend error 131

 
Good evening. I would like to know if anyone uses the indicator for distributing trades by price levels on a given timeframe, which can be downloaded from http://fxcoder.ru/indicators/tpo. If so, how can it be properly analysed? Do you have any information about it?
 
artemka_1981:
Now when testing does not open a single trade in the log writes Open_BuyS_SellS EURUSD,Daily: OrderSend error 131

Error 131 is incorrect volume. Try lot 1 for example, you might not be allowed to open with 0.01 lot.

ERR_INVALID_TRADE_VOLUME131Incorrect volume
 
ilunga:

Error 131 is incorrect volume. Try lot 1 for example, you might not be allowed to open with 0.01 lot.

ERR_INVALID_TRADE_VOLUME131Incorrect volume
//+------------------------------------------------------------------+
//|                                                Open_Buy_Sell.mq4 |
//|                                                                  |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#define magic 999
extern bool Buy = true  ; //  true - разрешено покупать
extern bool Sell = true  ; // true - разрешено продавать
#property link      "http://www.metaquotes.net"
extern double  _lots         = 1;
extern int     _takeProfit   = 1200;
extern int      maxpos       = 1;     // количество поз
extern bool    _trailingStop = true;
//+------------------------------------------------------------------+

int start()
  {
   double _slBuy=0.0,_slSell=0.0, _tpBuy=0.0, _tpSell=0.0, _opBuy=0.0, _opSell=0.0;

//if (iVolume(Symbol(),PERIOD_D1,0)>1) return;
//     if (Volume[0]>1) return;
     if (_trailingStop){ 
     _TrailingStop();
      }
   _opBuy=NormalizeDouble(iHigh(Symbol(),0,1), Digits);
   _slBuy=NormalizeDouble(iLow(Symbol(),PERIOD_D1,1), Digits);
   _tpBuy=NormalizeDouble(Ask+_takeProfit*Point, Digits);
      if ( _opBuy<Ask && CountPos(1)<maxpos)
       if(barOpen(OP_BUYSTOP)==1 ||barOpen(OP_BUY)==1 )
        OrderSend(Symbol(),OP_BUYSTOP,_lots,_opBuy,15,_slBuy,_tpBuy,"Open_Buy_Sell",0,Green);

   _opSell=NormalizeDouble(iLow(Symbol(),0,1), Digits);
   _slSell=NormalizeDouble(iHigh(Symbol(),PERIOD_D1,1), Digits);
   _tpSell=NormalizeDouble(Bid-_takeProfit*Point, Digits);
     if (_opSell>Bid && CountPos(0)<maxpos)
      if(barOpen(OP_SELLSTOP)==1 ||barOpen(OP_SELL)==1 )
       OrderSend(Symbol(),OP_SELLSTOP,_lots, _opSell,15,_slSell,_tpSell,"Open_Buy_Sell",0,Red);
//----
   return(0);
  }
//+------------------------------------------------------------------+  
 //Проверяем количесвто позиций.
   int CountPos(int type) 
{//Описание http://fxnow.ru/blog.php?user=Yuriy&blogentry_id=66

    
int i;
int col;
int count=0 ;
for(i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS)==true)
{
if(OrderType()==OP_BUYSTOP && OrderSymbol()==Symbol() && type==1 && OrderMagicNumber()== magic){count++;}
if(OrderType()==OP_SELLSTOP && OrderSymbol()==Symbol() && type==0 && OrderMagicNumber()== magic){count++;}
         }
       }   
return(count);
}
//+------------------------------------------------------------------+
void _TrailingStop(){
   int i;
   double _stopLossSellF=NormalizeDouble(iHigh(Symbol(),0,1), Digits),
          _stopLossBuyF=NormalizeDouble(iLow(Symbol(),0,1), Digits);
   if (OrdersTotal()>0){
      for (i=OrdersTotal()-1; i>=0; i--){
         if (OrderSelect(i, SELECT_BY_POS)){
            if (OrderSymbol()==Symbol() && OrderMagicNumber()==magic){
             
               if (OrderType()==OP_BUY && OrderOpenPrice() < _stopLossBuyF){
                  while (IsTradeContextBusy()) Sleep(1000);
                  RefreshRates();
                  OrderModify(OrderTicket(),OrderOpenPrice(),_stopLossBuyF,OrderTakeProfit(),OrderExpiration(),CLR_NONE);
               }
           
               if (OrderType()==OP_SELL && OrderOpenPrice() > _stopLossSellF && _stopLossSellF!=0.0){
                  while (IsTradeContextBusy()) Sleep(1000);
                  RefreshRates();
                  OrderModify(OrderTicket(),OrderOpenPrice(),_stopLossSellF,OrderTakeProfit(),OrderExpiration(),CLR_NONE);
               }
            }
         }
      }
   }
return;
}
int barOpen(int ty)
{
datetime tim=0;
 for(int i=0; i<=OrdersTotal(); i++)
    {  
       if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))continue;
       if(OrderSymbol() !=Symbol()|| OrderMagicNumber()!= magic|| OrderType()!=ty) continue; 
       if(tim<OrderOpenTime())        
          tim=OrderOpenTime();
   }
 for(i=0; i<=OrdersHistoryTotal(); i++)
    {  
       if (!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))continue;
       if(OrderSymbol() !=Symbol()|| OrderMagicNumber()!= magic|| OrderType()!=ty) continue; 
       if(tim<OrderOpenTime())        
          tim=OrderOpenTime();
   }
 
if(tim<iTime(Symbol(),PERIOD_D1,0)) return(1);
 return(0);
}
Afternoon. Now writes Open_BuyS_SellS EURUSD,H4: OrderSend error 3

 
artemka_1981:
Afternoon. Now writes Open_BuyS_SellS EURUSD,H4: OrderSend error 3

Read error codes
 
artemka_1981:
Good day. Now it says Open_BuyS_SellS EURUSD,H4: OrderSend error 3

See help for OrderSend parameters and error codes

3 - wrong parameters.

You missed one and instead of datetime expiration, you wrote colour arrow_color

 
ilunga:

See help for OrderSend parameters and error codes

3 - wrong parameters.

You missed one and instead of datetime expiration, you wrote colour arrow_color

I am sorry for stupid questions, this is my first EA I am trying to write by myself, all my problems started when I added the trail function, that's why I addressed to you for help in solving my mistakes
 

help who knows!!!!


The essence of the strategy: Entry by stochastic signal (5,14,3) exit also by stochastic, but with another period (5,3,3). I don't understand how to make an exit by stochastic and not by reverse signal.
I have a problem and I have no idea how it can be solved, I will try to explain.
So, in the code I posted, there are 2 functions
//+------------------------------------------------------------------+
//| подготовить массив тикетов для закрытия |
//+------------------------------------------------------------------+
void PrepareTicketsToClose(int signal, bool Revers, int & ticketsClose[][2], double & lots[],double arrayTickets[][9])
{
int size=ArrayRange(arrayTickets,0);
//----
if (size==0) return;

int i,type,ticket,closeSize;
for (i=0;i<size;i++)
{
type=arrayTickets[i][1];
// если тип ордера не рыночный, то пропускаем
if (type>OP_SELL) continue;

if (Revers) // перевернем тип рыночного ордера
{
if (type==OP_BUY) type=OP_SELL; else type=OP_BUY;
}

// тут решаем для каждого открытого ордера его судьбу
// оставить в рынке или добавить в массив на закрытие
if (type==OP_BUY)
{
//
// код разрешающий оставить покупку

// как пример
if (signal==OP_BUY) continue;
}

if (type==OP_SELL)
{
//
// код разрешающий оставить продажу

// как пример
if (signal==OP_SELL) continue;
}

closeSize=ArrayRange(ticketsClose,0);
ArrayResize(ticketsClose,closeSize+1);
ArrayResize(lots,closeSize+1);
ticketsClose[closeSize][0] = arrayTickets[i][0]; // # тикета
ticketsClose[closeSize][1] = arrayTickets[i][1]; // тип ордера

// здесь укажем сколько лотов нужно закрыть
lots[closeSize] = arrayTickets[i][2]; // закрываемый объем
// можно закрывать частично, тогда нужно переписать строку сверху
}
//----
return;
}

//+------------------------------------------------------------------+
//| Закрывает ордера с указанными тикетами |
//+------------------------------------------------------------------+
void CloseMarketOrders(int ticketsArray[][2], double lotsArray[])
{
//----
int i,size=ArrayRange(ticketsArray,0);
if (size==0) return;

int ticket,type;
double lots;
bool res;

int total=OrdersTotal();

for (i=0;i<size;i++)
{
ticket = ticketsArray[i][0];
type = ticketsArray[i][1];
lots = lotsArray[i];
RefreshRates(); // на всякий случай обновим сведения о рыночном окружении

// блок закрытия покупок
if (type==OP_BUY)
{
res = OrderClose(ticket,lots,Bid,Slippage,Orange);
if (!res)
{
Print("Не удалось закрыть ордер в покупку #",ticket,"! Ошибка №",GetLastError());
// дальнейшая обработка ошибки, написать самостоятельно
}
}

// блок закрытия продаж
if (type==OP_SELL)
{
res = OrderClose(ticket,lots,Ask,Slippage,Orange);
if (!res)
{
Print("Не удалось закрыть ордер в продажу #",ticket,"! Ошибка №",GetLastError());
// дальнейшая обработка ошибки, написать самостоятельно
}
}

}
//----
return;
}
In void PrepareTicketsToClose(int signal, bool Revers, int & ticketsClose[][2], double & lots[],double arrayTickets[][9]) we have to put a condition that will decide if we should leave or close the order.
I tried to put conditions but nothing works....
Can someone look and show if there is an error in these functions or i messed up....
Files:
osc_test_1.mq4  37 kb
 
Hello. After running the Expert Advisor in the tester, I need to get information about the total volume of trades made in lots (for example, in the logs). The Expert Advisor has the MM block enabled, the trades are executed in % of free funds, so simply multiplying by the number of trades does not work. Is there a standard function that provides this information (like OrderLots, but with total amount)? If there is no such a function, may someone suggest a simple code for realization of this task? Thank you.
 

how to open ports for mt4 on ADSL modem via WIFI? I go to the internet on 6 DTs. model tp-link W8901G read that you can open ports for torents can anyone face?

Reason: