PDA

View Full Version : Script showing error in different time chart for different insturment



nhasan
04-22-2015, 04:45 AM
Dear Team
I have converted a MQL indicator into VTL client script.
Logically it should work in all time chart for all instrument, but in my test it shows error in some specific chart.
Error message is: Subscript out of range '[number:0]'
I have tested it in three different instrument and five time chart and the result is as follows
It works without error in 1H, 30M, 5M for GBP/USD, 1M, 30M, 1H for EUR/USD and 5M, 15M, 1M for AUD/USD
But it sows the above error in 1M, 15M for GBP/USD, 5M, 15M for EUR/USD and 1M, 30M for AUD/USD

Please check and help me to avoid those unusual issues in this acript

I am trying to attach the vtl file, but manage attachment section of this site is not working properly.
So, I have posted the code here -

'################################################# ##########
' Script Name : VTL Paramon Scalp
' Author : Naeem Hasan
' Contact Mail: naeem.hasan@yahoo.com
' Description : This Client Script will draw four lines on the chart based on user selected time period.
' : There are two set time variables for user input. Time_Start_1 Time_End_1 and Time_Start_2 Time_End_2
' : It will draw two lines above high price and another two lines below low price from both set of start to end time period
' : There are another variable to specify market volitile Maximum_Volatility_Allowed,
' : If price difference between high and low is greater than this value no line will be shown for that time period
' : As a daily time based indicator this works properly in 30M, and 1H time period
' Date : November, 19, 2014
' User Input : User input can be changed from line 49 to 54
'################################################# ##########

Dim vchartId
Dim vchartName
Dim resultValue
Dim bar_count

Dim highArray()
Dim lowArray()
Dim timeArray()
Dim closeArray()

Dim hIndex
Dim lIndex
Dim tIndex

Dim Channel0()
Dim Channel1()
Dim Channel2()
Dim Channel3()

Dim indKey0
Dim indKey1
Dim indKey2
Dim indKey3

Dim Time_Start_1
Dim Time_End_1
Dim Time_Start_2
Dim Time_End_2
Dim Max_Volatility_Allowed
Dim Decimal_Point

