Page 1 of 1

How to get the Value (Ask/Bid) for the Spread?

PostPosted: Fri Feb 05, 2016 7:38 pm
by JakMike
Hello
I wrote my first little indicator for showing the spread Value on the Top Right Corner.
But I do have problems to get the actual value for the Ask and Bid price to calculate the Spread.
I tried different approaches but didn't solved it yet. I wrote into the code (see below) the errors which I got on each approach.
Can anybody help me and tell me, what I do wrong here?
Thanks
P.S. attached the code:

Re: How to get the Value (Ask/Bid) for the Spread?

PostPosted: Mon Feb 08, 2016 4:44 am
by Apprentice
local ASK = core.host:findTable("offers"):find("Instrument", source:instrument()).Ask;
local BID = core.host:findTable("offers"):find("Instrument", source:instrument()).Bid;

Re: How to get the Value (Ask/Bid) for the Spread?

PostPosted: Mon Feb 08, 2016 4:46 am
by Julia CJ
Hi JakMike,

We have fixed the code. Please find it in the attachment.

Re: How to get the Value (Ask/Bid) for the Spread?

PostPosted: Mon Feb 08, 2016 9:15 am
by JakMike
Hi Julia

Thank you very much for adapting the code - it works fine.
I just have a question to the code line:
Code: Select all
bid = core.host:execute("getSyncHistory", source:instrument(), source:barSize(), true, 0, 100, 101);

These integer numbers at the end (100, 101), do they have a specific meaning or can they be also 1 and 2? They just have to correspond to the numbers used in the function AsyncOperationFinished, right?

Another thing which I do not understand is, why I do not get a result when I use the code:
Code: Select all
print(source:barSize());
? Per my understanding this code should give an result i.e. "m5".

Thanks!

Re: How to get the Value (Ask/Bid) for the Spread?

PostPosted: Tue Feb 09, 2016 6:13 am
by Julia CJ
Hi JakMike,

These integer numbers at the end (100, 101), do they have a specific meaning or can they be also 1 and 2?

There are may be 1 and 2 values.


They just have to correspond to the numbers used in the function AsyncOperationFinished, right?

Ths is true.
Code: Select all
print(source:barSize());

Per my understanding this code should give an result i.e. "m5".


Try to use this code:
Code: Select all
core.host:trace(source:barSize());