How can I get the „inner“ spread ? - page 2

 
It changes every tick that's all.
 
Like I said that's not a problem. My code works. I think it's because my broker didn't adjust the chart's bid and ask lines according to the real spread.

But I solved the problem with a calculation. 
 
Marbo #:

My broker adds around 5 points to each side of the spread which is displayed by the solid lines.

Again, please provide an EA or an Indicator showing the discrepancy.

I suspect you are doing something wrong, but that can only be confirmed if you show actually the code that gives you this discrepancy.
 
Dominik Egert #:
Again, please provide an EA or an Indicator showing the discrepancy.

I suspect you are doing something wrong, but that can only be confirmed if you show actually the code that gives you this discrepancy.

My code is really not the problem. I think the misunderstanding is based on my knowledge about the English language and because I know you are German I describe it in German:

Hi Dominik, ich vermute, das Problem liegt darin, dass die bid/ask Linien, die man in den Chart Settings aktivieren kann, einfach falsch sind. Ich sehe das auch in dem Orderfenster vom MT5, dass bid und ask nicht den Werten der Linien entsprechen. Mein Broker hat einfach den Spread um 5 Points auf jeder Seite erweitert, allerdings haben die dabei wohl „vergessen“, das bei den eingebauten bid/ask Linien im Chart anzupassen. Wenn ich in meinem Code bid und ask prüfe, sollten die Preise mit den bid/ask Linien im Chart identisch sein. Ist es aber hier nicht. Das ist das ganze Problem.

Ich muss das so genau wissen, da mein EA Limit Orders platziert. Wenn ich kaufen will, sobald der Preis im Chart beispielsweise 1.25500 erreicht, muss ich ja ein Limit setzten, das bei 1.25500 plus Spread liegt. Dabei ist mir eben aufgefallen, dass SymbolInfoDouble(_Symbol,SYMBOL_BID/ASK) Werte nicht den angezeigten Linien im Chart entsprechen. 

Auto-translation for text above (applied by moderator) ...

Hi Dominik, I suspect the problem is that the bid/ask lines that you can activate in the chart settings are simply wrong. I also see in the MT5 order window that bid and ask do not correspond to the values of the lines. My broker simply expanded the spread by 5 points on each side, but they probably “forgot” to adjust this with the built-in bid/ask lines in the chart. When I check bid and ask in my code, the prices should be identical to the bid/ask lines on the chart. But it isn't here. That's the whole problem.

I need to know this exactly because my EA places limit orders. If I want to buy as soon as the price in the chart reaches 1.25500, for example, I have to set a limit that is 1.25500 plus the spread. I just noticed that SymbolInfoDouble(_Symbol,SYMBOL_BID/ASK) values do not correspond to the lines displayed in the chart.

 
Marbo #:

My code is really not the problem. I think the misunderstanding is based on my knowledge about the English language and because I know you are German I describe it in German:

Hi Dominik, ich vermute, das Problem liegt darin, dass die bid/ask Linien, die man in den Chart Settings aktivieren kann, einfach falsch sind. Ich sehe das auch in dem Orderfenster vom MT5, dass bid und ask nicht den Werten der Linien entsprechen. Mein Broker hat einfach den Spread um 5 Points auf jeder Seite erweitert, allerdings haben die dabei wohl „vergessen“, das bei den eingebauten bid/ask Linien im Chart anzupassen. Wenn ich in meinem Code bid und ask prüfe, sollten die Preise mit den bid/ask Linien im Chart identisch sein. Ist es aber hier nicht. Das ist das ganze Problem.

Ich muss das so genau wissen, da mein EA Limit Orders platziert. Wenn ich kaufen will, sobald der Preis im Chart beispielsweise 1.25500 erreicht, muss ich ja ein Limit setzten, das bei 1.25500 plus Spread liegt. Dabei ist mir eben aufgefallen, dass SymbolInfoDouble(_Symbol,SYMBOL_BID/ASK) Werte nicht den angezeigten Linien im Chart entsprechen. 

Auto-translation for text above (applied by moderator) ...

Hi Dominik, I suspect the problem is that the bid/ask lines that you can activate in the chart settings are simply wrong. I also see in the MT5 order window that bid and ask do not correspond to the values of the lines. My broker simply expanded the spread by 5 points on each side, but they probably “forgot” to adjust this with the built-in bid/ask lines in the chart. When I check bid and ask in my code, the prices should be identical to the bid/ask lines on the chart. But it isn't here. That's the whole problem.

I need to know this exactly because my EA places limit orders. If I want to buy as soon as the price in the chart reaches 1.25500, for example, I have to set a limit that is 1.25500 plus the spread. I just noticed that SymbolInfoDouble(_Symbol,SYMBOL_BID/ASK) values do not correspond to the lines displayed in the chart.