Public Sub OnInit()
''''TODO: initialization method
'###### User Input ############
Time_Start_1 ="06:00"
Time_End_1 ="11:00"
Time_Start_2 ="15:00"
Time_End_2 ="20:00"
Decimal_Point = 0.0001
Max_Volatility_Allowed = 40
'#########################
End Sub


Public Sub main ()


Dim Clr_White
Dim Clr_Yellow
Dim Clr_Red
Dim Clr_Orange
Dim Clr_Olive
Dim Clr_Gray

ObjectDeleteAll(0)

vchartId=chartId

vchartName=ChartSymbol(Clng(vchartId))

bar_count = Bars(0)

ReDim highArray(bar_count-1)
ReDim lowArray(bar_count-1)
ReDim timeArray(bar_count-1)
ReDim closeArray(bar_count-1)

ReDim Channel0(bar_count-1)
ReDim Channel1(bar_count-1)
ReDim Channel2(bar_count-1)
ReDim Channel3(bar_count-1)

Call Calculate_Channels

indKey0 = AddCustomIndicator (0, Channel0, 1, False )
indKey1 = AddCustomIndicator (0, Channel1, 1, False )
indKey2 = AddCustomIndicator (0, Channel2, 1, False )
indKey3 = AddCustomIndicator (0, Channel3, 1, False )


Clr_White = RGBColor(255,255,255)
Clr_Sky = RGBColor(0,255,255)
Clr_Red = 255
Clr_Black = 0
Clr_Olive = RGBColor(128,128,0)
Clr_Gray = RGBColor(128,128,128)
Clr_Orange = RGBColor(255, 69, 0)

SetDrawingStyle 0, cstr(indKey0), DRAW_LINE
LineColor 0, indKey0, Clr_Sky

SetDrawingStyle 0, cstr(indKey1), DRAW_LINE
LineColor 0, indKey1, Clr_White

SetDrawingStyle 0, cstr(indKey2), DRAW_LINE
LineColor 0, indKey2, Clr_Olive

SetDrawingStyle 0, cstr(indKey3), DRAW_LINE
LineColor 0, indKey3, Clr_Orange



End Sub

Function Calculate_Channels()

Dim i
Dim shift
Dim Start_Time_1
Dim Start_Time_2
Dim End_Time_1
Dim End_Time_2
Dim BTime
Dim cHigh
Dim cLow

bar_count = Bars(0)


'Make all indicator arrays
CopyHigh 0, 1, Clng(bar_count), Channel0
CopyHigh 0, 1, Clng(bar_count), Channel1
CopyLow 0, 1, Clng(bar_count), Channel2
CopyLow 0, 1, Clng(bar_count), Channel3

'Make Price Arrays
CopyHigh 0, 1, Clng(bar_count), highArray
hIndex = Ubound(highArray)

CopyLow 0, 1, Clng(bar_count), lowArray
lIndex = Ubound(lowArray)

CopyTime 0, 1, Clng(bar_count), timeArray
tIndex = Ubound(timeArray)


Start_Time_1 = Left(Time_Start_1,2)*60 + Right(Time_Start_1,2)
Start_Time_2 = Left(Time_Start_2,2)*60 + Right(Time_Start_2,2)
End_Time_1 = Left(Time_End_1,2)*60 + Right(Time_End_1,2)
End_Time_2 = Left(Time_End_2,2)*60 + Right(Time_End_2,2)


If tIndex > 0 And lIndex > 0 And hIndex > 0 Then

For i = 1 to lIndex
BTime = Hour(timeArray(i)) * 60 + Minute(timeArray(i))
if BTime > Start_Time_1 then
highArray(i) = 0
lowArray(i) = 10000
End IF

Next

cLow = 10000
cHigh = 0
For i = 1 to tIndex
if highArray(i) = 0 then cHigh = 0
if lowArray(i) = 10000 then cLow = 10000
if highArray(i) <> 0 then
if highArray(i) > cHigh then cHigh = highArray(i)
highArray(i) = cHigh
End IF
if lowArray(i) <> 10000 Then
If lowArray(i) < cLow then cLow = lowArray(i)
lowArray(i) = cLow
End If

Next

For i = tIndex to 1 Step - 1
if highArray(i) = 0 then cHigh = 0
if lowArray(i) = 10000 then cLow = 10000
if highArray(i) <> 0 then
if highArray(i) > cHigh then cHigh = highArray(i)
highArray(i) = cHigh
End IF
if lowArray(i) <> 10000 Then
If lowArray(i) < cLow then cLow = lowArray(i)
lowArray(i) = cLow
End If

Next

For i =1 to tIndex
if highArray(i)=0 then highArray(i)=highArray(i-1)
if lowArray(i)= 10000 then lowArray(i)=lowArray(i-1)
Next

For i = 1 to lIndex

BTime = Hour(timeArray(i)) * 60 + Minute(timeArray(i))
if BTime <= Start_Time_1 OR BTime => End_Time_1 Then
if BTime <= Start_Time_2 OR BTime => End_Time_2 Then
highArray(i) = 0
lowArray(i) = 10000
End If
End IF

Next


End if

bar_count = Clng(bar_count)

if bar_count <=0 then exit function

For shift = bar_count To 1 Step - 1

if highArray(shift) <> 0 then
Channel0(shift) = highArray(shift)
Channel1(shift) = highArray(shift) + 10 * Decimal_Point
else
Channel0(shift) = -987654321
Channel1(shift) = -987654321
end if

if lowArray(shift) <> 10000 then
Channel2(shift) = lowArray(shift)
Channel3(shift) = lowArray(shift) - 10 * Decimal_Point
else
Channel2(shift) = -987654321
Channel3(shift) = -987654321
end if

Next

End Function


Public Sub OnTick(SymbolName)

IF symbol = ChartSymbol(0) Then

Call Calculate_Channels

SetIndicatorData 0,CSTR(indKey0),CDbl(Channel0(Ubound(Channel0)- 1))
SetIndicatorData 0,CSTR(indKey1),CDbl(Channel1(Ubound(Channel1)- 1))
SetIndicatorData 0,CSTR(indKey2),CDbl(Channel2(Ubound(Channel2)- 1))
SetIndicatorData 0,CSTR(indKey3),CDbl(Channel3(Ubound(Channel3)- 1))

End IF

End Sub



Public Sub OnCalculate(symbol ,symPeriod, openVal , highVal , lowVal , closeVal )

IF symbol = ChartSymbol(0) Then
bar_count = Bars(0)
ReDim highArray(bar_count-1)
ReDim lowArray(bar_count-1)
ReDim timeArray(bar_count-1)
ReDim timeMinute(bar_count-1)
ReDim closeArray(bar_count-1)

ReDim Channel0(bar_count-1)
ReDim Channel1(bar_count-1)
ReDim Channel2(bar_count-1)
ReDim Channel3(bar_count-1)

Call Calculate_Channels

SetIndicatorData 0,CSTR(indKey0),CDbl(Channel0(Ubound(Channel0)- 1))
SetIndicatorData 0,CSTR(indKey1),CDbl(Channel1(Ubound(Channel1)- 1))
SetIndicatorData 0,CSTR(indKey2),CDbl(Channel2(Ubound(Channel2)- 1))
SetIndicatorData 0,CSTR(indKey3),CDbl(Channel3(Ubound(Channel3)- 1))

End IF

End Sub

Public Sub OnDeInit()
'''TODO: deinitialization method
ObjectDeleteAll 0

