pending order modify

To add comments, please log in or register
fab ian
26
fab ian  

Hey guys,

I have a problem with my pending order modify.

Has anyone of you an idea?

When I add this to a chart there is no modifying taking place and no error message given out.

Whats wrong here?


Cheers

Fabian

{
RefreshRates();
double ppoint=MarketInfo(OrderSymbol(), MODE_POINT); 
int total=OrdersTotal();
double pBid=MarketInfo(OrderSymbol(), MODE_BID); 

double pAsk=MarketInfo(OrderSymbol(), MODE_ASK);

double priceNew;

//----
for(int i=0; i<total; i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
Print("Error = ",GetLastError());
{

OrderPrint();

if (OrderType()==OP_BUYSTOP)
{
if (pBid-OrderOpenPrice()>50*ppoint)
{
priceNew=(pBid-50*ppoint);
OrderModify(OrderTicket(),priceNew,0,OrderStopLoss(),OrderTakeProfit());
Print("Modified Order");
}
}
}
if (OrderType()==OP_SELLSTOP)
{
if (OrderOpenPrice()-pAsk>50*ppoint)
{
priceNew=(pAsk+50*ppoint);
OrderModify(OrderTicket(),priceNew,0,OrderStopLoss(),OrderTakeProfit());
Print("Modified Order");
}
}
}
}
}
William Roeder
20207
William Roeder  
Fabian103 :
I have a problem with my pending order modify.
When I add this to a chart there is no modifying taking place and no error message given out.
Whats wrong here?
  1. That you don't state. No mind readers here.
  2. Because you don't print any. What are Function return values ? How do I use them ? - MQL4 forum
  3. Indenting
  4. Using Market info instead of predefines
  5. Using OrderSymbol() before a successful OrderSelect()
  6. Not adjusting 4/5 digit brokers
  7. Not testing STOPLEVEL vs your 50 points Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
  8. You buy at the Ask and Sell at the Bid
  9. A buystop must be above the ask. Do you mean buyLIMIT?
  10. Always count down.

GreenMoney
369
GreenMoney  
Fabian103 :

Whats wrong here?

double ppoint=MarketInfo(OrderSymbol(), MODE_POINT); 
double pBid=MarketInfo(OrderSymbol(), MODE_BID); 
double pAsk=MarketInfo(OrderSymbol(), MODE_ASK);

To get the point, bid price, and ask price for the current symbol, it is probably better to use Point, Bid, and Ask (just as WHRoeder suggested). Also, you must only use OrderSymbol() after you have selected an order using OrderSelect(). If you wish to continue using MarketInfo(), either use Symbol() to pass the symbol for the current chart or pass a symbol name that is supported by your broker (such as "EURUSD" or "USDJPY").

fab ian
26
fab ian  

Hey,

thanks for the quick answer.

What is the problem with the 4/5 brokers? Can someone rewrite the code, so that it is correct? So I can learn from it for later EAs. I am new to all the programming and try to write different EAs and put them on charts in demo-accounts. I want to write complex EAs one day.


Thanks so far.

Cheers,

Fabian

William Roeder
20207
William Roeder  
Fabian103 : What is the problem with the 4/5 brokers? Can someone rewrite the code, so that it is correct?
  1. you wrote 50 points. That is 5 pips on a 5 digit broker and 50 pips on a 4.
  2. Did you bother to look at the links posted? Since there are no slaves here, you have only three choices: Search for it, learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.
fab ian
26
fab ian  

Okay, no worries.

I know that there are no slaves and I looked at the posted links but something is very confusing. Thats why I asked if someone is willing to help by correcting the code.

But I will try myself anyways.

Thanks so far.

Cheers

Keith Watford
Moderator
20336
Keith Watford  

I am a novice programmer, but reading through your code, it seems to me that you are trying to modify a pending order after it has triggered.


if (OrderType()==OP_BUYSTOP)
{
if (pBid-OrderOpenPrice()>50*ppoint) //If bid is 5 pips higher than OrderOpenPrice, then Ask is 5 pips plus spread 
{                                    // above OrderOpenPrice, So pending order must have triggered already?
priceNew=(pBid-50*ppoint);
OrderModify(OrderTicket(),priceNew,0,OrderStopLoss(),OrderTakeProfit()); //Cannot modify OrderOpenPrice as order 
Print("Modified Order");                                                 //already triggered.}
}
Tjipke de Vries
6636
Tjipke de Vries  
GumRai :


I am a novice programmer, but reading through your code, it seems to me that you are trying to modify a pending order after it has triggered.



that is true if it was same Symbol() as ChartSymbol()

also WHRoeder did tell that

but is the selected trade same as ChartSymbol() ??? ........

and how do you know if the trade is not a trade manual placed or from other EA

and if it was well done can the pending trade be modified without changing OrderStopLoss() or OrderTakeProfit() ??

and looking to your code How do you know OrderModify succeed. Your code is also not telling

So read again the comments WHRoeder has given ....

William Roeder
20207
William Roeder  
What is ChartSymbol() ??? ........?
Tjipke de Vries
6636
Tjipke de Vries  
WHRoeder :
What is ChartSymbol() ??? ........?

was meaning (Chart) Symbol( ) of the chart the program is attached
Joel Protusada
14034
Joel Protusada  

Try this..

{
   RefreshRates();
   double ppoint=MarketInfo(OrderSymbol(), MODE_POINT); 
   int total=OrdersTotal();
   double pBid=MarketInfo(OrderSymbol(), MODE_BID); 
   
   double pAsk=MarketInfo(OrderSymbol(), MODE_ASK);
   
   double priceNew;
   
   //----
   for(int i=0; i<total; i++)
   {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      {
         if (OrderType()==OP_BUYSTOP)
         {
               if(OrderOpenPrice()-pAsk>50*ppoint)
               {
                     priceNew=(pAsk+50*ppoint);
                     OrderModify(OrderTicket(),priceNew,0,OrderStopLoss(),OrderTakeProfit());
                     Print("Modified Order");
               }
         }        
         else if (OrderType()==OP_SELLSTOP)
         {
               if (pBid-OrderOpenPrice()>50*ppoint)
               {
                     priceNew=(pBid-50*ppoint);
                     OrderModify(OrderTicket(),priceNew,0,OrderStopLoss(),OrderTakeProfit());
                     Print("Modified Order");
               }
         }
      }
   }
}
12
To add comments, please log in or register