
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I have extracted segments for testing.
ulong ticket = PositionSelectByTicket(219405612);
string position_symbol = PositionGetString(POSITION_SYMBOL);
double orderPriceCurrent = PositionGetDouble(POSITION_PRICE_CURRENT);
double price_difference = PositionGetDouble(POSITION_PRICE_OPEN) - orderPriceCurrent;
double point = SymbolInfoDouble(position_symbol,SYMBOL_POINT);
int digits = SymbolInfoInteger(position_symbol,SYMBOL_DIGITS);
Print("Difference: " + price_difference + " Point: " + point + " Digits: " + digits);
OUTPUT: 2018.11.09 17:14:02.667 Slave_Reader_CopyTrade_BTI_test (EURUSD,H1) Difference: -0.000220000000000109 Point: 1e-05 Digits: 5
All works up till then normally.
You are still doing it wrong. PositionSelectByTicket does not return a ticket, it returns a "boolean" which should be checked, as shown in my sample code. You even ignored the formatting example.
I know you mean well and want to help, but if the OP barely understands the basics of procedural programing, how do you expect him to fathom libraries, classes and OOP?
Let him first grasp the basics before complicating things for him with advanced coding techniques.
I know you mean well and want to help, but if the OP barely understands the basics of procedural programing, how do you expect him to fathom libraries, classes and OOP?
Let him first grasp the basics before complicating things for him with advanced coding techniques.
here is the actual code complete with all other statements. everything works as it should with the exception of the pip calculation. It worked fine on MQL4 for 3 years and I am only battling now as I have to convert to MQL5. As I said, everything else updates as it should.
for(uint i=0;i<total;i++) {
//--- return order ticket by its position in the list
if((ticket=PositionGetTicket(i))>0){
//--- return order properties
open_price =PositionGetDouble(POSITION_PRICE_OPEN);
time_setup =(datetime)PositionGetInteger(POSITION_TIME);
symbol =PositionGetString(POSITION_SYMBOL);
order_magic =PositionGetInteger(POSITION_MAGIC);
initial_volume=PositionGetDouble(POSITION_VOLUME);
type =EnumToString(ENUM_ORDER_TYPE(PositionGetInteger(POSITION_TYPE)));
//--- prepare and show information about the order
//Print(ORDER_PRICE_CURRENT);
double orderProfit = PositionGetDouble(POSITION_PROFIT);
double orderSwap = PositionGetDouble(POSITION_SWAP);
double orderCommission = PositionGetDouble(POSITION_COMMISSION);
double orderStoploss = PositionGetDouble(POSITION_SL);
double orderTakeProfit = PositionGetDouble(POSITION_TP);
double orderPriceCurrent;
double orderPriceClose;
int orderTicket = ticket;
int orderInProfit;
int orderType;
int tradeDirection;
int tradeStatus;
if(type == 0){tradeDirection = 0; orderType = 0;}
if(type == 1){tradeDirection = 1; orderType = 1;}
string orderOpenTime = PositionGetInteger(POSITION_TIME);
string orderCloseTime = DEAL_ENTRY_OUT;
string orderVolume = PositionGetDouble(POSITION_VOLUME);
if(orderCloseTime > 1){tradeStatus = 0;} else {tradeStatus = 1;}
orderPriceCurrent = PositionGetDouble(POSITION_PRICE_CURRENT);
if(tradeStatus == 0){orderPriceClose = PositionGetDouble(POSITION_PRICE_CURRENT);} else {orderPriceClose = "";}
//check if ticket exists with same account number and if open
string rowQuery2 = "SELECT number, ticket FROM transactions_slave WHERE number = '"+accountNumber+"' && ticket = '"+orderTicket+"' LIMIT 1";
long row_result2 = MySqlCursorOpen(dbConnectId, rowQuery2);
//if not found, then insert into database (order open from M30 etc), set flag = 1
if(MySqlCursorRows(row_result2) == 0){
//write to database
string rowQuery3 = "INSERT INTO `transactions_slave` (ticket, symbol, type, volume, price, slippage, stoploss, takeprofit, comment_open, comment_close, magicnumber, expiration, arrow_colour, period, status, spread, verify_status, number) VALUES ('"+orderTicket+"','"+PositionGetString(POSITION_SYMBOL)+"','"+type+"','"+PositionGetDouble(POSITION_VOLUME)+"','"+PositionGetDouble(POSITION_PRICE_OPEN)+"','','"+PositionGetDouble(POSITION_SL)+"','"+PositionGetDouble(POSITION_TP)+"','"+PositionGetString(POSITION_COMMENT)+"','""','"+PositionGetInteger(POSITION_MAGIC)+"','','clr','"+Period()+"','1','','1','"+accountNumber+"') ";
long insert_result3 = MySqlExecute(dbConnectId, rowQuery3);
} else {
int point_compat = 10;
if(_Digits == 3 || _Digits == 5) point_compat = 10;
double orderPips;
string position_symbol = PositionGetString(POSITION_SYMBOL);
if(orderType == 0){ //buy order
orderPips = MathAbs((NormalizeDouble(((orderPriceCurrent - PositionGetDouble(POSITION_PRICE_OPEN))/SymbolInfoDouble(position_symbol,SYMBOL_POINT)),SymbolInfoInteger(position_symbol,SYMBOL_DIGITS)))/point_compat); //price 2 is current, price 1 is open
if(orderPriceCurrent < PositionGetDouble(POSITION_PRICE_OPEN)){orderPips = orderPips * -1;}
}
if(orderType == 1){ // sell order
orderPips = MathAbs((NormalizeDouble(((PositionGetDouble(POSITION_PRICE_OPEN) - orderPriceCurrent)/SymbolInfoDouble(position_symbol,SYMBOL_POINT)),SymbolInfoInteger(position_symbol,SYMBOL_DIGITS)))/point_compat); //price 1 is open, price 2 is current
if(orderPriceCurrent > PositionGetDouble(POSITION_PRICE_OPEN)){orderPips = orderPips * -1;}
}
//Print("Open Price:" +OrderOpenPrice()+ "Current Price: " +orderPriceCurrent+ "Pips: " +orderPips);
//if ticket does exit then update info
string rowQuery4 = "UPDATE transactions_slave SET volume = '"+orderVolume+"', pips = '"+orderPips+"', type = '"+orderType+"', profit = '"+orderProfit+"', swap = '"+orderSwap+"', commission = '"+orderCommission+"', stoploss = '"+orderStoploss+"', takeprofit = '"+orderTakeProfit+"', price_current = '"+orderPriceCurrent+"', order_open_time = '"+orderOpenTime+"', order_close_time = '"+orderCloseTime+"', price_close = '"+orderPriceClose+"', verify_status = '1' WHERE ticket = '"+orderTicket+"' LIMIT 1";
long row_result4 = MySqlExecute(dbConnectId, rowQuery4);
}
MySqlCursorClose(row_result2);
//do this in same loop
//}
}
}
This updates every 10 seconds:
The only missing info is the pips. Everything else is correct.
I know you mean well and want to help, but if the OP barely understands the basics of procedural programing, how do you expect him to fathom libraries, classes and OOP?
Let him first grasp the basics before complicating things for him with advanced coding techniques.
OOP isn't the scary and "advanced" concept every here tries to make it out to be. Heck, my son is even learning it in his python class in middle-school.
If you're working with MQL5, you can't get around without knowing OOP, and I would argue that cluttering up your src file with 1000 character lines full of nested function calls is way more error prone and difficult to mentally parse than any OOP code I've ever seen.
here is the actual code complete with all other statements.
Please format your code for this forum before posting it. Use the </> button in the editor.
Please format your code for this forum before posting it.
Sorry :(
This updates every 10 seconds:
Well, you're clearing ignoring the compiler warnings of implicit conversion....
nicholi shen: OOP isn't the scary and "advanced" concept every here tries to make it out to be. Heck, my son is even learning it in his python class in middle-school.
If you're working with MQL5, you can't get around without knowing OOP, and I would argue that cluttering up your src file with 1000 character lines full of nested function calls is way more error prone and difficult to mentally parse than any OOP code I've ever seen.
Please trust me when I say this, and I am not the only one saying it: For most users, OOP is too complicated and difficult to understand. It is in fact "scary" for them!
Whether you find it easy or not is besides the point. Most users, even seasoned ones, try to stay away from it. They prefer writing 1000 extra lines of code than to face using OOP. That is just the reality of things!
So please understand that ramming it down throats will not help and it will actually just make them resent it even more.
What I would suggest, is a middle ground, where you present both a Procedural sample as well as the OOP version, so that they can see both and decide for themselves. By seeing both versions, they can then understand the OOP version better and may even be tempted to try develop their skills in OOP. But if you only provide the OOP version, they will most probably just skip over it all together.
Well, you're clearing ignoring the compiler warnings of implicit conversion....
Yes I currently as they wont be yielding the problem I am having.
Please trust me when I say this, and I am not the only one saying it: For most users, OOP is too complicated and difficult to understand. It is in fact "scary" for them!
Whether you find it easy or not is besides the point. Most users, even seasoned ones, try to stay away from it. They prefer writing 1000 extra lines of code than to face using OOP. That is just the reality of things!
So please understand that ramming it down throats will not help and it will actually just make them resent it even more.
What I would suggest, is a middle ground, where you present both a Procedural sample as well as the OOP version, so that they can see both and decide for themselves. By seeing both versions, they can then understand the OOP version better and may even be tempted to try develop there skills in OOP. But if you only provide the OOP version, they will most probably just skip over it all together.
I have come from a Java background and honestly I like a challenge but wont go close to OOP. Its just my preference as I find it easier to debug and read later on again.