End Sub

Hassan-HS
04-24-2015, 12:13 PM
Hello Neam,


We will study this and update you, please standby

Rawan-HS
04-29-2015, 06:24 AM
Dear Neam,
check this code .





'################################################# ##########
' Script Name : VTL Paramon Scalp
' Author : Naeem Hasan
' Contact Mail: naeem.hasan@yahoo.com
' Description : This Client Script will draw four lines on the chart based on user selected time period.
' : There are two set time variables for user input. Time_Start_1 Time_End_1 and Time_Start_2 Time_End_2
' : It will draw two lines above high price and another two lines below low price from both set of start to end time period
' : There are another variable to specify market volitile Maximum_Volatility_Allowed,
' : If price difference between high and low is greater than this value no line will be shown for that time period
' : As a daily time based indicator this works properly in 30M, and 1H time period
' Date : November, 19, 2014
' User Input : User input can be changed from line 49 to 54
'################################################# ##########


Dim vchartId
Dim vchartName
Dim resultValue
Dim bar_count
Dim highArray()
Dim lowArray()
Dim timeArray()
Dim closeArray()


Dim hIndex
Dim lIndex
Dim tIndex


Dim Channel0()
Dim Channel1()
Dim Channel2()
Dim Channel3()


Dim indKey0
Dim indKey1
Dim indKey2
Dim indKey3


Dim Time_Start_1
Dim Time_End_1
Dim Time_Start_2
Dim Time_End_2
Dim Max_Volatility_Allowed
Dim Decimal_Point


