I'm having a problem with a script that is intended to select one of multiple instruments. I have a loop as below, that is intended to ensure only executing a trade when the spread is beneath a threshold. I understood that getcurrentbid and getcurrentask are overloaded such that if I put in i as a parameter it would get the bid and ask of the instrument that corresponds with the bar series i.
When I run the loop below and examine the output, I find that irrespective of whether it's bar 1 or 2 (two futures of same instrument, different maturity), it will display the spread of the near future.
Could you please assist ?
for (i=1; i<Instruments.Length; i++)
{
Bid = GetCurrentBid(i);Ask = GetCurrentAsk(i);
if(Bid > 0 && Ask > 0 &&
GetCurrentBidVolume(i) > 0 &&
GetCurrentAskVolume(i) > 0)
if(Ask/Bid < ( 1.0+maxSpreadTrade)) okToTradeInst[i]=true;
else okToTradeInst[i]=false;
else okToTradeInst[i]=false;
Print(now+" bar "+i+" ask="+Ask+" bid="+Bid+" ok is "+okToTradeInst[i]);
}

Comment