Jaap8242
10-29-2009, 05:44 PM
curious if your able to share the indicator yet
Antonio and lookn4ddeal have made this code available in Tradestation forum. If you are proficient in C+ code you can reprogram this wonderful peace of work .
Jaap
MARKET DELTA PAINT BARS original by Antonio updated by lookn4ddeal
inputs:
iVolLo(1000), {VolumeLow, Original ELcodeName was "Threshold1 thru Threshold3}
iVolMd(2500),
iVolHi(4000),
pBidAsk(true), {"p"=Plot,v8.1 Displays Bid-Ask Difference to Left of the PriceBar as "9999 x 9999" }
pDelta(true), {Displays Total Delta Amount per PriceBar, Under the Low (DeltaTotal=AllAsks-AllBids)}
pAxisTotals(true), {Displays the Column of Delta totals per Horizontal Price, for each Tick Near the Chart rightAxis }
Type(1), { 1 = Use Upticks/Downticks, 2 = Use Bid/Ask }
_COLOR_INPUTS (0),
cAxisLine( DarkGray),
cAxisTotalUP(green),
cAxisTotalDN(rgb(255,100,200)),
cDeltaUP(green),
cDeltaDN(rgb(255,0,128)),
cBidAskGray(DarkGray),
cRed1(RGB(255,200,255)), {Red1=HighestDeltaVolume, Lighter colors more vibrant on Black BackGround}
cRed2(RGB(255,175,255)),
cRed3(RGB(255,150,255)),
cRed4(RGB(255,125,255)),
cGrn1(RGB(200,255,200)),
cGrn2(RGB(175,255,175)),
cGrn3(RGB(150,255,150)),
cGrn4(RGB(125,255,125)), {Green4=LowestDeltaVolume, are defaulted as Darker colors}
DeltaOffset(.35), {Offset Below PriceBar for Delta(sum of all Deltas on current price Bar}
BA_ArraySz(1000), {"BA"=BidAsk, BidAsk Array Size}
AlertsOn(true),
AlertHigh(4500),
AlertLow(-4500);
VARS:
intrabarpersist Red1(cRed1),intrabarpersist Red2(cRed2),intrabarpersist Red3(cRed3),intrabarpersist Red4(cRed4),
intrabarpersist Green1(cGrn1),intrabarpersist Green2(cGrn2),intrabarpersist Green3(cGrn3),intrabarpersist Green4(cGrn4),
intrabarpersist TickSize(MinMove / PriceScale),
intrabarpersist PriceAtIndex(Open),
intrabarpersist BaseIndex(BA_ArraySz/2),
intrabarpersist Price(0),
intrabarpersist MyVol(0),intrabarpersist VolTmp(0),
intrabarpersist LastTick(0),
intrabarpersist vCurrentBar(0),
intrabarpersist Index(0),
intrabarpersist BidAskDelta(0),intrabarpersist xDelta(0),
intrabarpersist TextString(""),intrabarpersist TextString2(""),
intrabarpersist TextStringBid(""),
intrabarpersist vUPTicks(0),intrabarpersist vDNTicks(0),
intrabarpersist LowRange(0),intrabarpersist HighRange(0),
intrabarpersist FirstTime(true),
intrabarpersist LineID(-1),
intrabarpersist DaysAgo(0),
intrabarpersist i(0);
ARRAYS:
intrabarpersist Bid[](0),
intrabarpersist Ask[](0),
intrabarpersist TotalBid[](0),intrabarpersist TotalAsk[](0),
intrabarpersist TextIDs[](-1),intrabarpersist TextID2s[](-1);
Array_SetMaxIndex(Bid,BA_ArraySz);
Array_SetMaxIndex(Ask,BA_ArraySz);
Array_SetMaxIndex(TotalBid,BA_ArraySz);
Array_SetMaxIndex(TotalAsk,BA_ArraySz);
Array_SetMaxIndex(TextIDs,BA_ArraySz);
Array_SetMaxIndex(TextID2s,BA_ArraySz);
if (Type = 1 or Type = 2) and LastBarOnChart and BarType < 2
then begin if FirstTime then begin
LowRange = Low;
HighRange = High;
FirstTime = false;
end;
MyVol = Ticks;
if CurrentBar > vCurrentBar then begin
VolTmp = 0;
vCurrentBar = CurrentBar;
vUPTicks = 0;
vDNTicks = 0;
for i = 0 to BA_ArraySz - 1 begin
Bid<i> = 0;
Ask<i> = 0;
end;
{***** DISPLAY TOTAL BID/ASK BELOW PRICEBAR }
if pAxisTotals then begin
if LineID <> -1 then
TL_Delete(LineID);
if Date = Date[1] then
DaysAgo = 0
else DaysAgo = 1;
i = 0;
Price = LowD(DaysAgo);
while Price <= HighD(DaysAgo)
begin if TextIDs<i> <> -1 then begin
Text_Delete(TextIDs<i>);
Text_Delete(TextID2s<i>);
end;
TextIDs<i> = -1;
TextID2s<i>= -1;
Price = Price + TickSize;
i = i + 1;
end;
if Date <> Date[1] then begin
LowRange = Low;
HighRange = High;
for i = 0 to BA_ArraySz - 1
begin TotalBid<i> = 0;
TotalAsk<i> = 0;
end; end; end; end; //end; end; end; end; end; end; end; end; end; end; end; end; end; end;
Index = BaseIndex + (Close - PriceAtIndex) / TickSize; { Index= (BA_ArraySz/2) + (Close - Open)/TickSize }
if InsideBid < InsideAsk then begin
if Type = 1 then begin
if DownTicks <> vDNTicks then begin // Use Upticks/Downticks
Bid[Index] = Bid[Index] + MyVol - VolTmp;
TotalBid[Index] = TotalBid[Index] + MyVol - VolTmp;
end else
if UpTicks <> vUPTicks then begin
Ask[Index] = Ask[Index] + MyVol - VolTmp;
TotalAsk[Index] = TotalAsk[Index] + MyVol - VolTmp;
end else begin
if Close <= LastTick then begin
Bid[Index] = Bid[Index] + MyVol - VolTmp;
TotalBid[Index] = TotalBid[Index] + MyVol - VolTmp;
end else begin
Ask[Index] = Ask[Index] + MyVol - VolTmp;
TotalAsk[Index] = TotalAsk[Index] + MyVol - VolTmp;
end; end;
end else begin
if Close <= InsideBid then begin // Use Bid/Ask Warning: TradeStation provides snapshot of bid/ask
Bid[Index] = Bid[Index] + MyVol - VolTmp;
TotalBid[Index] = TotalBid[Index] + MyVol - VolTmp;
end else
if Close >= InsideAsk then begin
Ask[Index] = Ask[Index] + MyVol - VolTmp;
TotalAsk[Index] = TotalAsk[Index] + MyVol - VolTmp;
end else begin
if Close <= LastTick then begin // Last tick was between bid/ask
Bid[Index] = Bid[Index] + MyVol - VolTmp;
TotalBid[Index] = TotalBid[Index] + MyVol - VolTmp;
end else begin
Ask[Index] = Ask[Index] + MyVol - VolTmp;
TotalAsk[Index] = TotalAsk[Index] + MyVol - VolTmp;
end; end; end; end; //end; end; end; end; end; end; end; end; end; end; end; end; end; end;
vUPTicks = UpTicks;
vDNTicks = DownTicks;
VolTmp = MyVol;
LastTick = Close;
xDelta = 0;
Price = Low;
while Price <= High
begin Index = BaseIndex + (Price - PriceAtIndex) / TickSize;
{***** DISPLAY BID/ASK AMOUNT(S)AT THE SIDE OF THE PRICEBARS }
if pBidAsk then begin
BidAskDelta = Ask[Index] - Bid[Index];
//TextString = NumToStr(BidAskDelta,0)+" ";
TextString = NumToStr(Bid[Index],0)+" ";
TextStringBid = NumToStr(Ask[Index],0)+" ";
//TextString = NumToStr(Bid[Index],0) + "-" + NumToStr(Ask[Index],0);
Value99 = Text_New(Date,Time,0," ");
Value95 = Text_New(Date,Time,0," ");
Text_SetString(Value99,TextString);
Text_SetString(Value95,TextStringBid);
Text_SetLocation(Value99,Date,Time,Price);
Text_SetLocation(Value95,Date,Time,Price);
Text_SetStyle(Value99,1,2);
Text_SetStyle(Value95,1,2);
if BidAskDelta > iVolHi
then begin Text_SetColor(Value99,cBidAskGray);
Text_SetColor(Value95,Green4);
end else begin if BidAskDelta > iVolMd
then begin Text_SetColor(Value99,cBidAskGray);
Text_SetColor(Value95,Green3);
end else begin if BidAskDelta > iVolLo
then begin Text_SetColor(Value99,cBidAskGray);
Text_SetColor(Value95,Green2);
end else begin if BidAskDelta >= 0
then begin Text_SetColor(Value99,cBidAskGray);
Text_SetColor(Value95,Green1);
end else begin if BidAskDelta < -iVolHi
then begin Text_SetColor(Value95, Red4);
Text_SetColor(Value95,cBidAskGray);
end else begin if BidAskDelta < -iVolMd
then begin Text_SetColor(Value99,Red3);
Text_SetColor(Value95,cBidAskGray);
end else begin if BidAskDelta < -iVolLo
then begin Text_SetColor(Value99,Red2);
Text_SetColor(Value95,cBidAskGray);
end else begin
Text_SetColor(Value99,Red1);
Text_SetColor(Value95,cBidAskGray);
end; end; end; end; end; end; end; end; //end; end; end; end; end; end; end; end; end; end;
xDelta = xDelta + BidAskDelta;
Price = Price + TickSize;
end;
{***** DISPLAY DELTA BID-ASK TOTAL BELOW THE PRICEBARS }
if pDelta then begin
Value99 = Text_New(Date,Time,0, " ");
// Value95 = Text_New(Date,Time,0, " ");
Text_SetString(Value99,NumToStr(xDelta,0));
// Text_SetString(Value95,NumToStr(xDelta,0));
Text_SetLocation(Value99,Date,Time,Low - DeltaOffset);
Text_SetStyle(Value99,1,2);
if xDelta >= 0
then Text_SetColor(Value99,cDeltaUP)
else Text_SetColor(Value99,cDeltaDN);
end; //end; end; end; end; end; end; end; end; end; end; end; end; end; end; end; end; end;
{***** AXIS TOTALS CUMULATIVE DELTA PER PRICE LEVEL DISPLAYED NEAR CHART AXIS LABELS ***********}
if pAxisTotals then begin
if Low < LowRange then LowRange = Low;
if High > HighRange then HighRange = High;
LineID = TL_New(Date, Time+BarInterval, LowRange, Date, Time+BarInterval, HighRange);
TL_SetColor(LineID, cAxisLine);
TL_SetSize(LineID, 2);
Price = LowRange;
i = 0;
while Price <= HighRange
begin Index = BaseIndex + (Price - PriceAtIndex) / TickSize;
TextString = NumToStr(TotalAsk[Index],0) + " ";
if TotalAsk[Index] > 999 and TotalAsk[Index] < 10000 then {most common occurance positioned 1st in ELcode}
TextString2= " " + NumToStr(TotalBid[Index],0) {v9.23 Added 2 Spaces from " " to " "}
else if TotalAsk[Index] > 9999 then {v9.23 Aligns Numbers to Right}
TextString2= " " + NumToStr(TotalBid[Index],0)
else if TotalAsk[Index] < 1000 then
TextString2= " " + NumToStr(TotalBid[Index],0); {v9.23 Added4 Spaces (2 per character)}
Value90 = Text_New(Date, Time+BarInterval, 0, TextString);
Value91 = Text_New(Date, Time+BarInterval, 0, TextString2);
TextIDs<i> = Value90;
Text_SetLocation(Value90, Date, Time+BarInterval, Price);
Text_SetStyle(Value90, 1, 2);
TextID2s<i> = Value91;
Text_SetLocation(Value91, Date, Time+BarInterval, Price);
Text_SetStyle(Value91, 0, 2);
if TotalBid[Index] - TotalAsk[Index] > 0
then begin Text_SetColor(Value91, cAxisTotalDN);
Text_SetColor(Value90, cBidAskGray);
Price = Price + TickSize;
i = i + 1;
end else begin
Text_SetColor(Value90, cAxisTotalUP);
Text_SetColor(Value91, cBidAskGray);
// if TotalBid[Index] - TotalAsk[Index] > 0 // v8.25
// then Text_SetColor(Value90, cAxisTotalDN) // v8.25
// else Text_SetColor(Value90, cAxisTotalUP); // v8.25
Price = Price + TickSize;
i = i + 1;
end; end; end; end; //end; end; end; end; end; end; end; end; end; end; end; end; end; end;
{***** Alert criteria }
If AlertsOn then begin
if xDelta > AlertHigh then {original: if OneAlert( xDelta > AlertHigh ) then }
Alert( "Delta High Volume" )
else
if xDelta < AlertLow then
Alert( "Delta Low Volume" ) ;
end; //end; end; end; end; end; end; end; end; end; end; end; end; end; end; end; end;