I made the follow code to get the right prices. Is this code correct?
Do you know why sometimes the ask and bid prices are filled and other times they are empty? I don't understand how EA handle the price refresh yet.
/* Gets the current price to sell */ double SellPrice(){ symbolInfo.RefreshRates(); double value = symbolInfo.Ask(); if(value == 0) value = SymbolInfoDouble(symbol,SYMBOL_ASK); if(value == 0){ MqlTick tick; ResetLastError(); if(SymbolInfoTick(symbol,tick)){ value = tick.ask; } else { PrintFormat("%s: Error: %d",__FUNCTION__, GetLastError()); } if(value == 0) value = tick.last - SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_SIZE); } return value; } /* Gets the current price to buy */ double BuyPrice(){ symbolInfo.RefreshRates(); double value = symbolInfo.Bid(); if(value == 0) value = SymbolInfoDouble(symbol,SYMBOL_BID); if(value == 0){ MqlTick tick; ResetLastError(); if(SymbolInfoTick(symbol,tick)){ value = tick.bid; } else { PrintFormat("%s: Error: %d",__FUNCTION__, GetLastError()); } if(value == 0) value = tick.last + SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_SIZE); } return value; }
I made the follow code to get the right prices. Is this code correct?
Do you know why sometimes the ask and bid prices are filled and other times they are empty? I don't understand how EA handle the price refresh yet.
Hi Rafael,
By this way, I always get the price (^̮^)
Hope it helps.
bool NewPositionBuy(......) { ResetLastError(); ZeroMemory(request); ZeroMemory(result); int ke=1; bool exit=false; //-- your request entry here --// request.action =TRADE_ACTION_DEAL; // trade operation request.type =ORDER_TYPE_BUY; // order type ........... ........... //--loop to get better price for current position while (!OrderSend(request,result)) //--this loop will ended after request is done { if(result.retcode==TRADE_RETCODE_REQUOTE) { if(ke<=1) Print("* Requotes. Wait for better price ..."); } else { Print("*! ",getErrorTradeDesc(result.retcode)); exit=true; break; //--exit from current loop } ke++; //-- read how many times EA read the price MqlTick ticknow; SymbolInfoTick(symbol,ticknow); request.price=SymbolInfoDouble(symbol,SYMBOL_ASK); // price Sleep(1000); //---- 1 second wait } if(exit) { Print("*! Can't open new position Buy. >>> (error: ",result.retcode,". Desc : ",getErrorTradeDesc(result.retcode),") "); //--do something, entry failed return(false); } //--do something after new position was opened return(true); }//-- eof NewPositionBuy
Btw, many coders have different logic, and code above is my simply logic.
You can try it if you wish ʘ‿ʘ
Yo.
Hi Rafael,
By this way, I always get the price (^̮^)
Hope it helps.
Btw, many coders have different logic, and code above is my simply logic.
You can try it if you wish ʘ‿ʘ
Yo.
So do you get ticknow and use for what?
These two lines are useless.
MqlTick ticknow; SymbolInfoTick(symbol,ticknow);
if(value == 0) value = tick.last - SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_SIZE);
I made the follow code to get the right prices. Is this code correct?
Do you know why sometimes the ask and bid prices are filled and other times they are empty? I don't understand how EA handle the price refresh yet.
if(value == 0) value = tick.last - SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_SIZE);
this tick is not in the right place...

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
The SYMBOL_BID and SYMBOL_ASK are always returning zero. Did I something wrong?