Auto Order creation from Explorer result

I want to trigger order creation for Amibroker Explorer results. I want Order to trigger immediately after the result is generated in the explorer. From Amobroker Order will go to another trading software, that software i capable of accepting Amibroker orders.
I have all the necessary information such as ticker, qty, price etc within the explorer AFL.

Please suggest.

Assuming there are 4 results generated by Amibroker explorer.

The function to create order is .. lets assume
PlaceOrder (Exch, ticker, qty, price high of the previous bar,.,., )

how to call Place order 4 times when explorer results are generated..
How to capture ticker name, highest price ..
Remaining things, I think I will be able to manage.

Written a very basic code for Order creation. Your input is required if this code looks OK.

cond=(buyma OR sellma) AND comb;//Explorer works fine with this
Filter=cond;
ORder = IIf(buyma AND comb,1,IIf(sellma AND comb,2,0));
if(BsCond>0) {
brd = CreateStaticObject("pibridge.Bridge");
NTrdSymbol = Name()+"-EQ";
prevO = Ref(O,-1);//previous bar's open
prevC = Ref(C,-1);////previous bar's close
cond=(buyma OR sellma) AND comb;
ooo=ValueWhen(cond,prevO,1);
ccc=ValueWhen(cond,prevC,1);
if (Order==1) {
NPrice=ooo; 
NOrder="BUY";
}
if (Order==2) {
NPrice=ccc; 
NOrder="SELL";
}
brd.PlaceOrder ("NSE", NTrdSymbol,NOrder,NPrice, 100,.....);



Resolved .. code is here : Need help with Static Text variable

I want a static text variable to store Symbols for all the signal generated by Explorer. This is to avoid duplicate OrderCreation by a custom program.

Static variable "CheckOne" starts with value "abc".

Before I trigger my custom OrderCreation program from the explorer results, I want to check if the symbol exists in the contents of the Text variable "CheckOne".
If it does not exist, I trigger OrderCreation and append that symbol to variable "CheckOne".
If it exists in the "CheckOne" variable, then I do not do anything.

I am trying this approach but could not able to achieve.

xx=StaticVarGetText("CheckOne"); //Retrieving contents the variable
if (xx=="") { staticVarSetText("CheckOne","abc"); }//conditional assignment, if CheckOne contents no chars 
CheckTwo = StrFormat(Name());// New symbol name

ye=StrFind(StaticVarGetText("Checkone"),CheckTwo); //checking whether new symbol is in the "CheckOne" variable's content

if(ye==0) {  //if it does not contain so it is not duplicate and OrderCreation can be triggered
  brd.PlaceOrder("NSE", Arg1, arg2,...);
  staticVarSetText("CheckOne",staticvargettext("CheckOne")+CheckTwo); //
  }

Finally with this code I could meet the requirement.
It may not be very efficient way to do this but it works.

Checkone=StaticVarGetText("Check"+StrFormat(Name()));
Checktwo = StrFormat(Name())+"-"+NumToStr(LastValue((Cum(Buy)+Cum(Sell)),1),1.0);

a=Strfind(CheckOne,"-");
aa=StrMid(CheckOne,0,a-1);
b=Strfind(CheckTwo,"-");
bb=StrMid(CheckTwo,0,b-1);


if(aa != bb) {
	brd = CreateStaticObject("pibridge.Bridge"); 
	PlaceOrder(arg1,arg2,....);
	StaticVarSetText("Check"+StrFormat(Name()),CheckTwo );
}
    

1 Like

You can use StrExtract() for way more efficient extraction of substrings between separators than your StrFind/StrMid

And there is no need to start two topics on same subject. Doing so adds a lot of work for forum maintainers. Moving threads around and keeping site tidy because people don't follow forum rules is not really the best way to spend developers time.

Thanks Tomasz.
I tried to use this function..
The syntax is
StrExtract(String,field,separator=",");

Examples given:
StrExtract( "MSFT,AAPL,AMD,INTC", 2 );// will return AMD
StrExtract( "MSFT,AAPL,AMD,INTC", 0 ); // will return MSFT
StrExtract( "MSFT,AAPL,AMD,INTC", 200 );// will return empty string "" `
=> The separator "," is it fixed? can we not change?
I tried to use StrExtract("xxx-yy-zzz",2,"-") with "-" as separator, while compiling it gave Argument type mismatch error.

hello
also you can replace the "-" to "," comma separator
try this on one is not tested buy will work

mystring= "xxx-yy-zzz";
SymbolLatin = StrExtract( StrReplace(mystring,"-",","), 2 ); // extract the second item of the string = zzz
1 Like

Ok.. This will work. Can be used as as workaround. Code length and efficiency may remain similar as earlier.
Thank for suggesting this workaround.

1 Like

@Panos, why do you do over complicate things to such extent?

You just need StrExtract alone but nothing else.
Please read here and following ones

Third parameter of StrExtract is not string but type number representing value of ASCII table.

So proper way is this one

mystring= "xxx-yy-zzz";
SymbolLatin = StrExtract(mystring, 2, '-');

Nothing more and nothing less being required.

2 Likes

@Panos, you don't need StrReplace at all. As per documentation, StrExtact can use ANY character as separator. You specify separator as 3rd argument of function call. Use single quotes to denote single character.

2 Likes

fxshrat - thank you so much. I am very happy with this information.

Hi,
Will you please paste the code here. Actually i am unable to open the page . It shows " Oops! That page doesn’t exist or is private."

Thanks.

Checkone=StaticVarGetText("Check"+StrFormat(Name()));
Checktwo = StrFormat(Name())+"-"+NumToStr(LastValue((Cum(Buy)+Cum(Sell)),1),1.0);

a=Strfind(CheckOne,"-");
aa=StrMid(CheckOne,0,a-1);
b=Strfind(CheckTwo,"-");
bb=StrMid(CheckTwo,0,b-1);


if(aa != bb) {
	brd = CreateStaticObject("pibridge.Bridge"); 
	PlaceOrder(arg1,arg2,....);
	StaticVarSetText("Check"+StrFormat(Name()),CheckTwo );
}```