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

Section for discussions related to indicators, use of indicators, and building of trading stategies using indicators.

Moderator: admin

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

Postby JakMike » Fri Feb 05, 2016 7:38 pm

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:
Attachments
Test ShowSpread.lua
Test ShowSpread
(2.07 KiB) Downloaded 545 times
JakMike
 
Posts: 4
Joined: Thu Jan 28, 2016 10:17 am

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

Postby Apprentice » Mon Feb 08, 2016 4:44 am

local ASK = core.host:findTable("offers"):find("Instrument", source:instrument()).Ask;
local BID = core.host:findTable("offers"):find("Instrument", source:instrument()).Bid;
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 23173
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

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

Postby Julia CJ » Mon Feb 08, 2016 4:46 am

Hi JakMike,

We have fixed the code. Please find it in the attachment.
Attachments
Test ShowSpread.lua
(1.99 KiB) Downloaded 576 times
Julia CJ
 

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

Postby JakMike » Mon Feb 08, 2016 9:15 am

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!
JakMike
 
Posts: 4
Joined: Thu Jan 28, 2016 10:17 am

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

Postby Julia CJ » Tue Feb 09, 2016 6:13 am

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());
Julia CJ
 


Return to Discussions

Who is online

Users browsing this forum: No registered users and 3 guests