Excel Rtd for forex

Camo100

New Member
Joined
Mar 6, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
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
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

StephenCrump

MrExcel MVP
Joined
Sep 18, 2013
Messages
4,302
Office Version
  1. 365
Platform
  1. Windows
Welcome to the Forum!

Your two Subs Robot and Lasttrademade make changes to the worksheet, which will trigger the Worksheet_Calculate, which will call Robot etc etc - you're stuck in a loop.

Try:

VBA Code:
Private Sub Worksheet_Calculate()

    Application.EnableEvents = False
    
    'Do everything here that will trigger Worksheet_Calculate, including calling Subs
    
    Application.EnableEvents = True

End Sub
 

Camo100

New Member
Joined
Mar 6, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Welcome to the Forum!

Your two Subs Robot and Lasttrademade make changes to the worksheet, which will trigger the Worksheet_Calculate, which will call Robot etc etc - you're stuck in a loop.

Try:

VBA Code:
Private Sub Worksheet_Calculate()

    Application.EnableEvents = False
   
    'Do everything here that will trigger Worksheet_Calculate, including calling Subs
   
    Application.EnableEvents = True

End Sub
Thanks so much. I have implemented it and will let you know how it goes.
 

Forum statistics

Threads
1,144,155
Messages
5,722,818
Members
422,460
Latest member
VBA_Noob01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top