I was using this with TS without any problem but with Multicharts, it simply would not verify.
Would anyone please help. It has this gradient coloring without using ADE functions and it's easier to use and read.
Many thanks.
Code: Select all
inputs:
Threshold1( 150 ),
Threshold2( 300 ),
Threshold3( 600 ),
DisplayBidAsk( true ),
DisplayDelta( false ),
DisplayTotalBidAsk( false ),
Type( 1 ), // 1 = Use Upticks/Downticks, 2 = Use Bid/Ask
LineColor( DarkGray ),
BidAskArraySz( 1000 );
variables:
intrabarpersist Red1(RGB(255,185,185)),
intrabarpersist Red2(RGB(255,128,128)),
intrabarpersist Red3(RGB(255,0,0)),
intrabarpersist Red4(RGB(128,0,0)),
intrabarpersist Green1(RGB(210,255,210)),
intrabarpersist Green2(RGB(125,255,125)),
intrabarpersist Green3(RGB(0,255,0)),
intrabarpersist Green4(RGB(0,128,0)),
intrabarpersist TickSize( MinMove / PriceScale ),
intrabarpersist PriceAtIndex( Open ),
intrabarpersist BaseIndex( BidAskArraySz/2 ),
intrabarpersist Price( 0 ),
intrabarpersist MyVol( 0 ),
intrabarpersist VolTmp( 0 ),
intrabarpersist LastTick( 0 ),
intrabarpersist MyCurrentBar( 0 ),
intrabarpersist Index( 0 ),
intrabarpersist BidAskDelta( 0 ),
intrabarpersist xDelta( 0 ),
intrabarpersist TextString(""),
intrabarpersist MyUpTicks( 0 ),
intrabarpersist MyDownTicks( 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);
Array_SetMaxIndex( Bid, BidAskArraySz );
Array_SetMaxIndex( Ask, BidAskArraySz );
Array_SetMaxIndex( TotalBid, BidAskArraySz );
Array_SetMaxIndex( TotalAsk, BidAskArraySz );
Array_SetMaxIndex( TextIDs, BidAskArraySz );
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 > MyCurrentBar then
begin
VolTmp = 0;
MyCurrentBar = CurrentBar;
MyUpTicks = 0;
MyDownTicks = 0;
for i = 0 to BidAskArraySz - 1
begin
Bid[i] = 0;
Ask[i] = 0;
end;
if DisplayTotalBidAsk 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
Text_Delete(TextIDs[i]);
TextIDs[i] = -1;
Price = Price + TickSize;
i = i + 1;
end;
if Date <> Date[1] then
begin
LowRange = Low;
HighRange = High;
for i = 0 to BidAskArraySz - 1
begin
TotalBid[i] = 0;
TotalAsk[i] = 0;
end;
end;
end;
end;
Index = BaseIndex + (Close - PriceAtIndex) / TickSize;
if InsideBid < InsideAsk then
begin
if Type = 1 then
begin
// Use Upticks/Downticks
if DownTicks <> MyDownTicks then
begin
Bid[Index] = Bid[Index] + MyVol - VolTmp;
TotalBid[Index] = TotalBid[Index] + MyVol - VolTmp;
end
else if UpTicks <> MyUpTicks 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
// Use Bid/Ask
// Warning: TS provides snapshot of bid/ask
if Close <= InsideBid then
begin
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
// Last tick was between bid/ask
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;
end;
MyUpTicks = UpTicks;
MyDownTicks = DownTicks;
VolTmp = MyVol;
LastTick = Close;
xDelta = 0;
Price = Low;
while Price <= High
begin
Index = BaseIndex + (Price - PriceAtIndex) / TickSize;
if DisplayBidAsk then
begin
TextString = NumToStr(Bid[Index],0) + " x " + NumToStr(Ask[Index],0);
Value99 = Text_New(Date, Time, 0, " ");
Text_SetString(Value99, TextString);
Text_SetLocation(Value99, Date, Time, Price);
Text_SetStyle(Value99, 1, 2);
end;
BidAskDelta = Ask[Index] - Bid[Index];
if DisplayBidAsk then
begin
if BidAskDelta > Threshold3 then
Text_SetColor(Value99, Green4)
else if BidAskDelta > Threshold2 then
Text_SetColor(Value99, Green3)
else if BidAskDelta > Threshold1 then
Text_SetColor(Value99, Green2)
else if BidAskDelta >= 0 then
Text_SetColor(Value99, Green1)
else if BidAskDelta < -Threshold3 then
Text_SetColor(Value99, Red4)
else if BidAskDelta < -Threshold2 then
Text_SetColor(Value99, Red3)
else if BidAskDelta < -Threshold1 then
Text_SetColor(Value99, Red2)
else
Text_SetColor(Value99, Red1);
end;
xDelta = xDelta + BidAskDelta;
Price = Price + TickSize;
end;
if DisplayDelta = true then
begin
Value99 = Text_New(Date, Time, 0, " ");
Text_SetString(Value99, NumToStr(xDelta, 0 ));
Text_SetLocation(Value99, Date, Time, Low - TickSize);
Text_SetStyle(Value99, 1, 2);
if xDelta >= 0 then
Text_SetColor(Value99, Green)
else
Text_SetColor(Value99, Red);
end;
if DisplayTotalBidAsk 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, LineColor);
TL_SetSize(LineID, 2);
Price = LowRange;
i = 0;
while Price <= HighRange
begin
Index = BaseIndex + (Price - PriceAtIndex) / TickSize;
TextString = " " + NumToStr(TotalBid[Index],0) + " x " + NumToStr(TotalAsk[Index],0) + " " + NumToStr(TotalBid[Index]+TotalAsk[Index],0);
Value98 = Text_New(Date, Time+BarInterval, 0, TextString);
TextIDs[i] = Value98;
Text_SetLocation(Value98, Date, Time+BarInterval, Price);
Text_SetStyle(Value98, 0, 2);
if TotalBid[Index] - TotalAsk[Index] > 0 then
Text_SetColor(Value98, Red)
else
Text_SetColor(Value98, Green);
Price = Price + TickSize;
i = i + 1;
end;
end;
end;