[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 174

 
Please advise. I have an Expert Advisor in one window (e.g. USDJPY), but I need it to put arrows(ObjectCreate) in other open windows, e.g. AUDUSD, EURUSD etc.
 
nicdevis >> :
>> Please advise. I have an Expert Advisor in one window (for example, USDJPY) and I need it to set arrows(ObjectCreate) at a certain moment in other open windows, for example, AUDUSD, EURUSD e.t.c.

If you look in the ObjectCreate helper, you can clearly see that it only works within a single open chart, on which the indicator or Expert Advisor is located. The output can be the transfer of data to the Expert Advisor in the desired window through the global variables or file.

 
granit77 >> :

If you look in the ObjectCreate helper, you can clearly see that it only works within a single open chart, on which the indicator or Expert Advisor is located. The output can be the transfer of data to the Expert Advisor in the required window through global variables or a file.

I.e., there is no way to do it from another window? >> Thank you.

 

How can this pending order modification function be disabled via external variables?


//+------------------------------------------------------------------+
//| Модификация ордеров                                              |
//+------------------------------------------------------------------+
void ModifyOrders() {
  bool   fm;
  double ldStop=0, ldTake=0;
  int    spr=MarketInfo(Symbol(), MODE_SPREAD);
  double pAsk=Ask+( DistanceSet+ spr)*Point;
  double pBid=Bid- DistanceSet*Point;

  for (int i=0; i<OrdersTotal(); i++) {
    if (OrderSelect( i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==Symbol() && OrderMagicNumber()== MAGIC+1) {
        if ( StopLoss!=0) ldStop= pAsk- StopLoss*Point;
        if ( TakeProfit!=0) ldTake= pAsk+ TakeProfit*Point;
        OrderModify(OrderTicket(), pAsk, ldStop, ldTake, 0, clModifyBuy);
      }
      if (OrderSymbol()==Symbol() && OrderMagicNumber()== MAGIC+2) {
        if ( StopLoss!=0) ldStop= pBid+ StopLoss*Point;
        if ( TakeProfit!=0) ldTake= pBid- TakeProfit*Point;
        OrderModify(OrderTicket(), pBid, ldStop, ldTake, 0, clModifySell);
      }
    }
  }
}

//+------------------------------------------------------------------+
//| Возвращает флаг существования ордера или позиции по номеру       |
//+------------------------------------------------------------------+
bool ExistOrder(int mn) {
  bool Exist= False;
  for (int i=0; i<OrdersTotal(); i++) {
    if (OrderSelect( i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==Symbol() && OrderMagicNumber()== MAGIC+ mn) {
        Exist= True; break;
      }
    }
  }
  return( Exist);
}

//+------------------------------------------------------------------+
//| Возвращает флаг существования позиции по номеру                  |
//+------------------------------------------------------------------+
bool ExistPosition(int mn) {
  bool Exist= False;
  for (int i=0; i<OrdersTotal(); i++) {
    if (OrderSelect( i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==Symbol() && OrderMagicNumber()== MAGIC+ mn) {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          Exist= True; break;
        }
      }
    }
  }
  return( Exist);
}
 
1Rakso писал(а) >>

How can this pending order modification function be disabled via external variables?

extern bool bModify=false;
int start()
  if ( bModify) ModifyOrders();
  return(0);
}
Something like this
 
Vinin >> :
>> something like this.

Thank you! Vinin!

>> I'll try it.)

 
Channel EA

Programmers, please help, I need an EA to open orders, even if they are already open. This is a channel EA. Every time a line touches one of the lines, the corresponding order should be opened. I would like to thank you in advance.



//+------------------------------------------------------------------+
//| TradeChannel.mq4 |
//| Copyright © 2005, Yuri Makarov |
//| http://mak.tradersmind.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Yuri Makarov"
#property link "http://mak.tradersmind.com"

extern double Lots = 1.0;
extern int Slippage = 5;
extern int TimeOut = 10000;

double SetLevel(double Level, double NewLevel, string ObjName, int Style)
{
switch (Style)
{
case 1: // Buy Order line
ObjectSet(ObjName,OBJPROP_COLOR,Blue);
ObjectSet(ObjName,OBJPROP_STYLE,STYLE_SOLID);
ObjectSet(ObjName,OBJPROP_WIDTH,2);
break;
case 2: // Sell Order line
ObjectSet(ObjName,OBJPROP_COLOR,Red);
ObjectSet(ObjName,OBJPROP_STYLE,STYLE_SOLID);
ObjectSet(ObjName,OBJPROP_WIDTH,2);
break;
case 3: // Buy Stop line
ObjectSet(ObjName,OBJPROP_COLOR,Blue);
ObjectSet(ObjName,OBJPROP_STYLE,STYLE_DASH);
ObjectSet(ObjName,OBJPROP_WIDTH,1);
break;
case 4: // Sell Stop line
ObjectSet(ObjName,OBJPROP_COLOR,Red);
ObjectSet(ObjName,OBJPROP_STYLE,STYLE_DASH);
ObjectSet(ObjName,OBJPROP_WIDTH,1);
break;
case 5: // Buy Take line
ObjectSet(ObjName,OBJPROP_COLOR,Blue);
ObjectSet(ObjName,OBJPROP_STYLE,STYLE_DOT);
ObjectSet(ObjName,OBJPROP_WIDTH,1);
break;
case 6: // Sell Take line
ObjectSet(ObjName,OBJPROP_COLOR,Red);
ObjectSet(ObjName,OBJPROP_STYLE,STYLE_DOT);
ObjectSet(ObjName,OBJPROP_WIDTH,1);
break;
}

if (MathAbs(NewLevel - Close[0]) < MathAbs(Level - Close[0])) return (NewLevel);
else return (Level);
}

int start()
{
int NumObj = ObjectsTotal();
double Spread = Ask - Bid;

double pBuy = 0;
double pSell = 0;
double pBuyStop = 0;
double pBuyTake = 0;
double pSellStop = 0;
double pSellTake = 0;

for (int i = 0; i < NumObj; i++)
{
string ObjName = ObjectName(i);
string ObjDesc = ObjectDescription(ObjName);
double Price = 0;

switch (ObjectType(ObjName))
{
case OBJ_HLINE:
Price = ObjectGet(ObjName,OBJPROP_PRICE1);
break;
case OBJ_TREND:
Price = ObjectGetValueByShift(ObjName,0);
break;
}

if (Price > 0)
{
if (ObjDesc == "Buy") pBuy = SetLevel(pBuy, Price, ObjName, 1); else
if (ObjDesc == "Sell") pSell = SetLevel(pSell, Price, ObjName, 2); else
if (ObjDesc == "Stop")
{
if (Price < Close[0]) pBuyStop = SetLevel(pBuyStop, Price, ObjName, 3);
else pSellStop = SetLevel(pSellStop, Price, ObjName, 4);
} else
if (ObjDesc == "Take")
{
if (Price > Close[0]) pBuyTake = SetLevel(pBuyTake, Price, ObjName, 5);
else pSellTake = SetLevel(pSellTake, Price, ObjName, 6);
}
}
}

int NumOrders = OrdersTotal();
int NumPos = 0;

for (i = 0; i < NumOrders; i++)
{
OrderSelect(i, SELECT_BY_POS);
if (OrderSymbol() != Symbol()) continue;

NumPos++;

double tp = OrderTakeProfit();
double sl = OrderStopLoss();

if (OrderType() == OP_BUY)
{
if (Bid > pSell && pSell > 0)
{
OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, Red);
Sleep(TimeOut);
return(0);
}
if (MathAbs(tp - pBuyTake) > Spread || MathAbs(sl - pBuyStop) > Spread)
{
OrderModify(OrderTicket(), Ask, pBuyStop, pBuyTake, 0);
Sleep(TimeOut);
return(0);
}
}

if (OrderType() == OP_SELL)
{
if (Ask < pBuy)
{
OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, Red);
Sleep(TimeOut);
return(0);
}
if (MathAbs(tp - pSellTake) > Spread || MathAbs(sl - pSellStop) > Spread)
{
OrderModify(OrderTicket(), Bid, pSellStop, pSellTake, 0);
Sleep(TimeOut);
return(0);
}
}
}

