[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 289

 

Well basically the strategy itself is very long and complex, and there is no point in describing it, it's 1 point to create a loop ie I need to find something instead of total==1 that does not open a position not matching the request, ie if it closes on st then .........open 1, if closed at ......... тп open 2, the condition lack of an order in the market, that's all,

 
FoxUA:

Well basically the strategy itself is very long and complex, and there is no point in describing it, it's 1 point to create a loop ie I need to find something instead of total==1 that does not open positions not matching the request, ie if closed by st then .........open 1, if closed by ......... тп open 2, the condition abscence of the order in the market, that's all,


Then you just don't want to use Igor's function. You need a function that returns the type of the last closed order and why it was closed. It won't return the reason of the last closed order of a certain type. I will try to think of something now...

 
Figar0:


Then you just don't fit Igor's function that you are using. You need a function that returns the type of the last closed order and why it was closed (tap or sl). It won't return the reason of the last closed order of a certain type. I will try to think of something now...


If you have something similar to Klimovskoe that returns a value for the last order closure only, I would be very grateful to you
 

Try such a function in conjunction with Igor's function:

//+----------------------------------------------------------------------------+
//|  Версия   : 30.03.2011                                                     |
//|  Описание : Возвращает тип последней закрытой позиции                      |
//|  если Buy 1 , если Sell -1                                                 |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    symbol - наименование инструмента                                       |
//|    magic - MagicNumber                                                     |
//+----------------------------------------------------------------------------+
int LastCloseDeal(string symbol, int magic) 
{
  int lastclosetime=-1;
  int lastcloseticket=-1;
  int lastdealtype=0;

  for (int i=0; i<OrdersHistoryTotal(); i++) 
  {
    if (!OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) continue; 
    if (OrderSymbol()==symbol || OrderMagicNumber()==magic) 
    {
      if (lastclosetime<OrderCloseTime()) 
      {
        lastclosetime=OrderCloseTime();
        lastcloseticket=OrderTicket();
      }
    }
  }

  if (OrderSelect(lastcloseticket, SELECT_BY_TICKET, MODE_HISTORY)) 
  {
    if (OrderType()==OP_BUY) lastdealtype=1;
    if (OrderType()==OP_SELL) lastdealtype=-1;   
  }
  return(lastdealtype);
}
 

Your piece of code should then look like this

bool Buystop=isCloseLastPosByStop(NULL,OP_BUY,MagBuy);
bool BuyTake=isCloseLastPosByTake(NULL,OP_BUY,MagBuy);
bool Sellstop=isCloseLastPosByStop(NULL,OP_SELL,MagBuy);
bool SellTake=isCloseLastPosByTake(NULL,OP_SELL,MagBuy);

//--------------------------------------------------------------------------------+
if(total==1) 
 {

   if (LastCloseDeal(Symbol(), MagBuy)==1)

  {
      if(Buystop==True)    OpenPosition(NULL, OP_SELL, Lot,Bid+Sl3*Point, Bid-Tp3*Point,MagBuy);
      if(BuyTake==True)   OpenPosition(NULL, OP_BUY,  Lot, Ask-Sl*Point, Ask+Tp*Point,MagBuy);      
   }

   if (LastCloseDeal(Symbol(), MagBuy)==-1)

   { 
      if(Sellstop==True)   OpenPosition(NULL, OP_BUY,  Lot, 0, Ask+Tp*Point,MagBuy);
      if(SellTake==True)    OpenPosition(NULL, OP_BUY,  Lot, Ask-Sl*Point, Ask+Tp*Point,MagBuy); 
   }  

}

 
Figar0:

Your piece of code should then look like this


Thanks. I'll give it a try.
 
Hello, please help me to set virtual stops at specified points. To be more precise: instead of sending data about new SL, EA should just store them in variables (or somewhere else), and keep trailing, trailing, and when price reaches a certain level (price), send a signal to DC to close order, (a kind of virtual trailing stop with virtual stoploss). In other words, the Expert Advisor includes a trailing stop on an invisible level from 1 pip to the DC server... is it realistic?
 
Centuriy:
Hello, please help me to set virtual stoplosses at specified points. To be more precise: instead of sending data about a new SL, the EA shall simply store them in variables (or somewhere else), and trawl, trawl, and when the price reaches a certain level it sends a signal to brokerage companies about closing an order, (a kind of virtual trailing stop with virtual stoploss). In other words, the Expert Advisor includes a trailing stop on an invisible level from 1 pip to the DC server... is it realistic?


Yes it is real, of course. You look through the open orders, they have an open price, for example, we have a Buy order opened at the price of X, virtual stop-loss Y points, so if the current price Z < = X-Y*Point the order should be closed. Of course, we should also take into account the spreads and if the stop loss is not fixed but calculated, the calculated value must be securely stored somewhere, etc.

Search for "virtual stop", "virtual stoploss" etc.

 
Figar0:


It is realistic of course. If we look through the open orders, their open price will be set, for example, we have a Buy order opened at X price and the virtual stoploss is Y points so if the current price Z <=X-Y*Point the order will be closed. Of course we have to take into account the spreads, and if the stop loss is not fixed but calculated, then the calculated value has to be securely stored somewhere, etc.

Search for "virtual stop", "virtual stoploss" etc.

I think we cannot do without having our own order bookkeeping of some kind.

Create your own order array and store all the necessary virtual stop data in it.

 
Figar0:


Yes it is real, of course. You look through the open orders, they have an open price, for example, we have a Buy order opened at the price of X, virtual stop-loss Y points, so if the current price Z < = X-Y*Point the order should be closed. Of course, we should also take into account the spreads and if the stop loss is not fixed but calculated, the calculated value must be securely stored somewhere, etc.

Search for "virtual stop", "virtual stoploss" etc.

Thanks for the reply, it's just the trailing stop (trailing stop) that is the problem, I want to trail 1 pip min, and I want to send orderModify to brokerage company with every tick - it's just hooliganism IMHO ))

"If the stop loss is not fixed but calculated, the calculated value must be securely stored somewhere".

where to store and how to call it... I think it has to be a variable, or am I wrong...

Reason: