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

 
hoz:


Yesterday I was in a hurry, had to go. I wrote the question at that moment not the one I wanted.

Actually, I meant Expert Advisors which, under a given condition, send a bunch of orders (a grid). I have not seen in such Expert Advisors that neither spread, nor stop-loss, nor price position above (below Asc or Bid), nor anything else is checked. I'm going to write it myself and show it to everyone.


Why even take some gore-experts as an example? At the very least they are solely for the tester, at the most they are written with crooked hands, as mentioned above...
 
alsu:

Why take some woe-experts as an example at all? At the very least they are solely for the tester, at the most they are written with crooked hands, as stated above...

Well, I understood how to implement it, but decided to see how others do it.
 

Guys, I'm having a really horrible problem! My graph doesn't shift to the left when I save the drawing! The "shift graph" function is activated! How do I fix it?


 

Hello!

I want my Expert Advisor to open no more than one trade a day. Can you tell me how to do this?

 

Hello, I've been looking into mql4 for a while now, maybe one of the experienced programmers can help. I want to know how to make it lock when order reaches -30 or -40. I have to add some properties for this script to lock the orders as soon as they go in minus.

void start()
{
double StopLoss;
double Lots=0;
for(int i=0;i<OrdersTotal();i++)
{
if(!OrderSelect(i,SELECT_BY_POS))
continue;
if(OrderSymbol()!=Symbol())
continue;
if(OrderType()==OP_BUY)
Lots+=OrderLots();
if(OrderType()==OP_SELL)
Lots-=OrderLots();
}
if(Lots>0)
OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Ask+StopLoss*Point,0,NULL,Red);
if(Lots<0)
OrderSend(Symbol(),OP_BUY,-(Lots),Ask,3,Bid-StopLoss*Point,0,NULL,Blue);

 
protey7:

Hello!

I want my Expert Advisor to open no more than one trade a day. Can you tell me how to do this?

extern int MagicNumber=555;
//---
if (OrdersTotal()>0) // Есть ли отложенные ордера или открытые позиции
{  for (i=OrdersTotal()-1; i>=0; i--) // Перебираем ордера
   {  if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) // Oрдер выбирается среди открытых и отложенных ордеров
      {  if (OrderSymbol()!=Symbol()) continue; // Если торговый символ не тот, на котором работает эксперт - игнорируется
         if (OrderMagicNumber()!=MagicNumber) continue; // Если магик номер не тот, что надо - игнорируется
         if (OrderOpenTime()>=iTime(NULL,PERIOD_D1,0)) // Если время открытия ордера больше или равен началу открытия данной свечи,
                                                       // то дальший код эксперта не работает. Вместо PERIOD_D1 можно вставить любой другой период.
            return(0);
}  }  }
 
Wild_Wolf:

Guys, I'm having a really horrible problem! My graph doesn't shift to the left when I save the drawing! The "shift graph" function is activated! How do I fix it?

Note: on the graph at the top right there is a little triangle like this. When you hover your cursor over it, a tooltip pops upsaying "Chart shift". Hook it and move it to the left as much as you need to make room on the right.
 
hoz:

Well, I understood how to implement it, but I decided to see how others do it.
What if others start jumping out of windows?
 
paladin80:


Thanks for the tip!

Only in the suggested variant the expert doesn't work)))) Here is a working variant that I got :

if (OrdersTotal()==0) // If there are no open positions

{ for (int i=OrdersHistoryTotal()-1; i>=0; i--) // Search for orders from the account history list

{ if (OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) // the order is selected among the closed orders

{

if (OrderCloseTime()>=iTime(NULL,PERIOD_D1,0)) // If the order close time is greater than or equal to the start of the current candle opening

// The Expert Advisor does not work. Any other period can be inserted instead of PERIOD_D1.

return(-1);

} } }

 
alsu:

Why do you even take some woe-experts as an example? At a minimum they are designed exclusively for the tester, at a maximum they are written with crooked hands, as it was said above...


Wrote it my way. I didn't particularly optimize the code, just wrote it to make it work and show the logic.

//+-------------------------------------------------------------------------------------+
//| Открытие длинной позиции                                                            |
//+-------------------------------------------------------------------------------------+
bool OpenBuy(double initialOOP, int i)
{
   int ticket;
   
   ticket = OrderSend(Symbol(), OP_BUYSTOP,0.1,NormalizeDouble(Ask + (step*i) * pt, Digits),3,0,0,NULL,i_magic,0,CLR_NONE);
   
   if (ticket > 0)
       return (true);
}
//+-------------------------------------------------------------------------------------+
//| Открытие короткой позиции                                                           |
//+-------------------------------------------------------------------------------------+
bool OpenSell(double initialOOP, int i)
{
   int ticket;
   
   ticket = OrderSend(Symbol(), OP_SELLSTOP,0.1,NormalizeDouble(Bid - (step*i)*pt, Digits),3,0,0,NULL,i_magic,0,CLR_NONE);
   
   if (ticket > 0)
       return (true);
}
//+-------------------------------------------------------------------------------------+
//| Посылаем пачку ордеров на сервер                                                    |
//+-------------------------------------------------------------------------------------+
bool SendPackOfOrders(int lastPosTicket, int lastPosType, double initialOOP)
{
   if (lastPosTicket == -1)                        // Если нет рыночных ордеров, значит..
       return(false);                              //..сетку отложек не кидаем
       
  // if (lastPosType != g_lastPosType)               // Если тикет изменился, значит..
   {
      lastPosType = g_lastPosType;
      
      for (int i=1; i<=5; i++)
      {
         if (!OpenBuy(initialOOP, i))
             return(false);
         if (!OpenSell(initialOOP, i))
             return(false);
      }
   }
}

The step is the order grid spacing.

My question is this. Is my logic correct? Is there any way to improve the code so that it would work faster? From performance point of view...

I also have an idea that we may need to make pauses after each message. Well, all in all these points are very interesting to me.