PDA

View Full Version : Having problem in the vtl ea



ankitkalindi
10-08-2013, 10:20 AM
hi i have this ea but having problem while running and showing exception in main. thanks



Dim PipsLong
Dim PipsShort
Dim Lots
Dim StopLoss
Dim TrailingStop
Dim TakeProfit
Dim Slipage
Dim Profit
Dim PipLoc
Dim Sl
Dim OpenPrice
Public Sub main()
MsgBox"It is main"
Dim i,cnt,ticketShort,ticketLong
Dim targetLong,targetShort,sl,tp,Bid,Point,Ask
cnt =PositionTotal()
ticketShort = 0
ticketLong = 0
targetLong = 0
targetShort = 0
SymbolInfoInteger Cstr(ChartSymbol(0)),SYMBOL_PIP_LOCATION,PipLoc
Point=( 1/(10^Cint(-PipLoc)))
SymbolInfoDouble Cstr(ChartSymbol(0)),SYMBOL_ASK,Ask
SymbolInfoDouble Cstr(CharSymbol(0)),SYMBOL_BID,Bid
If (PipsLong <> 0) Then
targetLong=Bid+PipsLong*Point
If (PipsShort<> 0) Then
targetShort=Ask-PipsShort*Point
End If
End If
PositionGetDouble POSITION_PROFIT,Profit
For i=1 To cnt

IF (PositionSelect(PositionGetTicket(Cint(i)))) Then
IF PositionGetSymbol(Cint(i)) = ChartSymbol(0) Then
If(OrderType()=TRADE_ACTION_BUY) Then
If (TrailingStop <> 0 And Profit > 0 ) Then
sl = Ask-TrailingStop*Point
PositionGetDouble POSITION_SL,SL
PositionGetDouble POSITION_TP,TP

If (SL< sl) Then
UpdateSLTPOrder CSTR(ManageOrders.Orders(i)), Cdbl(OrderLots(ManageOrders.Orders(i))),Cdbl(SL) , Cdbl(TP)
End If
ticketLong = -1
End If
End IF
if (OrderType()=TRADE_ACTION_SELL) Then
If (TrailingStop <> 0 And Cdbl(Profit) > 0 ) Then
sl = Bid+TrailingStop*Point
PositionGetDouble POSITION_SL,SL
PositionGetDouble POSITION_TP,TP
if (SL > sl) Then
UpdateSLTPOrder CSTR(ManageOrders.Orders(i)), Cdbl(OrderLots(ManageOrders.Orders(i))),Cdbl(SL) , Cdbl(TP)
End if
ticketShort = -1
if (OrderType() =TRADE_ACTION_SELL_STOP) Then
ticketShort = PositionGetTicket(i)
End If
if (OrderType() =TRADE_ACTION_BUY_STOP) Then
ticketLong = PositionGetTicket(i)
End If
End If
End If

End If
End If
Next

tp = 0
If (PipsShort <> 0) Then
if (ticketShort = 0) Then
sl = targetShort+StopLoss*Point

if (TakeProfit <> 0) Then
tp = targetShort-TakeProfit*Point
End If
ticketShort = NewMarketOrder (TRADE_ACTION_SELL_STOP,ChartSymbol(0),Cdbl(Lots))
if (ticketShort < 0) Then
MsgBox"Order Failed with "
End If
End if

ElseIf ticketShort <> -1 Then

PositionGetDouble POSITION_PRICE_OPEN,OpenPrice
if (targetShort > OpenPrice) Then
sl = targetShort+StopLoss*Point
End If
if (TakeProfit <> 0) Then
tp = targetShort-TakeProfit*Point
ticketShort = UpdateSLTPOrder(ticketShort, Cdbl(targetShort),Cdbl(sl) ,Cdbl(tp) )
End If

End If



if (PipsLong <> 0) Then
if (ticketLong = 0) Then
sl = targetLong-StopLoss*Point
if (TakeProfit <> 0) Then
tp = targetLong+TakeProfit*Point
ticketLong = NewMarketOrder(TRADE_ACTION_BUY_STOP,ChartSymbol(0 ),Cdbl(Lots))
End If
if (ticketLong < 0) Then
MsgBox "error"
End If
End If

if (ticketLong <> -1) Then
PositionGetDouble POSITION_PRICE_OPEN,OpenPrice
if (targetLong <OpenPrice) Then
sl = targetLong-StopLoss*Point
End If
if (TakeProfit <> 0) Then
tp = targetLong+TakeProfit*Point
ticketLong =UpdateSLTPOrder(ticketLong, Cdbl(targetLong),Cdbl(sl) , Cdbl(tp) )
End If
if (ticketLong < 0) Then
MsgBox "Error"
End If
End If
End if

End Sub


Public Sub OnInit()
PipsLong=300
PipsShort=300
Lots=0.01
StopLoss=300
TrailingStop=100
TakeProfit=100
Slipage=30
End Sub

b_morar
10-08-2013, 11:50 AM
Dear sir

You have many bugs,

1- Wrong function name (Line24) ,"CharSymbol".

2-Type miss-match when calling "UpdateSLTPOrder".

ankitkalindi
10-09-2013, 05:06 AM
sir can you remove that bug i am not able to solve that bug update .i solved that chartsymbol bug but not able to solve that update bug.Thanks in advance

ankitkalindi
10-09-2013, 07:20 AM
hello sir can you tell me how to solve the updatesltporder i have try to much but not able to solve it