No, the Ask/Bid lines are not wrong. There may sometimes be a slight delay if the Chart thread is over-burden with many Indicators or if an Indicator is malfunctioning and slowing down the functionality.

So, it is best to make sure your Chart is clean and there is nothing causing a problem with its processing. Another issue is that and Graphical Objects you place on the chart can be processed late due to the nature of how MT5 handles these objects.

You have thus far not presented any full code example that can be tested to replicate the issue. So, please provide sample code that can be compiled and tested on our end, to either replicate the issue, or to help identify what you may be doing incorrectly.

 

I absolute appreciate that you all want to help me. But my code is working perfect. It’s only the part for the OnInit() and the other part must be put in OnTick(). That’s absolutely all. There is no more code. It’s only an EA to print the REAL spread. That is all it should do and it works.

And just to proof you that I am not wrong and that the bid/ask lines are NOT displaying the real spread you can see it at this screenshot.

Please have a look at the order window and its bid/ask prices. You will see that it is not identical with the built in bid/ask lines from MT5 (which are colored in red here) but they are identical with the black dotted lines which are printed by my EA using SymbolInfoDouble(_Symbol,SYMBOL_BID/ASK). Just compare the order window to the lines in the chart and you will agree with me.

Files:
IMG_8841.jpeg  572 kb
 
Marbo #:
I absolute appreciate that you all want to help me. But my code is working perfect. It’s only the part for the OnInit() and the other part must be put in OnTick(). That’s absolutely all. There is no more code. It’s only an EA to print the REAL spread. That is all it should do and it works.

And just to proof you that I am not wrong and that the bid/ask lines are NOT displaying the real spread you can see it at this screenshot.

Please have a look at the order window and its bid/ask prices. You will see that it is not identical with the built in bid/ask lines from MT5 (which are colored in red here) but they are identical with the black dotted lines which are printed by my EA using SymbolInfoDouble(_Symbol,SYMBOL_BID/ASK). Just compare the order window to the lines in the chart and you will agree with me.

and yet, it is wrong   the chart will only ever represent the bid/ask from the broker   you drawing lines on it with your code is the difference....

either you  are doing it wrong, not updating the data or not redrawing the chart

no point keep showing pictures it will not help, you need to provide working code 

 
Paul Anscombe #:

and yet, it is wrong   the chart will only ever represent the bid/ask from the broker   you drawing lines on it with your code is the difference....

either you  are doing it wrong, not updating the data or not redrawing the chart

no point keep showing pictures it will not help, you need to provide working code 

It's really interesting that you still insist that I am wrong although you can clearly see that the values in the order window don't match with the values of the built-in bid/ask lines of MT5.

 
Marbo #:

It's really interesting that you still insist that I am wrong although you can clearly see that the values in the order window don't match with the values of the built-in bid/ask lines of MT5.

the bid/ask from the chart are derived from the brokers price feed are bult in and works for everyone else.

your line objects derived from your code don't agree, why do you keep thinking it is the system that is wrong?

you have not yet provided code that shows where and when you are creating your line objects, which means the error is most likely in your coding or sequence of code

you have also not stated what other loads are on your chart/terminal which can easliy cause delays

stop assuming you  are right and the problem will mostly likely appear :)

 
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   ObjectCreate(0,"bidLine",OBJ_HLINE,0,0,SymbolInfoDouble(_Symbol,SYMBOL_BID));
   ObjectSetInteger(0,"bidLine",OBJPROP_WIDTH,1);
   ObjectSetInteger(0,"bidLine",OBJPROP_STYLE,STYLE_DOT);
   ObjectSetInteger(0,"bidLine",OBJPROP_COLOR,clrBlack);
   ObjectSetInteger(0,"bidLine",OBJPROP_SELECTABLE,false);
   
   ObjectCreate(0,"askLine",OBJ_HLINE,0,0,SymbolInfoDouble(_Symbol,SYMBOL_ASK));
   ObjectSetInteger(0,"askLine",OBJPROP_WIDTH,1);
   ObjectSetInteger(0,"askLine",OBJPROP_STYLE,STYLE_DOT);
   ObjectSetInteger(0,"askLine",OBJPROP_COLOR,clrBlack);
   ObjectSetInteger(0,"askLine",OBJPROP_SELECTABLE,false);
      
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   ObjectSetDouble(0,"bidLine",OBJPROP_PRICE,SymbolInfoDouble(_Symbol,SYMBOL_BID));
   ObjectSetDouble(0,"askLine",OBJPROP_PRICE,SymbolInfoDouble(_Symbol,SYMBOL_ASK));
  }
//+------------------------------------------------------------------+