Public Sub OnInit()
''''TODO: initialization method
'###### User Input ############
Time_Start_1 ="06:00"
Time_End_1 ="11:00"
Time_Start_2 ="15:00"
Time_End_2 ="20:00"
Decimal_Point = 0.0001
Max_Volatility_Allowed = 40
'#########################
End Sub




Public Sub main()


' Open or Create File and write Data , finally Close it


Dim Clr_White
Dim Clr_Yellow
Dim Clr_Red
Dim Clr_Orange
Dim Clr_Olive
Dim Clr_Gray


ObjectDeleteAll(0)


vchartId=chartId


vchartName=ChartSymbol(Clng(vchartId))


bar_count = Bars(0)


ReDim highArray(bar_count-1)
ReDim lowArray(bar_count-1)
ReDim timeArray(bar_count-1)
ReDim closeArray(bar_count-1)


ReDim Channel0(bar_count-1)
ReDim Channel1(bar_count-1)
ReDim Channel2(bar_count-1)
ReDim Channel3(bar_count-1)


Call Calculate_Channels

indKey0 = AddCustomIndicator (0, Channel0, 1, False )
indKey1 = AddCustomIndicator (0, Channel1, 1, False )
indKey2 = AddCustomIndicator (0, Channel2, 1, False )
indKey3 = AddCustomIndicator (0, Channel3, 1, False )




Clr_White = RGBColor(255,255,255)
Clr_Sky = RGBColor(0,255,255)
Clr_Red = 255
Clr_Black = 0
Clr_Olive = RGBColor(128,128,0)
Clr_Gray = RGBColor(128,128,128)
Clr_Orange = RGBColor(255, 69, 0)


SetDrawingStyle 0, cstr(indKey0), DRAW_LINE
LineColor 0, indKey0, Clr_Sky


SetDrawingStyle 0, cstr(indKey1), DRAW_LINE
LineColor 0, indKey1, Clr_White


SetDrawingStyle 0, cstr(indKey2), DRAW_LINE
LineColor 0, indKey2, Clr_Olive


SetDrawingStyle 0, cstr(indKey3), DRAW_LINE
LineColor 0, indKey3, Clr_Orange





End Sub


Function Calculate_Channels()

Dim i
Dim shift
Dim Start_Time_1
Dim Start_Time_2
Dim End_Time_1
Dim End_Time_2
Dim BTime
Dim cHigh
Dim cLow


bar_count = Bars(0)




'Make all indicator arrays
CopyHigh 0, 1, Clng(bar_count), Channel0
CopyHigh 0, 1, Clng(bar_count), Channel1
CopyLow 0, 1, Clng(bar_count), Channel2
CopyLow 0, 1, Clng(bar_count), Channel3



'Make Price Arrays
CopyHigh 0, 1, Clng(bar_count), highArray
hIndex = Ubound(highArray)


CopyLow 0, 1, Clng(bar_count), lowArray
lIndex = Ubound(lowArray)


CopyTime 0, 1, Clng(bar_count), timeArray


tIndex = Ubound(timeArray)




Start_Time_1 = Left(Time_Start_1,2)*60 + Right(Time_Start_1,2)
Start_Time_2 = Left(Time_Start_2,2)*60 + Right(Time_Start_2,2)
End_Time_1 = Left(Time_End_1,2)*60 + Right(Time_End_1,2)
End_Time_2 = Left(Time_End_2,2)*60 + Right(Time_End_2,2)




If tIndex > 0 And lIndex > 0 And hIndex > 0 Then


For i = 1 to lIndex
BTime = Hour(timeArray(i)) * 60 + Minute(timeArray(i))
if BTime > Start_Time_1 then
highArray(i) = 0
lowArray(i) = 10000



End IF


Next



cLow = 10000
cHigh = 0
For i = 1 to tIndex
if highArray(i) = 0 then cHigh = 0
if lowArray(i) = 10000 then cLow = 10000
if highArray(i) <> 0 then
if highArray(i) > cHigh then cHigh = highArray(i)
highArray(i) = cHigh
End IF
if lowArray(i) <> 10000 Then
If lowArray(i) < cLow then cLow = lowArray(i)
lowArray(i) = cLow
End If


Next





For i = tIndex to 1 Step - 1
if highArray(i) = 0 then cHigh = 0
if lowArray(i) = 10000 then cLow = 10000
if highArray(i) <> 0 then
if highArray(i) > cHigh then cHigh = highArray(i)
highArray(i) = cHigh
End IF
if lowArray(i) <> 10000 Then
If lowArray(i) < cLow then cLow = lowArray(i)
lowArray(i) = cLow
End If


Next


For i =1 to tIndex


if highArray(i)=0 AND I <> 1 then


highArray(i)=highArray(i-1)
END IF


if lowArray(i)= 10000 AND I <> 1 then
lowArray(i)=lowArray(i-1)
END IF


Next




For i = 1 to lIndex


BTime = Hour(timeArray(i)) * 60 + Minute(timeArray(i))
if BTime <= Start_Time_1 OR BTime => End_Time_1 Then
if BTime <= Start_Time_2 OR BTime => End_Time_2 Then
highArray(i) = 0
lowArray(i) = 10000
End If
End IF


Next


End if


bar_count = Clng(bar_count)


if bar_count <=0 then exit function


For shift = bar_count To 1 Step - 1


if highArray(shift) <> 0 then
Channel0(shift) = highArray(shift)
Channel1(shift) = highArray(shift) + 10 * Decimal_Point
else
Channel0(shift) = -987654321
Channel1(shift) = -987654321
end if


if lowArray(shift) <> 10000 then
Channel2(shift) = lowArray(shift)
Channel3(shift) = lowArray(shift) - 10 * Decimal_Point
else
Channel2(shift) = -987654321
Channel3(shift) = -987654321
end if


Next





End Function




Public Sub OnTick(SymbolName)


IF symbol = ChartSymbol(0) Then


Call Calculate_Channels


SetIndicatorData 0,CSTR(indKey0),CDbl(Channel0(Ubound(Channel0)- 1))
SetIndicatorData 0,CSTR(indKey1),CDbl(Channel1(Ubound(Channel1)- 1))
SetIndicatorData 0,CSTR(indKey2),CDbl(Channel2(Ubound(Channel2)- 1))
SetIndicatorData 0,CSTR(indKey3),CDbl(Channel3(Ubound(Channel3)- 1))


End IF
End Sub






Public Sub OnCalculate(symbol ,symPeriod, openVal , highVal , lowVal , closeVal )
IF symbol = ChartSymbol(0) Then
bar_count = Bars(0)
ReDim highArray(bar_count-1)
ReDim lowArray(bar_count-1)
ReDim timeArray(bar_count-1)
ReDim timeMinute(bar_count-1)
ReDim closeArray(bar_count-1)


ReDim Channel0(bar_count-1)
ReDim Channel1(bar_count-1)
ReDim Channel2(bar_count-1)
ReDim Channel3(bar_count-1)


Call Calculate_Channels


SetIndicatorData 0,CSTR(indKey0),CDbl(Channel0(Ubound(Channel0)- 1))
SetIndicatorData 0,CSTR(indKey1),CDbl(Channel1(Ubound(Channel1)- 1))
SetIndicatorData 0,CSTR(indKey2),CDbl(Channel2(Ubound(Channel2)- 1))
SetIndicatorData 0,CSTR(indKey3),CDbl(Channel3(Ubound(Channel3)- 1))


End IF


End Sub


Public Sub OnDeInit()
'''TODO: deinitialization method
ObjectDeleteAll 0
End Sub