b_morar
10-09-2013, 07:53 AM
This code is quoted from your script, I have made some modifications to update SLTP orders in the right way.

1-It is loop over all positions
2- if chart symbol equal position symbol.
3-if and only if the position type equal buy.
4- its request the collection of the orders that mapped with the position using "RequestManageOrders (http://www.hybrid-solutions.com/support/index.php?/Knowledgebase/Article/View/3651)" method.
5- when the collection received by "OnManageOrdersReceived (http://www.hybrid-solutions.com/support/index.php?/Knowledgebase/Article/View/2565)" event its loop over all orders and update it.
Note : Why the position may have many manage orders? because VertexFx support the partial manage.



dim SL
dim TP
dim cnt

Public Sub main()
cnt=PositionTotal()
for i=1 To cnt
IF (PositionSelect(PositionGetTicket(Cint(i)))) Then
IF PositionGetSymbol(Cint(i)) = ChartSymbol(0) Then
If (GetPositionType()=TRADE_ACTION_BUY) Then
RequestManageOrders (PositionGetTicket(Cint(i)))
end if
end if
end if
next

End Sub


Public Sub OnManageOrdersReceived(manageOrders)

Sl=1
TP=100

For i = 1 To manageOrders.Count()

UpdateSLTPOrder Clng(manageOrders.Orders(i)), Cdbl(OrderLots(Clng(manageOrders.Orders(i)))),Cdbl (Sl) , Cdbl(TP)

Next


End Sub

b_morar
10-09-2013, 08:08 AM
Dear sir,
Please check the following notes carefully.

1- VTL its not case sensitive.
2- All Tickets IDs and Orders IDs is returns by events UN-like other trading languages.
ex:



Public Sub main()
MsgBox NewMarketOrder(TRADE_ACTION_BUY,"EUR/USD",1) ' Returns True if buy operation was successful.
End Sub


''' <summary>
''' Raise when the server returns position result
''' </summary>

Public Sub OnPositionTrade (ActionType ,ticketID)
If ActionType= TRADE_POSITION_NEW then
MsgBox ticketID ' The Ticket ID
end if

End Sub

If you need any further assistance, please don't hesitate to contact us.

ankitkalindi
10-09-2013, 08:17 AM
thanks sir

ankitkalindi
10-09-2013, 11:27 AM
sir can you help me i have getting error object variable or with block variable not set .Type mismatch RequestManageorders.

b_morar
10-09-2013, 12:18 PM
Dear sir
Can you please attach your code and I will check it immediately ?

ankitkalindi
10-10-2013, 06:24 AM
PositionGetDouble POSITION_PRICE_OPEN,OpenPrice
if (targetShort > OpenPrice) Then
sl = targetShort+StopLoss*Point
End If
if (TakeProfit <> 0) Then
tp = targetShort-TakeProfit*Point
MsgBox "takeprofit!=0"
RequestManageOrders (PositionGetTicket (Cint(ticketShort)))
End If


sir i used this code but it still giving exception while running i have written this type of code four times as my ea has too many modify statement .dont understand the exception

Hassan-HS
10-10-2013, 07:23 AM
Dear sir,

The exception occurs here

RequestManageOrders (PositionGetTicket (Cint(ticketShort)))

Because you are send an empty value to PositionGetTicket method.


Your code after some modifications :D :


Public Sub main()
Dim TargetShort
Dim SL
Dim TP
Dim StopLoss
Dim TakeProfit
Dim OpenPrice
Dim Point

TakeProfit=1
StopLoss=100
TargetShort = 100
Point = 0.001

for i = 1 to PositionTotal()
PositionSelect PositionGetTicket(Cint(i))
PositionGetDouble POSITION_PRICE_OPEN,OpenPrice
If (TargetShort > OpenPrice) Then
SL = TargetShort+StopLoss*Point
End If

if (TakeProfit <> 0) Then
TP = TakeProfit-TakeProfit*Point
RequestManageOrders (PositionGetTicket(Cint(i)))
End If

Next
End Sub


public sub OnManageOrdersReceived(manageOrders)
For Counter = 1 To manageOrders.Count()
MsgBox manageOrders.Orders(Counter)
Next
End Sub

ankitkalindi
10-10-2013, 07:47 AM
sir it i have to pass some value like ticket short as a parameter and their no for loop than what can i write ?

Hassan-HS
10-10-2013, 07:56 AM
Dear sir,

Check this code.




Public Sub main()
Dim TargetShort
Dim SL
Dim TP
Dim StopLoss
Dim TakeProfit
Dim OpenPrice
Dim Point
Dim ticketShort

TakeProfit=1
StopLoss=100
TargetShort = 100
Point = 0.001
ticketShort=1

PositionSelect PositionGetTicket(Cint(ticketShort))
PositionGetDouble POSITION_PRICE_OPEN,OpenPrice
If (TargetShort > OpenPrice) Then
SL = TargetShort+StopLoss*Point
End If

if (TakeProfit <> 0) Then
TP = TakeProfit-TakeProfit*Point
RequestManageOrders (PositionGetTicket(Cint(ticketShort)))
End If

End Sub


public sub OnManageOrdersReceived(manageOrders)
For Counter = 1 To manageOrders.Count()
MsgBox manageOrders.Orders(Counter)
Next
End Sub

Hassan-HS
01-09-2014, 09:41 AM
Dear Sir,

Please update us if every thing is clear now or not, and let me know if you need any further assistance.