error: position doesen't exist

 

trying to change the stoploss of an order, I get the error in question and "error n 4756"
i'm using a library downloaded from this site, it's called k_orders, i've changed it a bit believing i'll solve the problem but i still get the error.
the library is in the attachment.
p.s. I'm trying to move the stoploss up by about 16 pips.

p.s.2 This happens in the strategy tester, I didn't do other tests.

void changeTrailingStop(){

   double price, slInPrice;
   int pips, slInPoints; //stoploss
   ENUM_ORDER_TYPE operation;
   
   slInPoints = round(minValueToChangeTrailingStop * 2/3);

   if(positionInfo.PositionType() == POSITION_TYPE_BUY){
      price = SymbolInfoDouble(Symbol(),SYMBOL_BID);
      pips = ( price - orderPriceOpen ) / Point();
      slInPrice = orderPriceOpen + ( slInPoints * Point() );
      operation = ORDER_TYPE_BUY;
   }else if(positionInfo.PositionType() == POSITION_TYPE_SELL){
      price = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
      pips = ( orderPriceOpen - price ) / Point();
      slInPrice = orderPriceOpen - ( slInPoints * Point() );
      operation = ORDER_TYPE_SELL;
   }   

   order.SetSL_inPrice(slInPrice);
   order.Modify(operation);

}

wha'ts the problem? how to solve it?


thanks

Files:
k_orders.mqh  10 kb
 
You have to specify which position with an index, 0 being the latest one.
See the section about positioninfo.

Normally(without classes) you do
PositionGetTicket(index) in a loop where index is the position number.
 
pennyhunter #:
You have to specify which position with an index, 0 being the latest one.
See the section about positioninfo.

Normally(without classes) you do
PositionGetTicket(index) in a loop where index is the position number.

thanks for reply

I did the loop, in the library line 236.

 
CaneRandagio #:

thanks for reply

I did the loop, in the library line 236.

I suppose you get to know the debugger, set stop points at every line of your code and put every variable under watch, then go through the code line by line in debugger and see what values the respective variable gets at what point in time. Maybe set up a test program to buy without condition so that it has some position to process.

See section 2.Debugging

Also are you aware that it is very likely you are just buiding your own CTrade version there, why not use the one provided in standard library?
Debugging MQL5 Programs
Debugging MQL5 Programs
  • www.mql5.com
This article is intended primarily for the programmers who have already learned the language but have not fully mastered the program development yet. It reveals some debugging techniques and presents a combined experience of the author and many other programmers.
 
pennyhunter #:

I suppose you get to know the debugger, set stop points at every line of your code and put every variable under watch, then go through the code line by line in debugger and see what values the respective variable gets at what point in time. Maybe set up a test program to buy without condition so that it has some position to process.

See section 2.Debugging

Also are you aware that it is very likely you are just buiding your own CTrade version there, why not use the one provided in standard library?
thanks for help
Reason: