Results 1 to 4 of 4
  1. #1
    malcolm
    Guest

    Default How to get values from BollingerBands study into an Array?

    Dear Fellow Programmers

    I am trying to use Bollinger Bands in an indicator (VTL Client Side Script) and I have 2 issues:

    (1) When I try and use the BollingerBands(0,Price_close,20,2,1) study, this puts the study below the chart panel. I would like this study/indicator to be superimposed on the price chart as it is normally used. I tried using Chart ID 0, but no luck. Any suggestions?

    (2) Someone suggested extracting the values from
    BollingerBands(0,Price_close,20,2,1) into an array and then passing this array to the AddCustomIndicator function and then use the SubWindow/Panel ID to put the study on top of the price bars. However, when you try and use BollingerBands(0,Price_close,20,2,1) in your code, it just returns the handle. How do you get the actual Bollinger Bands values to put into an array?

    For example Upper Bollinger Band value at Bar1 = 1.0224, Upper Bollinger Band Value at Bar2 = 1.0226, etc. Lower Bollinger Band Value at Bar1 = 1.0202, etc.

    Any help would be much appreciated as this is very urgent.

    Thank you in advance.

    Malcolm

  2. #2
    Administrator Hassan-HS's Avatar
    Join Date
    Jun 2013
    Posts
    795

    Default

    Hello,


    You can use iBandsOnArray method to get the array of the Bollinger bands then you can add it easily to the chart.


    Please check this code
    Code:
     Dim indKey1
     Dim indKey2
     Dim indKey3
     Dim ary ()
     Dim Top()
     Dim Bottom()
     Dim Period
     Dim result()
     Dim MA_Type
     Dim StandardDeviation
     Public Sub main()
        Period = 13
        MA_Type = 1
    	StandardDeviation = 2
        CopyClose 0, 1, Bars (0), Ary
        iBandsOnArray Ary, CInt(Period), CInt(StandardDeviation), CInt (MA_Type), Result,Top,Bottom
    	For i= 1 to Period
    		Result(i)=-987654321 ' DTNull Value, because the 0 is not a valid value
    		Top(i)=-987654321
    		Bottom(i)=-987654321
    	Next
    	indKey1=AddCustomIndicator(0, Result,1,False)
    	indKey2=AddCustomIndicator(0, Top,1,False)
    	indKey3=AddCustomIndicator(0, Bottom,1,False)
    End Sub
    
    
    ''' <summary>
    ''' To Update the bollinger band every new candle.....
    ''' </summary>
    
    
    Public Sub OnCalculate(symbol, symbolPeriod, openVal, highVal, lowVal, closeVal)
    	CopyClose 0, 1, Bars (0), Ary
        iBandsOnArray Ary, CInt(Period), CInt(StandardDeviation), CInt (MA_Type), Result,Top,Bottom
    	SetIndicatorData 0,CSTR(indKey1),CDbl(Result(Ubound(Result)))
    	SetIndicatorData 0,CSTR(indKey2),CDbl(Top(Ubound(Top)))
    	SetIndicatorData 0,CSTR(indKey3),CDbl(Bottom(Ubound(Bottom)))
    End Sub
    
    
    ''' <summary>
    ''' The function is generated when deinitialization script
    ''' </summary>
    
    
    Public Sub OnDeInit()
    '''TODO: deinitialization method
    	ObjectDelete 0,CSTR(indKey1)
    	ObjectDelete 0,CSTR(indKey2)
    	ObjectDelete 0,CSTR(indKey3)
    End Sub

  3. #3
    malcolm
    Guest

    Default

    Thank you very much. We will take a look now.

  4. #4
    Administrator Hassan-HS's Avatar
    Join Date
    Jun 2013
    Posts
    795

    Default

    Great, welcome bro

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. CCI on Array
    By Edakad in forum VertexFX API/VTL Forum
    Replies: 3
    Last Post: 07-12-2015, 11:23 AM
  2. Array access through index
    By Balasaravanan in forum VertexFX API/VTL Forum
    Replies: 2
    Last Post: 07-11-2014, 08:45 AM
  3. Updating values of a Custom Indicator
    By novice in forum VertexFX API/VTL Forum
    Replies: 7
    Last Post: 02-24-2014, 11:32 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •