[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] vbScript Problem



PureBytes Links

Trading Reference Links

Hello,

First you are indexing arrays before declaring them. Variables in VBScript
represent simple types. Arrays must be defined or copied from another array
to be initialized properly, so before:
> For i = 0 To UBound(vbH)
> vbUpBar(i) = 0
> vbDownBar(i) = 0
> vbOutsideBar(i) = 0
> vbInsideBar(i) = 0
> vbPeakBar(i) = 0
> vbTroughBar(i) = 0
> Next

you should write
vbUpBar = vbH
vbDownBar = vbH
vbOutsideBar = vbH
vbInsideBar = vbH
vbPeakBar = vbH
vbTroughBar = vbH

Second thing: you are using Select Case statement wrong
Select Case True simply causes an error.
Ordinary If ... Then is more appropriate.

Third thing: you access array elements outside of bounds.

Fourth thing: Do While i > 0 loop never ends.

Fifth thing: be aware that coding this in VBScript will be at least 10 
times slower than in AFL. 

Best regards,
Tomasz Janeczko
===============
AmiBroker - the comprehensive share manager.
http://www.amibroker.com

----- Original Message ----- 
From: <gmulhall@xxxx>
To: <amibroker@xxxxxxxxxxxxxxx>
Sent: Wednesday, June 06, 2001 1:30 PM
Subject: [amibroker] vbScript Problem


> Folks,
> 
> Can anyone spot the cause of the error
> 
> "ActiveScriptSite::OnScriptError()
> Line 8, Character 5
> Line text:"
> 
> in the script below pls ?
> 
> 
> Geoff (getting desperate !)
> 
> 
> /* Buy on Gann Swing Gap AFL Implementation by Geoff Mulhall 4/6/2001 
> */
> 
> dollars = 5000;
> AtrRange = 200;
> 
> EnableScript("vbscript");
> <%
> vbH = AFL( "high" )
> vbL = AFL( "low" )
> 
> rem---------Initialize Arrays
> 
> For i = 0 To UBound(vbH)
> vbUpBar(i) = 0
> vbDownBar(i) = 0
> vbOutsideBar(i) = 0
> vbInsideBar(i) = 0
> vbPeakBar(i) = 0
> vbTroughBar(i) = 0
> Next
> 
> rem---------Flag UpBars, Downbars, InsideBars, OutsideBars
> 
> For i = 0 To Ubound(vbH)
> Select Case True
> Case (vbH(i + 1) > vbH(i) And vbL(i + 1) >= vbL(i))
> vbUpBar(i + 1) = 1
> Case (vbL(i + 1) < vbL(i + 1) And vbH(i + 1) <= vbH(I))
> vbDownBar(i + 1) = 1
> Case (vbH(i + 1) > vbH(i) And vbLow(i + 1) < vbLow(i))
> vbOutsideBar(i + 1) = 1
> Case (vbH(i + 1) <= vbH(i) And vbL(i + 1) >= vbL(i))
> vbInsideBar(i + 1) = 1
> End Select
> Next
> 
> rem------------Flag Peak and Trough Bars
> 
> For i = 1 To UBound(vbH)
> Select Case True
> Case (vbUpBar(i) = 1 And vbDownBar(i + 1) = 1)
> vbPeakBar(i) = 1
> Case (vbDownBar(i) And vbUpBar(i + 1))
> vbTroughBar = 1
> Case (vbOutsideBar = 1)
> For j = i + 1 To UBound(vbH)
> Select Case True
> Case (vbUpBar(j) = 1)
> vbTroughBar(i) = 1
> Exit For
> Case (vbDownBar(j) = 1)
> vbPeakBar(i) = 1
> Exit For
> End Select
> Next
> End Select
> Next
> 
> rem--------------Scan for Gaps
> 
> i = Ubound(vbH)
> 
> Do While i > 0
> 
> vb1stTroughFound = False
> vb2ndTroughFound = False
> vb1stPeakFound = False
> vb2ndPeakFound = False
> 
> For j = i To 0 Step -1
> 
> Select Case True
> Case (Not vb1stTroughFound And vbTroughBar(j) = 1)
> Trough1 = vbL(j)
> vb1stTroughFound = True
> Case (Not vb1stPeakFound And vbPeakBar(j) = 1)
> Peak1 = vbH(j)
> vb1stPeakFound = True
> Case (Not vb2ndTroughFound And vb1stTroughFound And 
> vbTroughBar(j) = 1)
> Trough2 = vbL(j)
> vb2ndTroughFound = True
> vbNextStart = j
> Case (Not vb2ndPeakFound And vb1stPeakFound And vbPeakBar
> (j) = 1)
> Peak2 = vbH(j)
> vb2ndPeakFound = True
> End Select
> 
> If vb1stPeakFound And vb2ndPeakFound And _
> vb1stTroughFound And vb2ndTroughFound Then
> If Trough1 > Peak2 And (Peak1 - Trough2) / 2 < Trough1 
> Then
> vbBuy(i) = 1
> End If
> End If
> 
> If vb2ndTroughFound Then
> i = vbNextStart
> Exit For
> Else
> i = j
> End If
> Next
> 
> Loop
> 
> AFL ("buy" ) = vbBuy
> %>
> 
> BangForBucks = (dollars/close) * atr(AtrRange);
> 
> filter = buy; 
> 
> numcolumns = 2;
> column0 = close;
> column0format = 3.2;
> column0name = "Close";
> column1= BangForBucks;
> column1ormat = 5.2;
> column1name = "BangForBucks"; 
> 
> sell = 0;
> 
> /* buy = exrem(buy,sell); 
> sell = exrem(sell,buy);*/
> 
> 
> 
> 
> 
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 
> 
> 
>