if (NumPos > 0) return(0);
if ((pSell - pBuy) < Spread*2) return(0);

if (Bid > pSell && pSell > pBuyStop)
{
OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, pSellStop, pSellTake);
Sleep(TimeOut);
return(0);
}

if (Ask < pBuy && (pBuy < pSellStop || pSellStop == 0))
{
OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, pBuyStop, pBuyTake);
Sleep(TimeOut);
return(0);
}
}

int init()
{
return(0);
}

int deinit()
{
return(0);
}

 

You are most likely hampered by this line:

if (NumPos > 0) return(0);

We can start with this. This should be removed.

AND Separate the buy and sell entry mechanism. Take I.Kim's function (insert it at the very-very end of the code)





//+----------------------------------------------------------------------------+
//|  Версия   : 19.02.2008                                                     |
//|  Описание : Возвращает количество позиций.                                 |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (""   - любой символ,                   |
//|                                     NULL - текущий символ)                 |
//|    op - операция                   (-1   - любая позиция)                  |
//|    mn - MagicNumber                (-1   - любой магик)                    |
//+----------------------------------------------------------------------------+
int NumberOfPositions(string sy="", int op=-1, int mn=-1) {
  int i, k=OrdersTotal(), kp=0;

  if ( sy=="0") sy=Symbol();
  for ( i=0; i< k; i++)                                    {
    if (OrderSelect( i, SELECT_BY_POS, MODE_TRADES))      {
      if (OrderSymbol()== sy || sy=="")                   {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if ( op<0 || OrderType()== op)                   {
            if ( mn<0 || OrderMagicNumber()== mn) kp++;
          }}}}}  return( kp);}

Then the condition of transaction opening will be buy:



if ( NumberOfPositions(NULL,OP_BUY, -1)<1 ) {
//если нет бай-позиций 



And the condition for opening a sell trade :



if ( NumberOfPositions(NULL,OP_SELL, -1)<1) {


 
RomanS писал(а) >>

This problem has probably been solved before 2003. But since someone else doesn't know, I'll share)))

Right-click on the chart - select properties - general tab - check fixed scale - OK

Then hover the mouse over the price scale, left click and keep it pressed, move the mouse up/down to adjust the scale.

You may have it in the main window, so you don't have to look far.

 
Synax >> :
Channel EA

I want to ask the EA to open orders even if they are already open. This is a channel EA, every time some line or other is touched, the corresponding order should be opened. I think this EA will open one order and do not open another one until it closes.



I did what I described in the post above. I inserted the number of positions function and replaced the position opening block at the end with this one:

//if (NumPos > 0) return(0);
if (( pSell - pBuy) < Spread*2) return(0);
//-------------------------------------------------
if ( NumberOfPositions(NULL,OP_SELL, -1)<1) {//если нет открытых селл-позиций
if (Bid > pSell && pSell > pBuyStop)//если условия соответствуют заданным
{//продаем
OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, pSellStop, pSellTake);
Sleep( TimeOut);
return(0);
}}
//-----------------------------------------------------
if ( NumberOfPositions(NULL,OP_BUY, -1)<1 ) {//если нет открытых бай-позиций
if (Ask < pBuy && ( pBuy < pSellStop || pSellStop == 0))
{// покупаем
OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, pBuyStop, pBuyTake);
Sleep( TimeOut);
return(0);
}}

Now EA can hold at least 2 positions at the same time.

Sorry, I can't test it as you forgot to attach the indicator which draws the channels.

Files:
Reason: