PDA

View Full Version : Creating an indicator like Market Delta


antonio
09-04-2008, 04:42 PM
I just started getting familiar with NinjaScript in order to create a footprint chart similar to Market Delta and I have a few questions. Attached is a draft footprint chart that I put together for reference. The number at the bottom of the bid/ask info is the Delta. I am using the DrawText() function to print the bid/ask info. So here are my questions:
How do I get the footprint color shading to be of equal length (uniform) for the bid/ask at each price?
How do I align the x's on each line?
How do I create a text panel displaying Delta statistics (e.g., Bid, Ask, Delta, Delta Chg, Cum Delta, Volume, etc)?I'm just looking for someone to point me in the right direction, by either telling me the function I should be using or a link to relevant examples. Thanks.

2993

NinjaTrader_Josh
09-04-2008, 05:01 PM
1. I am not sure what you mean by equal length? You want them to line up equally vertically down the various columns?
2. Sorry it is beyond the level we can offer support for. It is not simple. There is no built in function to do it. You may need to use custom Plot() to achieve the display you want.
3. You just need to use DrawText and find the relevant locations on the screen to print to with the information you want.

antonio
09-04-2008, 05:23 PM
Josh, thanks for the quick reply. Below are my follow-up questions/comments.

Yes, I would like the color boxes to line up vertically with the left/right edges of the box being aligned with the left/right edges of all the other boxes above/below it to give it a neat look.
I will take a look at the Plot() function.
If I use DrawText() to print the statistics, wouldn't the text move off the screen as new price data arrives? I'm assuming that you're suggesting printing the text in the price panel. I would like to view the statistics at all times.

NinjaTrader_Josh
09-05-2008, 08:03 AM
1. You could use DrawRectangle() of the same parameters for the boxes yes?
3. Try DrawTextFixed(). It will be in the price panel, but it will not move.

antonio
01-20-2009, 12:29 PM
I'm trying to align the bid/ask data within a cell in the chart. Currently, the data is spanning across cells. I think I need to change the price axis so that the price is "between the grid lines" as opposed to "at the grid lines." How do I do this? Attached is a chart illustrating what I'm trying to do. Hope this makes sense. Thanks.

NinjaTrader_Bertrand
01-20-2009, 12:36 PM
Hi antonio, you would need to overwrite the Plot method, which is unfortunately not supported.

antonio
01-20-2009, 12:57 PM
Bertrand, thanks for your reply.

dda2008
01-20-2009, 11:53 PM
Hi Antonio, Can you share your code here?
Thanks.

darthtrader
01-21-2009, 07:27 PM
I would also like to check out the code if you don't mind. I might be able to get it working with plot().

cwineria
01-24-2009, 01:22 AM
I would also like to check out the code if you don't mind. I might be able to get it working with plot().

Hi Antonio,

I would also like to see the code for the indicator, looks great:)

antonio
02-03-2009, 11:03 AM
I currently run my "MarketDelta" indicator twice, once to get the bid/ask on the price chart and again to get the bid/ask stats in an indicator panel (see attached figure). Is there a way to run the indicator once and have data displayed in panels 1 & 2. I tried changing "DrawOnPricePanel" and "Panel" parameters in the code in real-time, but data is only displayed in the price panel. Is there something else I need to do? Thanks.

4499

NinjaTrader_Bertrand
02-03-2009, 11:16 AM
Hi antonio, unfortunately this is not supported. Stay with the solution you have right now and you should be good.

PrTester
02-03-2009, 01:39 PM
I currently run my "MarketDelta" indicator twice, once to get the bid/ask on the price chart and again to get the bid/ask stats in an indicator panel (see attached figure). Is there a way to run the indicator once and have data displayed in panels 1 & 2. I tried changing "DrawOnPricePanel" and "Panel" parameters in the code in real-time, but data is only displayed in the price panel. Is there something else I need to do? Thanks.

4499

Maybe this help http://www.ninjatrader-support2.com/vb/showthread.php?t=13032&highlight=draw

antonio
02-04-2009, 01:06 PM
PrTester, thanks for the link. I tried the suggestion in that thread, but it didn't work for me. Did you have any success printing to both panels from one indicator?

PrTester
02-04-2009, 01:14 PM
PrTester, thanks for the link. I tried the suggestion in that thread, but it didn't work for me. Did you have any success printing to both panels from one indicator?


Yes, there's a file in the thread. works for me.

Regards

timmyb
02-25-2009, 06:47 PM
I currently run my "MarketDelta" indicator twice, once to get the bid/ask on the price chart and again to get the bid/ask stats in an indicator panel (see attached figure). Is there a way to run the indicator once and have data displayed in panels 1 & 2. I tried changing "DrawOnPricePanel" and "Panel" parameters in the code in real-time, but data is only displayed in the price panel. Is there something else I need to do? Thanks.

4499

would you share the indicator??

timmyb
03-03-2009, 11:46 PM
Bump ,, are you willing to share this indicator??

subterfuge
03-04-2009, 02:36 PM
any update mate? Im interested in learning about market delta and this would be a good way to start. Cheers

antonio
03-04-2009, 04:39 PM
Not at this time, sorry.

timmyb
03-04-2009, 05:57 PM
you want to share what you have so far???

timmyb
05-02-2009, 12:10 PM
curious if your able to share the indicator yet

iwannatoscript
05-03-2009, 09:39 PM
I currently run my "MarketDelta" indicator twice, once to get the bid/ask on the price chart and again to get the bid/ask stats in an indicator panel (see attached figure). Is there a way to run the indicator once and have data displayed in panels 1 & 2. I tried changing "DrawOnPricePanel" and "Panel" parameters in the code in real-time, but data is only displayed in the price panel. Is there something else I need to do? Thanks.

4499


Antonio could you explain to us what is the difference of your indicator and market delta please?

What is the advantage that your indicator could give us?

Could you post links or something else to understand it please?

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;

floyd084
02-18-2010, 11:19 AM
has anyone been able to convert this code for NT7?

NinjaTrader_Bertrand
02-18-2010, 12:10 PM
Depending on how strongly you want it converted, you could also check out a NinjaScript consultant to assist you -

http://www.ninjatrader.com/webnew/partners_onlinetrading_NinjaScript.htm

For a similar technique you can check into a NinjaTrader add on FinAlg offers - http://www.fin-alg.com/product.html