Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 94

 
void CheckForClose()
  {
   double PriceHigh, PriceLow;
//---- go trading only for first tiks of new bar
   if(Volume[0]>1) return;
   
   PriceHigh = iCustom (Symbol(), 0, "ExtremeTMALine", TimeFrame, HalfLength , Price, ATRMultiplier, ATRPeriod, Interpolate, TrendThreshold, Distances, 1, 0); 
   PriceLow = iCustom (Symbol(), 0, "ExtremeTMALine", TimeFrame, HalfLength , Price, ATRMultiplier, ATRPeriod, Interpolate, TrendThreshold, Distances, 2, 0); 
   
   
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)        break;
      if(OrderMagicNumber()!=Magic || OrderSymbol()!=Symbol()) continue;
      //---- check order type 
      if(OrderType()==OP_BUY)
        {
         if(Low[1]<=PriceHigh && Ask>PriceHigh) OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,White);
         break;
        }
      if(OrderType()==OP_SELL)
        {
         if(Ask<=PriceLow && High[1]>PriceLow) OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,White);
         break;
        }
     }
//----
  }

artmedia70

Going back to my rams, regarding closing a position on price crossing an indicator line. I think the error is in this function

if(Volume[0]>1) return;

I read in the tutorial that instead of counting ticks we can open (close) a position at appearing of bars. Is it possible? If so, can you give me a hint how to program it for my situation.

 
alexey1979621:

artmedia70

Going back to my rams, regarding closing a position on price crossing an indicator line. I think the error is in this function

if(Volume[0]>1) return;

I read in the tutorial that instead of counting ticks we can open (close) a position at appearing of bars. Is it possible? If so, can you send us a hint on how to program it for my situation.

Maybe it will be useful:

The function returns true when a new bar appears on M15

bool CheckOpenM15()
{
   static int PrevTime=0;
   if (PrevTime==iTime(NULL, PERIOD_M15,0)) return(false);
   PrevTime=iTime(NULL, PERIOD_M15,0);
   return(true);
}
 
ex1m:

Please advise!!!

I am writing pending orders at a certain time

{

Define open time

}

if ((condition)==true)//
{
OrderSend ( OP_BUYSTOPP, parameters);// open a pending BuyStop order
OrderSend ( OP_SELLSTOP, parameters);// open a pending SellStop order
}

I think I wrote the time correctly; it detect it but for some reason, it opens either Sell Stop or Buy Stop and doesn't open two orders at once. I try to open two pending orders of different types (Bistop and Sellstop) at the same time and one by one. The question seems to be primitive, please help for dummies.)

To paste the code correctly here, click on SRC first and then copy the code there.

If I understood you correctly, at a certain point in time I need to open one OP_BUYSTOP and one OP_SELLSTOP ? Is it acceptable to have any other pending orders at this moment? For example, there are pending orders, but we have to delete the old ones before we open the new ones?

 
artmedia70:
This error refers to graphical objects, not orders

.
Exactly! The error refers to objects, but I have no objects in this EA...


borilunad:
Good evening, Victor! Strange, the pending order is not an object! Maybe you have some object that should have already been deleted, but wasn't!

Good afternoon, Boris! The Expert Advisor does not create objects. This error comes from the function that places a pending order. Here is the version of the function (for the tester):

bool OpenPendingBuy(double lot, double price)
{
   int g_ticket = -1;
   double OOP = price + i_distanceFromLastPos * pt;

   if (OOP > Ask)
   {
       fCheck_ValidPendingOOP(Symbol(), OP_BUYSTOP, OOP);
       
       g_ticket = OrderSend(Symbol(), OP_BUYSTOP, lot, ND(OOP), 30, 0, 0, NULL, i_magic, 0, CLR_NONE);
   }
   if (g_ticket > 0)
   {
       return (true);
   }
   else
       pr ("OpenPendingBuy(): Ордер послать не удалось " + GetLastError());
   
   return (false);
}

If no order has been placed, this means that a block has triggered:

else
       pr ("OpenPendingBuy(): Ордер послать не удалось " + GetLastError());

This is the block that reports the error.


Has anyone understood the logic?

 
artmedia70:

Since there's no answer to the question, here's a function that will return the ticket of the last order set:



Thank you!!! just what I need

 
hoz:
Exactly! The error concerns objects, but I have no objects in this EA...

Good afternoon, Boris! The Expert Advisor does not create objects. This error comes from the function that places a pending order. Here is the version of the function (for the tester):

If the order has not been placed, this means that a block has triggered:

This is the block that reports the error.

Has anyone understood the logic?

So, check your error check? There must be something glitchy there!
 
borilunad:
So, check your error check? There must be something glitchy there!

Heh)) What's there to glitch about Boris? It's all transparent...

pr is a print function. And the error, it's already a standard constant. Logically, it's unacceptable to be that way at all. If you still have a suspicion about the pr function, here it is:

//+-------------------------------------------------------------------------------------+
//| Распринтовка на экран                                                               |
//+-------------------------------------------------------------------------------------+
void pr (string txt)
{
string info [];
ArrayResize(info,20);
string h,m,s,cm; int i;
h=DoubleToStr(Hour(),0);    if (StringLen(h)<2) h="0"+h;
m=DoubleToStr(Minute(),0);  if (StringLen(m)<2) m="0"+m;
s=DoubleToStr(Seconds(),0); if (StringLen(s)<2) s="0"+s;
txt=h+":"+m+":"+s+" - "+txt;
for(i=20-1; i>=1; i--)
info[i]=info[i-1];
info[0]=txt;
for(i=20-1; i>=0; i--)
if(info[i]!=""){
cm=info[i];
ObjectCreate ("txtw"+i,OBJ_LABEL,0,0,0);
ObjectSet    ("txtw"+i,OBJPROP_CORNER,1);
ObjectSet    ("txtw"+i,OBJPROP_XDISTANCE,10);
ObjectSet    ("txtw"+i,OBJPROP_YDISTANCE,30+15*i);
ObjectSetText("txtw"+i,cm, 10, "Times New Roman", Green);}}
 

  • Does anyone understand the logic?


Is the lot normalized? Well and check the price.

Are i_magic, pt, i_distanceFromLastPos global?

 
splxgf:

i_magic, pt, i_distanceFromLastPos are global?


Yes. Variables with i_ are input variables (from the word intut, which can be changed by the user...), and pt is a global variable too, which is visible everywhere...
splxgf:


  • Does anyone understand the logic?


Is the lot normalized? Well and check the price.


No, the lot has not been normalised. Never encountered it in the tester... And what does lot have to do with the object (error 4200)?
 
hoz:

I occasionally, but not constantly, get a 4200 error when I set a pending order. According to the documentation this error means that the object already exists:

ERR_OBJECT_ALREADY_EXISTS 4200 Объект уже существует

It turns out that an order of this type is already in the market when the pending order is sent?

Maybe, some other program creates a graphical object with the same name, to which the EA reacts. Maybe you need to change the names of the objects.
Reason: