R4tna C #: Here is some code to get you started - play around with it. But do consider the advice above - using a struct in an array is far more effective
according to my knowledge i am doing it correctly but it is not working can u please have a look ?
voidOnTick()
{
int totalPositions = PositionsTotal(); // Get the total number of open positionsdouble openPrice = PositionGetDouble(POSITION_PRICE_OPEN);
double lotSize = PositionGetDouble(POSITION_VOLUME);
double newPrice = NormalizeDouble(openPrice - 500 * _Digits); // for buy// Iterate through all open positions to get their informationfor (int i = 0; i < totalPositions; i++)
{
ulong ticket= PositionGetTicket(i);
if (PositionSelectByTicket(ticket)) // Select the position by its ticket
{
MyArray[LastRow][def_ticketNo] = (double)ticket;
MyArray[LastRow][def_OpenPrice] = openPrice;
MyArray[LastRow][def_LotSize] = lotSize;
MyArray[LastRow][def_NextDayPrice] = openPrice + Points;
LastRow = ArrayResize(MyArray, (ArraySize(MyArray)/def_cols) +1) - 1; //Increase rows by 1 [Note ArraySize() returns number of cells so divide by cols to get rows]
MyArray[LastRow][def_ticketNo] = (double)ticket;
MyArray[LastRow][def_OpenPrice] = openPrice;
MyArray[LastRow][def_LotSize] = lotSize;
MyArray[LastRow][def_NextDayPrice] = openPrice + Points;
ArrayPrint(MyArray);
}
}
}
You have just registered and most likely you have questions such as, "How do I insert a picture to my a message?" "How do I format my MQL5 source code?" "Where are my personal messages kept?" You may have many other questions. In this article, we have prepared some hands-on tips that will help you get accustomed in MQL5.community and take full advantage of its available features.
Sunny DP #: according to my knowledge i am doing it correctly but it is not working can u please have a look ?
Some suggestions:
Be more specific when you say "its not working" - what are the errors?
Paste compilable code (the full mq5 file) - that way I can debug it if necessary
You need to read the documentation on PositionGetDouble() - at first glance your usage does not appear correct. You have to select the context of the ticket you want before using such functions [i.e. within the for (int i = 0; i < totalPositions; i++) loop - AFTER the ulong ticket= PositionGetTicket(i) statement]
Write a function to encapsulate the addition to the array - just pass the values. No point writing repetitive code - re-use
Please read the MQL5 documentation - there are lots of good examples for everything you need - copy their style for optimal/better code
Be more specific when you say "its not working" - what are the errors?
Paste compilable code (the full mq5 file) - that way I can debug it if necessary
You need to read the documentation on PositionGetDouble() - at first glance your usage does not appear correct. You have to select the context of the ticket you want before using such functions [i.e. within the for (int i = 0; i < totalPositions; i++) loop - AFTER the ulong ticket= PositionGetTicket(i) statement]
Write a function to encapsulate the addition to the array - just pass the values. No point writing repetitive code - re-use
Please read the MQL5 documentation - there are lots of good examples for everything you need - copy their style for optimal/better code
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.
MyArray [0] [0] = Here we will save the ticket number of the previous open trade.
Here is some code to get you started - play around with it.
But do consider the advice above - using a struct in an array is far more effective
Here is some code to get you started - play around with it.
But do consider the advice above - using a struct in an array is far more effective
according to my knowledge i am doing it correctly but it is not working can u please have a look ?
Some suggestions:
You have to select the context of the ticket you want before using such functions [i.e. within the for (int i = 0; i < totalPositions; i++) loop
- AFTER the ulong ticket= PositionGetTicket(i) statement]
Please read the MQL5 documentation - there are lots of good examples for everything you need - copy their style for optimal/better code
Please always use the CODE button (Alt-S) when inserting code.
Some suggestions:
You have to select the context of the ticket you want before using such functions [i.e. within the for (int i = 0; i < totalPositions; i++) loop
- AFTER the ulong ticket= PositionGetTicket(i) statement]
Please read the MQL5 documentation - there are lots of good examples for everything you need - copy their style for optimal/better code
here is the file brother
Please follow the bullet points 3 & 4 i mentioned - your efforts will result in you learning MQL5 better.
Coding it yourself is the only way.
here is the file brother
...wouldnt new price be "... * _Point" not Digits?
...wouldnt new price be "... * _Point" not Digits?
yes brother my mistake