PDA

View Full Version : How to take current spread in OnTick event ?



NCD
07-09-2015, 01:17 PM
I am trying to detect the current spread in the OnTick event.
The problem I am facing is SymbolInfoInteger() returns TRUE (success), but
the value of spread is NULL.


Sample code follows :




Public Sub OnTick(symbolName)


If( symbolName <> ChartSymbol(0) ) Then Exit Sub
Dim spread
If( SymbolInfoInteger(ChartSymbol(0), SYMBOL_SPREAD, spread) ) Then
' Display the spread in message box
MsgBox "spread = " & spread
Else
' SymbolInfoInteger failed.
MsgBox "Could not fetch spread"
End If


End Sub

Rawan-HS
07-12-2015, 08:27 AM
Dear Sir,


Thanks for contacting us.


When the retrieved value of the spread is null that means the system administrator set the spread to be “Source ” so the spread value calculated from the Data Feed side.


But you can get the spread manually by calculate the difference between ask and bid prices on your market watch.


Check this code




Public Sub OnTick(symbolName)


If( symbolName <> ChartSymbol(0) ) Then Exit Sub
Dim Spread
Dim Bid
Dim Ask
Dim Result
If(SymbolInfoInteger(ChartSymbol(0), SYMBOL_SPREAD, spread)) Then
If not ISNUMERIC(spread) then
SymbolInfoDouble ChartSymbol(0) , SYMBOL_BID , Bid
SymbolInfoDouble ChartSymbol(0) , SYMBOL_ASK , ask
result = ask-bid
AlertMessage result
else
AlertMessage result
end if
Else
AlertMessage "Could not fetch spread"
End If




End Sub

NCD
07-13-2015, 03:15 PM
If I calculate the spread as Ask - Bid, then how to convert this value into points ? I could not find any value in ENUM_SYMBOL_INFO_DOUBLE or ENUM_SYMBOL_INFO_INTEGER that specifies the number of digits or point.

Rawan-HS
07-14-2015, 07:43 AM
Dear NCD ,


you can calculate it by division the of result of Ask - bid by the numbers of pip

check this code and tell me if you need any things :)




Public Sub OnTick(symbolName)
If( symbolName <> ChartSymbol(0) ) Then Exit Sub
Dim Spread
Dim Bid
Dim Ask
Dim pipLoc
Dim PiP
Dim Result
If(SymbolInfoInteger(ChartSymbol(0), SYMBOL_SPREAD, spread)) Then
If not ISNUMERIC(spread) then
SymbolInfoInteger ChartSymbol(0), SYMBOL_PIP_LOCATION, pipLoc
SymbolInfoDouble ChartSymbol(0) , SYMBOL_BID , Bid
SymbolInfoDouble ChartSymbol(0) , SYMBOL_ASK , ask
pip = 10 ^ pipLoc
result = (ask-bid )/pip
AlertMessage result
else
AlertMessage result
end if
Else
AlertMessage "Could not fetch spread"
End If


End Sub