PDA

View Full Version : Need help with Drawing text


sisidemo
07-02-2007, 03:08 AM
I'm a beginner with ninjaTrader, and I am trying to draw text/verticalLine/... on the prev bar on the chart but I see notning

protected override void OnBarUpdate()
{
if (CurrentBar == 1)
{
//DrawVerticalLine("tag1", 1, Color.Blue);
DrawText("tag1", "AAA", 1, High[1], Color.Black);
}
}

What am I doing wrong?
Thanks

NinjaTrader_Dierk
07-02-2007, 04:13 AM
Your condition CurrentBar == 1 is incorrect, since this paints only on bar #1.

Should read:

if (CurrentBar < 1)
return;
DrawText("tag1", "AAA", 1, High[1], Color.Black);

sisidemo
07-02-2007, 05:12 AM
Your condition CurrentBar == 1 is incorrect, since this paints only on bar #1.

Should read:

if (CurrentBar < 1)
return;
DrawText("tag1", "AAA", 1, High[1], Color.Black);



Thanks,

What is the correct syntax for drawing only on bar no.5?

if (CurrentBar < 5)
return;
DrawVerticalLine("tag1", 5, Color.Blue);

or is there another alternative?

NinjaTrader_Dierk
07-02-2007, 05:17 AM
Do you mean the 5th bar of the left of the chart or the 5 bars back from the current bar (which is the right most bar)?

If the latter, then your code is correct.

sisidemo
07-03-2007, 05:57 AM
Thanks for the help,
Another question if I am in a for loop and I want to get the low value of index bar ago (low), do I need every time in the loop do the check: if (CurrentBar < index) ?
Note: if I don't do the check I get Error to the Log.

[I]What Is the correct syntax for this problem?

Example:
protected override void OnBarUpdate()
{
for (int i = 25; i >= 0; i--)
{
if (CurrentBar < i)
continue;
Print(Low[i]);
}
}

NinjaTrader_Dierk
07-03-2007, 06:00 AM
Your approach is fine. You also could do:
protectedoverridevoid OnBarUpdate()
{
if (CurrentBar < 25)
return;

for (int i = 25; i >= 0; i--)
{
Print(Low[i]);
}
}

jojojo
08-20-2007, 06:29 AM
:confused: Hello
As far as I understand the code :

if (CurrentBar < 1)
return;
DrawText("tag1", "AAA", 1, High[1], Color.Black);

should plot a triple A at the high of the lastbut one bar ,but I can't get no plot. What am I doing wrong?
regs
Jojo

NinjaTrader_Ray
08-20-2007, 07:01 AM
That code works as expected. Please check your log tab for any other errors you may have in your indicator.

The code below for sure works as is.

protected override void OnBarUpdate()
{
if (CurrentBar < 1)
return;
DrawText("tag1", "AAA", 1, High[1], Color.Black);
}

jojojo
08-21-2007, 06:25 AM
Sorry but I did as described , compiles with no errors. Do I miss something like declaring a font or something like this ?
regs

NinjaTrader_Ray
08-21-2007, 07:03 AM
Hi jojojo,

It works as outlined. Attached is an indicator that demonstrates this. You can import it via the Control Center window, File > Utilities > Import NinjaScript.

jojojo
08-22-2007, 03:34 AM
Thanks Ray
But please consider this one .It's quite identical , that's what's driving me mad.

NinjaTrader_Dierk
08-22-2007, 03:47 AM
That's pretty clear. You need to apply different (!) tag names for different drawing objects:
protected override void OnBarUpdate()
{
if (CurrentBar < 1)
return;
DrawText("tag1", "AAA", 1, High[1], Color.Black);

if (CurrentBar < 5)
return;
DrawVerticalLine("tag2", 5, Color.Blue);
}

jojojo
08-22-2007, 08:05 AM
Ok you can call me goofy :)

jojojo
08-29-2007, 03:58 AM
Hello (still goofin around) :)
Another one : How can I plot this (example AAA)at the current price(at the right or left side) , so that the plot is moving up and down with the incoming ticks like a cursor?

regs
Jojo

NinjaTrader_Dierk
08-29-2007, 04:01 AM
How about:
DrawText("tag1", "AAA", 1, Close[0], Color.Black);

jojojo
08-29-2007, 06:50 AM
Thanks
there's some strange behaviour. If I do apply it to a chart , everything freezes and I have to restart.

NinjaTrader_Ray
08-29-2007, 07:06 AM
Do you mean you applied an indicator with the code above to a chart and NT completely locked up? Non responsive? If yes, please post the indicator and the chart instrument and settings you are using.

Thanks.

jojojo
08-29-2007, 07:17 AM
Fdax with 21 Tickchart

NinjaTrader_Ray
08-29-2007, 08:01 AM
Works as expected here.

Can you try this.

Open a 1 minute chart of ES, 15 days back. Then apply this indicator. Does it lock up?

jojojo
08-29-2007, 09:45 AM
hmmm
this works . maybe it depends on ticks?

NinjaTrader_Ray
08-29-2007, 11:20 AM
Try opening a new 150 tick chart, 3 days back. Does it work as expected?

jojojo
08-30-2007, 10:54 AM
sorry for delay .Yes - is working on a 150 tick - chart , but not on a 21 .

NinjaTrader_Ray
08-30-2007, 11:40 AM
I tested on 21 tick chart and it worked as expected. Can you please try the following:

- Open a brand new ES chart
- 21 tick, 3 days back
- Apply indicator

Thanks in advance.

jojojo
08-30-2007, 11:49 AM
works for es 21t

NinjaTrader_Ray
08-30-2007, 11:57 AM
Great.

So what 21 tick chart does it not work for?

jojojo
08-30-2007, 12:01 PM
started with new chart and now works as expected on fdax- sorry for confusion
have no explanation for this :confused:
maybe some internal probs with datafeed and dll's
again thanks for patience