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:
![image__23|690x137](upload://j0JRVeCSJkKqpHg8Y5yHtcPzxu9.png)
The only missing info is the pips. Everything else is correct.