I'm learning to write an advisor... - page 4

 

If your Expert Advisor is multi-currency, you have to.

The more so because the Bid and Point values areprobably already set (stated) through MarketInfo().

Once I started a branch on multicurrency Expert Advisor. Have a look and some questions will be clarified....

'Multicurrency Expert Advisor Question'.

 

And here specifically on the modification

'Multicurrency advisor question'

 

I made this variant... Immediately after opening, I call ModifyPos()

OrderSend (...);

ModifyPos();



void ModifyPos()
  {
   if (OrderSelect(0, SELECT_BY_POS)==true) // Если есть открытый ордер
    { 
     if (OrderType()==OP_BUY)
     OrderModify(OrderTicket(),OrderOpenPrice(),Bid- Stop*Point,Bid- TakeProfit*Point,0,Red);
     if (OrderType()==OP_SELL)
     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+ Stop*Point,Ask+ TakeProfit*Point,0,Red);
    }  
  }

Stop - 20.

TakeProfit - 100

Message in the log - OrderModify error 130

 

Try a buy position for the take positions

Ask+ TakeProfit*Point

Think about it! Why is it that for a buy position take profit is suddenly below the current price?

No wonder that an error is generated

And the same for the sell position...

If you don't need to change Take Profit, then it's better to do this:

OrderModify(OrderTicket(), OrderOpenPrice(), Bid- Stop*Point,
                                                     OrderTakeProfit(), 0, Blue);
Similarly, for the sell-side
 
rid >> :

Think about it! Why is it that your take profit on a buy position is suddenly below the current price?

No wonder that an error is being generated!

Rid thanks a lot!

I wasn't paying attention)... it worked and even worked)

void ModifyPos()
   {
        if (OrderSelect(0, SELECT_BY_POS)==true) // Если есть открытый ордер
            { 
               if (OrderType()==OP_BUY)
                   OrderModify(OrderTicket(),OrderOpenPrice(),Bid- Stop*Point,OrderTakeProfit(),0,Red);
               if (OrderType()==OP_SELL)
                   OrderModify(OrderTicket(),OrderOpenPrice(),Ask+ Stop*Point,OrderTakeProfit(),0,Red);
            }      
   }
 

The last error that is now in the log during testing is OrderSend error 138.

This error occurs without interruption when there are no trades, i.e. for every tick this error occurs.

As soon as an order is triggered, the error disappears... the order closes and the error goes again...

It looks like it is trying to send an order without any signals... But I don't understand why, since there is an(if) condition to sell and to buy

 
ALex2008 писал(а) >>

The last error that is now in the log during testing is OrderSend error 138.

This error occurs without interruption when there are no trades, i.e. for every tick this error occurs.

As soon as an order is triggered, the error disappears... the order closes and the error goes again...

It looks like it is trying to send an order without any signals... But I don't understand why, since we have conditions(if) to sell and to buy.

do not read carefully read https://book.mql4.com/ru/content it is all there

 

Reading and understanding are different things... I want to understand in practice)

There is a condition for entering, after these conditions are met the control is passed to the function that opens the order...

I cannot understand how OrderSend is trying to work bypassing conditions... and logically it generates an error... because there are no entry conditions

 
bool RefreshRates( )

Refreshes data in predefined variables and time-series arrays. This function is used when an Expert Advisor or script has been performing calculations for a long time and needs updated data. It returns TRUE if the data is updated, otherwise FALSE. The data may not be updated only because it corresponds to the current state of the client terminal. Expert Advisors and scripts work with their own copy of historical data. The copy of data on the current symbol is created at the initial launch of the Expert Advisor or script. At every next launch of the Expert Advisor (remember, the script is executed once and does not depend on incoming ticks), the initially created copy is updated. During the time the Expert Advisor or script runs, one or more new ticks may come, so the data may become outdated.

//------------------------------------------------------------------------------

Try to insert this function before executing OrderSend

See also: Opening and Setting Orders 2008-05. :

Opening and Setting Orders2008-05-05 14:26:13

"For the program to work steadily, with a minimum number of rejected trade orders, before executing the OrderSend() function, the information environment parameters used by the program should be updated using MarketInfo() and RefreshRates() functions."

 
   RefreshRates();
   OrderSend(Symbol(), OP_SELL, Lot, Price, Slippage, 0, Profit, Comment, MAGIC,0, colorsell);

doesn't help...