Hi all.
I was hoping someone can assist me. I have built a trading robot via excel Rtd based on my strategy. The robot has two triggers to to run being
1) All conditions met. Cell B2 equals 15. This is the sum total of all formulas that check conditions &
2) Cell B70 = "OK".
The code runs fine for a few trades then goes into a huge loop and runs trade after trade after trade without stopping.
The code I use to to trigger a trade is
Private Sub Worksheet_Calculate()
Dim calc As Long
Dim check As String
calc = Range("B2").Value
check = Range("B70").Value
On Error Resume Next
If calc = 15 And check = "OK" Then
Call ROBOT
Exit Sub
End If
End Sub
____________________
Public Sub ROBOT()
' Get the values from the named cells on the worksheet
strAccount = Range("AccountNumber").Value
strSymbol = Range("TradeSymbol").Value
strCommand = Range("TradeDirection").Value
vVolume = Range("TradeVolume").Value
StrStop = Range("StopLoss").Value
StrTp = Range("TakeProfit").Value
' Check that the values are valid
If Not IsNumeric(strAccount) Then
' MsgBox "Account number must be numeric!"
Exit Sub
End If
If strSymbol = "" Then
' MsgBox "Symbol to trade cannot be blank!"
Exit Sub
End If
If vVolume < 1 Then
'MsgBox "Volume is not valid (should be a trade size such as 10000, not a number of lots such as 0.10)"
End If
' Build the parameters which are sent for the trading command: symbol and volume
strParameters = "s=" & strSymbol & "|v=" & vVolume & "|sl=" & StrStop & "|tp=" & StrTp
' Timeout in seconds
lTimeoutSeconds = 5
' Create the FXBlueLabs.ExcelCommand object and send the command
Set cmd = CreateObject("FXBlueLabs.ExcelCommand")
strResult = cmd.SendCommand(strAccount, strCommand, strParameters, lTimeoutSeconds)
' STOP TRADES THIS CHANGES THE VALUE OF B7O FROM OK TO NO OK
Range("B73").Select
Selection.Copy
Range("B73").Select
Application.CutCopyMode = False
Selection.Copy
Range("B70").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("B75").Select
' Check the result
If InStr(strResult, "ERR:") = 1 Then
'MsgBox strResult
End If
Call Lasttrademade
End Sub
Public Sub Lasttrademade()
'
' Lasttrade Macro
'
'This copys the activity of the last trade taken
Range("$B$41").Select
Selection.Copy
Range("$B$29").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.SmallScroll Down:=-6
Range("$B$20").Select
Application.CutCopyMode = False
Selection.Copy
Range("$B$30").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub
I was wondering if anyone can assist and let me know what I am doing wrong here,
Many thanks
I was hoping someone can assist me. I have built a trading robot via excel Rtd based on my strategy. The robot has two triggers to to run being
1) All conditions met. Cell B2 equals 15. This is the sum total of all formulas that check conditions &
2) Cell B70 = "OK".
The code runs fine for a few trades then goes into a huge loop and runs trade after trade after trade without stopping.
The code I use to to trigger a trade is
Private Sub Worksheet_Calculate()
Dim calc As Long
Dim check As String
calc = Range("B2").Value
check = Range("B70").Value
On Error Resume Next
If calc = 15 And check = "OK" Then
Call ROBOT
Exit Sub
End If
End Sub
____________________
Public Sub ROBOT()
' Get the values from the named cells on the worksheet
strAccount = Range("AccountNumber").Value
strSymbol = Range("TradeSymbol").Value
strCommand = Range("TradeDirection").Value
vVolume = Range("TradeVolume").Value
StrStop = Range("StopLoss").Value
StrTp = Range("TakeProfit").Value
' Check that the values are valid
If Not IsNumeric(strAccount) Then
' MsgBox "Account number must be numeric!"
Exit Sub
End If
If strSymbol = "" Then
' MsgBox "Symbol to trade cannot be blank!"
Exit Sub
End If
If vVolume < 1 Then
'MsgBox "Volume is not valid (should be a trade size such as 10000, not a number of lots such as 0.10)"
End If
' Build the parameters which are sent for the trading command: symbol and volume
strParameters = "s=" & strSymbol & "|v=" & vVolume & "|sl=" & StrStop & "|tp=" & StrTp
' Timeout in seconds
lTimeoutSeconds = 5
' Create the FXBlueLabs.ExcelCommand object and send the command
Set cmd = CreateObject("FXBlueLabs.ExcelCommand")
strResult = cmd.SendCommand(strAccount, strCommand, strParameters, lTimeoutSeconds)
' STOP TRADES THIS CHANGES THE VALUE OF B7O FROM OK TO NO OK
Range("B73").Select
Selection.Copy
Range("B73").Select
Application.CutCopyMode = False
Selection.Copy
Range("B70").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("B75").Select
' Check the result
If InStr(strResult, "ERR:") = 1 Then
'MsgBox strResult
End If
Call Lasttrademade
End Sub
Public Sub Lasttrademade()
'
' Lasttrade Macro
'
'This copys the activity of the last trade taken
Range("$B$41").Select
Selection.Copy
Range("$B$29").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.SmallScroll Down:=-6
Range("$B$20").Select
Application.CutCopyMode = False
Selection.Copy
Range("$B$30").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub
I was wondering if anyone can assist and let me know what I am doing wrong here,
Many thanks