Jump to content

# If Condition with Eval(String) not working

## Recommended Posts

Hi all.

I have a 2^8 conditions to check in order to sharpen result.

TO "simplify it I used this method:

First I created a function that, based on which checkbox is select returns the "IF" string

```Func _GenerateConditions(\$mode)
Local \$condition = "Number(\$array_assets[\$n][14]) = 1"
If \$mode = 1 Then ; long
If GUICtrlRead(\$CB_A_Ichi) = \$GUI_CHECKED Then \$condition &= " AND Number(\$array_assets[\$n][4]) >= Number(\$long_greenred) AND Number(\$array_assets[\$n][5]) > Number(\$long_TKvsKJ)"
If GUICtrlRead(\$CB_A_MACD) = \$GUI_CHECKED Then \$condition &= " AND Number(\$array_assets[\$n][6]) = Number(\$long_MACD) AND Number(\$array_assets[\$n][7]) = Number(\$long_Histo)"
If GUICtrlRead(\$CB_A_RSI) = \$GUI_CHECKED Then \$condition &= " AND Number(\$array_assets[\$n][11]) >= Number(\$RSI)"
If GUICtrlRead(\$CB_A_MA) = \$GUI_CHECKED Then \$condition &= " AND Number(\$array_assets[\$n][8]) = Number(\$MA)"
If GUICtrlRead(\$CB_A_EMA) = \$GUI_CHECKED Then \$condition &= " AND Number(\$array_assets[\$n][9]) = Number(\$EMA)"
If GUICtrlRead(\$CB_A_Mom) = \$GUI_CHECKED Then \$condition &= " AND Number(\$array_assets[\$n][10]) = Number(\$Momentum)"
If GUICtrlRead(\$CB_A_Cross) = \$GUI_CHECKED Then \$condition &= " AND Number(\$array_assets[\$n][13]) = Number(\$Crossover)"
If GUICtrlRead(\$CB_A_BB) = \$GUI_CHECKED Then \$condition &= " AND Number(\$array_assets[\$n][12]) = Number(\$BollingerBands)"
Else ; short
If GUICtrlRead(\$CB_A_Ichi) = \$GUI_CHECKED Then \$condition &= " AND Number(\$array_assets[\$n][4]) <= Number(\$short_greenred) AND Number(\$array_assets[\$n][5]) < Number(\$short_TKvsKJ)"
If GUICtrlRead(\$CB_A_MACD) = \$GUI_CHECKED Then \$condition &= " AND Number(\$array_assets[\$n][6]) = Number(\$short_MACD) AND Number(\$array_assets[\$n][7]) = Number(\$short_Histo)"
If GUICtrlRead(\$CB_A_RSI) = \$GUI_CHECKED Then \$condition &= " AND Number(\$array_assets[\$n][7]) >= Number(\$short_RSI)"
If GUICtrlRead(\$CB_A_MA) = \$GUI_CHECKED Then \$condition &= " AND Number(\$array_assets[\$n][8]) = Number(\$short_MA)"
If GUICtrlRead(\$CB_A_EMA) = \$GUI_CHECKED Then \$condition &= " AND Number(\$array_assets[\$n][9]) = Number(\$short_EMA)"
If GUICtrlRead(\$CB_A_Mom) = \$GUI_CHECKED Then \$condition &= " AND Number(\$array_assets[\$n][10]) = Number(\$short_Mom)"
If GUICtrlRead(\$CB_A_Cross) = \$GUI_CHECKED Then \$condition &= " AND Number(\$array_assets[\$n][13]) = Number(\$short_Crossover)"
If GUICtrlRead(\$CB_A_BB) = \$GUI_CHECKED Then \$condition &= " AND Number(\$array_assets[\$n][12]) = Number(\$short_Bollinger)"
EndIf
Return \$condition
EndFunc```

Then I call it in my loop:

```\$sConditions = _GenerateConditions(\$iTradeWallet)
__CW(\$sConditions)
For \$n = 0 To UBound(\$array_assets) - 1
If Eval(\$sConditions) Then
_send(\$array_assets[\$n][3] & " good to be added!", \$green)
_ArrayAdd(\$aRemoteAssets, \$array_assets[\$n][3])
EndIf
Next```

when I write to console \$conditions it properly shows the condition itself but using EVAL() seems not passing it to IF cycle so I never can enter the IF

Just to clarify: \$array_asset is a 2D array containing:

```; x,0 = id
; x,1 = Exchange
; x,2 = Currency
; x,3 = Asset
; x,4 = GreenRedStreaks
; x,5 = TKRatio
; x,6 = MACDTrend
; x,7 = HistoTren
; x,8 = MA
; x,9 = EMA
; x,10 = Mom
; x,11 = RSI
; x,12 = Bollinger
; x,13 = Crossover
; x,14 = Volume
; x,15 = MarginEnabled
; x,16 = LastUpdate```

Any suggestion to avoid a 2^8 If...then

Marco

##### Share on other sites

I think that Eval is not what you want, from the helpfileReturn the value of the variable defined by a string. You are not passing a variable to Eval, so it fails with 0, and your If check fails

I think what you want is Execute:  https://www.autoitscript.com/autoit3/docs/functions/Execute.htm

Give Execute a read and try, and see if that works.

We ought not to misbehave, but we should look as though we could.

##### Share on other sites

Perfect! Exactly what I needed!!!
Thanks @mistersquirrle!

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account

## Sign in

Already have an account? Sign in here.

Sign In Now
• ### Recently Browsing   0 members

• No registered users viewing this page.
×

• Wiki

• Back

• #### Beta

• Git
• FAQ
×
• Create New...