Using SetForeign

I would like to put these codes in just one Analysis-Window,

the logic would be…
scan IBM, if there is any cross (buy or sell)
then run buy-ibm.exe or sell-ibm.exe

and after scan IBM, also …

scan INTC, if there is any cross (buy or sell)
then run buy-intc.exe or sell-intc.exe

SetForeign("ibm");        

Buy = Cross( Close,   MA( Close, 10) )   ;
Sell = Cross( MA( Close,10),  Close    ) ;

AlertIF( Buy, "EXEC buy-ibm.exe", "SOME_PARAM", 2,1+2 );
AlertIF( Sell,"EXEC sell-ibm.exe", "SOME_PARAM", 2,1+2 );

RestorePriceArrays();



SetForeign("intc");        

Buy = Cross( Close,   MA( Close, 10) )   ;
Sell = Cross( MA( Close,10),  Close    ) ;

AlertIF( Buy, "EXEC buy-intc.exe", "SOME_PARAM", 2,1+2 );
AlertIF( Sell,"EXEC sell-intc.exe", "SOME_PARAM", 2,1+2 );

RestorePriceArrays();

looks like i still failed, so currently i put each code in two analysis-windows, but soon i will be in trouble if i need to scan 20-or 30 stocks.

any help ?

Thank you

@ab-ami it seems to me that you want to achieve something similar to what is described in this KB article titled “How to setup automatic periodic scans & explorations”

There is no need to use the Foreign() function since it is the “scan” procedure that goes over all the symbols that are specified in the “Apply to:” field.

In your case, instead of selecting “*All symbols”, as in the above example, you should create a watchlist including only the tickers what you want to monitor/trade and select such a list in the analysis ‘Define Filter’ dialog and then “Apply to:” set to “*Filter”

1 Like

hi beppe
thank for your response
i know and have use filter everyday
but what i want is to to run different exe.file for each stocks

so
for stock1, if crossed MA, run stk1.exe
for stock2, if crossed MA, run stk2.exe and so on
both are running different executable files

and i think filter only help us to select the stocks we want

right now, i put each stock and each code for each exe.file

in separate new-analysis-windows, they run and give me expected results

but i will have a lot of new-windows-analysis in my screen.

if i can do it with code, i only need one new-analysis-window

Hi @ab-ami, I am not understanding your issue. When you say your posted code fails, how does it fail?

If we understand where it is not meeting your expectations, we might be able to help. And for me, often, doing a good job explaining the problem to someone else causes me to see my mistakes.

2 Likes

This is not a problem since you already named you exe files like the stocks!

In a standard scan/exploration, your code could be similar to:

AlertIF( Buy, "EXEC buy-" + Name() + ".exe", "SOME_PARAM", 2,1+2 );
2 Likes

i cannot tell the new-analysis-window to catch the cross

the result is just empty, it shows nothing.

i will try to elaborate what i mean...with examples

currently i utilize 2 new-analysis-window

the first one has this AFL code, and use filtering to just scan let's say IBM only

Buy = Cross( Close,   MA( Close, 10) )   ;
Sell = Cross( MA( Close,10),  Close    ) ;

AlertIF( Buy, "EXEC action.exe", "PARAM abc", 2,1+2 );
AlertIF( Sell,"EXEC action.exe", "PARAM def", 2,1+2 );

.

the second new-analysis-window contain this code, also using filter to just scan for FB:

Buy = Cross( Close,   MA( Close, 10) )   ;
Sell = Cross( MA( Close,10),  Close    ) ;

AlertIF( Buy, "EXEC action.exe", "PARAM opq", 2,1+2 );
AlertIF( Sell,"EXEC action.exe", "PARAM rst", 2,1+2 );

please notice for above example, i need to run just one executable file (action.exe), but passing different parameter/argument
for different stock and for cross-buy or cross-sell

the above scenario work just fine,
but i now need to run it for 10, 20 or 30 stocks, and i just want to use one new-analysis-window

so i need the codes to put in just one new-analysis-window

and to do that, i try to using SetForeign

hope i make it clear

1 Like

i need to try that code,

i think i made mistake, i need to run just one executable file, but with different parameter/argument

example

if IBM cross above MA
execute action.exe with param abc

if IBM cross below MA
execute action.exe with param def

if FB cross above MA
execute action.exe with param opq

if FB cross below MA
execute action.exe with param rst

Do you have any kind of logic to dynamically decide what parameter to pass to executable? Or do you want to use a list of entirely different parameters, each one specific to a single ticker?

In this last case - if your watchlist is limited to 20/30 stocks (otherwise it will be soon unmanageable) - you could hard code the params using a switch based on the current ticker Name() since the AmiBroker switch conditional statement support also strings as switch expressions (see the switch Statement doc)

The type of switch expression and case constant-expression can be any. The value of each case constant-expression must be unique within the statement body. Otherwise, first-match will be used.

Probably it is not the optimal solution, but you could give it a try to see if it is enough for your own goal.

1 Like

Let us know how it goes....

1 Like

I dumped those methods, and utilize VBscript call to send data to Excel.
using shellexecute to call the VBS file is easier
by combining shellexecute and VBscript,
i could send parameters as well, and get my job done.