//@Name:Bid Change //@Description: Calculates the change in the Bid form the start of the day. //@Returns:Number //@Width:60 //@Update:periodic,15 // Care has been taken in preparing this code but it is provided without guarantee. // You are welcome to modify and extend it. Please add your name as a modifier if you distribute it. // Coded by: Phil Tolhurst, ShareScope Support //Create a Global Cache object into which we can store data for later use var cache = {}; function init() { } function getVal(share) { //Setup Arrays var bars = share.getIBidOfferArray(); var TA = share.getITradeArray(); //Check for data, if not data ends the script. if (!TA || !bars || TA.length==0 || bars.length==0) return; var trigger = 0; var output = 0; var shareIdStr = share.getShareScopeID()+":"+share.getShareNum(); if (bars[bars.length-1].timeNum<28800) return output; //Check if the start value has been cached, if not calculate and cache it. if (!cache[shareIdStr]) { //Check for an uncrossing trade and get the time for (i=0;i=30600); break; if (TA[i].type==TradeType.UT) { trigger = TA[i].timeNum; break; } } //If there is an uncrossing trade select the next bid after this happens as the start value if (trigger>0) { for (j=0;j=trigger) { cache[shareIdStr] = {start:bars[j].bid}; break; } } } //If there is not an uncrossing trade use the last bid before 8am (timeNum value of 28800) unless there is no bid before 8:00am then use the first bid of hte day if (trigger==0) { for (k=0;k=28800) { if (k>0) { cache[shareIdStr] = {start:bars[k-1].bid}; break; } else { cache[shareIdStr] = {start:bars[k].bid}; break; } } } } } output = bars[bars.length-1].bid-cache[shareIdStr].start; return output; }