You have to set flag algo itself for next position and current position.
you can place order, if algo signal and next position is matched
if(AlgoSignal==nextPostion) placeOrder(parm1.. nextPostion)
Based on NIFTY LTP(spot price), you can calculate like below.
sample,
ATM=(Math.round(NIFTYLTP/100))*100;
ATMPlus=ATM+100;
ATMMinus=ATM-100;
TradeSymbolCE="NIFTY20JAN"+ATMPlus+"CE";
for javascript nodejs, u can use below code.
function GetOrderTrdSym(ordid){
kc.getOrders().then(function(response) {
if (response.length === 0) {
console.log("No orders.")
return
}
for (var order of response)…