Anyway, back to us I think the problem is in this part of the code ... In practice, once you enter with two different positions (a buy and a sell) the program should automatically place, buy stop and sell stop based on the last purchased position, but does not ...
Sorry Vladimir, but I am writing to you while I am at work or as I get home after 12 hours of work, yes you are right it was a very stupid mistake, however I corrected it and it seems now I can open more symbols without messing with the positions.
Anyway if I may ask, would you leave the array static or turn it into dynamic?
I am attaching the current code
You don't listen to anything and keep making a silly mistake:
for (int i =0; i<=size; i++)
{
if (PositionSelectByTicket(positions[i+1]))
{
You don't listen to anything and keep making a silly mistake:
Excuse me Vladimir but I can't understand, the loop you are talking about is the one that occurs when "i" becomes equal to "size" and I take "i + 1" which is outside the array?
Thanks Anucha for the code, however I shouldn't take the last open position on the symbol but the penultimate ... reading the code I think it returns the last position right?
Thanks Anucha for the code, however I shouldn't take the last open position on the symbol but the penultimate ... reading the code I think it returns the last position right?
NO!!! If you enter the list you MUST be on this list !!!
NO!!! If you enter the list you MUST be on this list !!!
Sorry Vlad, i m not a programmer.... however i had write this code now.... It working very well... So i must to close this post ?
for (int i =PositionsTotal()-1; i>=0; i--){
if (pos_info.SelectByIndex(i)){
ulong ticket = PositionGetTicket(i);
if (ticket==positions[1]){
Print(" ticket ", positions[1]);
long positiondirect = PositionGetInteger(POSITION_TYPE);
double openprice = PositionGetDouble(POSITION_PRICE_OPEN);
if (positiondirect == POSITION_TYPE_BUY){
Print("Buy Stop");
trade.BuyStop(lotCalculating(2),(openprice+Pos_Dis*_Digits),_Symbol,0,0,ORDER_TIME_GTC,0);
break;
}// end buy stopif (positiondirect==POSITION_TYPE_SELL){
Print("sell stop");
trade.SellStop(lotCalculating(1),(openprice-Pos_Dis*_Digits),_Symbol,0,0,ORDER_TIME_GTC,0);
break;
}// end sell stop
}// end ticket
}// end if idenx
}// end 2 for
}
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Anyway, back to us I think the problem is in this part of the code ... In practice, once you enter with two different positions (a buy and a sell) the program should automatically place, buy stop and sell stop based on the last purchased position, but does not ...
Try this code
Sorry Vladimir, but I am writing to you while I am at work or as I get home after 12 hours of work, yes you are right it was a very stupid mistake, however I corrected it and it seems now I can open more symbols without messing with the positions.
Anyway if I may ask, would you leave the array static or turn it into dynamic?
I am attaching the current code
You don't listen to anything and keep making a silly mistake:
You don't listen to anything and keep making a silly mistake:
Excuse me Vladimir but I can't understand, the loop you are talking about is the one that occurs when "i" becomes equal to "size" and I take "i + 1" which is outside the array?
Try this code
Thanks Anucha for the code, however I shouldn't take the last open position on the symbol but the penultimate ... reading the code I think it returns the last position right?
Thanks Anucha for the code, however I shouldn't take the last open position on the symbol but the penultimate ... reading the code I think it returns the last position right?
NO!!! If you enter the list you MUST be on this list !!!
Forum on trading, automated trading systems and testing trading strategies
Problem with Expert Code
Vladimir Karputov, 2021.09.24 05:45
You don't listen to anything and keep making a silly mistake:
NO!!! If you enter the list you MUST be on this list !!!
Sorry Vlad, i m not a programmer.... however i had write this code now.... It working very well... So i must to close this post ?