Parallel execution in a afl code

I am writing a system on short straddles. Say there are n conditions to short a straddle. when all conditions meet we have to short a straddle i.e. short at the money call and put of that instrument. writing sample code below:

FEtime = 031000;
timeval= TimeNum()>=Stime AND TimeNum()<=FEtime;
ShortStraddle = timeval ; // and it can include other conditions also

when shortStraddle =1, I want to carry out two activities 1. short call and 2 short put, code is as under:`

/// Part A Shorting Call
if ( LastValue(ShortStraddle ) == 1 AND Nz(StaticVarGet("CE",True)) ==0  AND Nz(StaticVarGet("HI",True)) ==0 )
StaticVarSetText("ftceShortOrderID",ftOrderForeignQ(cesymbol,"Sell",Q),True); // Placing the order and storing the orderId
	SendTelegram(" Straddle ce sold "+cesymbol+" at "+cesymbval);

//// Part B shorting put
if (  LastValue(ShortStraddle ) == 1  AND Nz(StaticVarGet("PE",True)) ==0 AND Nz(StaticVarGet("HI",True)) ==0 )
StaticVarSetText("ftpeShortOrderID",ftOrderForeignQ(pesymbol,"Sell",Q),True); // Placing the order and storing the orderId
	SendTelegram(" Straddle pe sold "+pesymbol+" at "+pesymbval);

The code is running in a sequence first part A is executed and then part B is executed and at exchange level there are many times 1 second delay in two orders (b is delayed by 1 second from A)
Is there any way to process both parts A and B parallel at same time rather than in sequence.

Your time is spent in these function calls because in most API calls, the order status is returned from the Broker in turn from the exchange etc.
What you should do is use Basket Orders provided in the APIs, if they are supported.
AB is not causing the delay.
Sequential processing will always do this, unless you have raw API code and can call something like Python subprocess .Popen which supports non-blocking call.
within AB I'm not sure how to execute non-blocking call. Drawback is you are spinning-off multiple processes but mostly acceptable in a relatively small number.

Here one blocking call is made by part A and part B is waiting for it to return a value then part B executes.
If there are two blocking calls happen at same time then result can be expected in similar times. I dont want part B to wait till part A returns a value and unblocks for further sequence of code

some one doing similar thing in python, what i want to do. make all orders without waiting for order number of previous fired orders

you have not given any details about the way the orders are sent.

Anyway, first understand and use basket orders, thats the best way. Finvasia supports it.

Put you code in two panes and they will execute in parallel, just like that. No special code is needed. Amibroker is multithreaded everywhere.

This is very popular strategy 920 Straddle, control is required from same afl for proper execution

Parallel execution BY NATURE is parallel and INDEPENDENT, not sequential, so I guess you don't know what you want.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.