onTick - Why o why ??

Spin

Well-known member
Joined
May 22, 2019
Posts
455
Likes
178
So i added this code to an already working study:

Java:
 public void onTick(Tick tick)
    {
          debug ("Tick incoming !!");
//      calculateValues(ctx);
    }

I know my broker delivers TickData (because I can see MW's standard VolumeProfile Study updating when I add it to a chart; it also uses 'onTick')

Why o why don't I get any output to the Study log ? :unsure:

Just to make sure: I use onTick without @override (otherwise my IDE complains "method does not override or implement a method from a supertype")

Do I need to declare something else for onTick to work ?
Is there any other coding voodoo involved ? Ritual sacrifices perhaps ? :LOL:
 

igor.s

Well-known member
Joined
May 22, 2019
Posts
258
Likes
138
have you tried a different bar type? any non-linear, say Renko?
 

Spin

Well-known member
Joined
May 22, 2019
Posts
455
Likes
178
Hello Igor, and thanks for your answer. No I haven't tried non-linear yet, but will give it a go when markets are open tomorrow.

Seems rather weird that linear is unable to work with onTick.
In the meantime I stumbled upon this in MW's TradeManager code:
Java:
@Override
  public void onBarUpdate(OrderContext ctx)
  {
    //System.out.println("onBarUpdate(): " + com.motivewave.common.Util.formatDateMMMDDHHSS(ServiceInstance.getCurrentTime()));
    if (getEntryState() != Enums.EntryState.OPEN) return;
    // Check to see if we have hit the break even state, if so adjust the trail orders.
    Instrument instr = ctx.getInstrument();
    int breakEvenPips = getSettings().getInteger(BREAK_EVEN_PIPS);
    if (isLong()) {
      if (instr.round(instr.getSellPrice() - ctx.getAvgEntryPrice()) >= instr.round(breakEvenPips * instr.getPointSize())) {
        doBreakEven(ctx);
      }
    }
    else {
      if (instr.round(ctx.getAvgEntryPrice() - instr.getBuyPrice()) >= instr.round(breakEvenPips * instr.getPointSize())) {
        doBreakEven(ctx);
      }
    }
  }

Could we use the same to make a simple 'current price to daily ATR'-study that prints that distance on a chart somewhere ? :unsure:
 

Spin

Well-known member
Joined
May 22, 2019
Posts
455
Likes
178
Tried with both Renko & Range. No difference :confused:
 

michaelphines

Member
Joined
Apr 21, 2020
Posts
7
Likes
2
It's tough without more of your code, but the fact that your IDE complains that "method does not override or implement a method from a supertype" implies that the class you're extending from does not implement onTick. Since it's the Study class that implements onTick—and thus the Study class you need to override onTick in—the first thing I would check is that you're defining your onTick method in the actual Study class and not a subclass or some other utility class that your study implements.
 

Spin

Well-known member
Joined
May 22, 2019
Posts
455
Likes
178
Thank you @michaelphines for your answer. I checked and I do override the Study class.

But it gets more interesting (or worse ?):

For testing purposes, I added all this code to figure out what 'gets caught' when:
Java:
@Override
  public void onLoad(Defaults defaults)
  {
      setMinBars(1000);
      debug("onLoad !");
  }

  @Override
  public void onTick(DataContext ctx, Tick tick)
  {
      debug("Tick !");
  }

  public void onDataSeriesMoved(DataContext ctx)
  {
      debug("DataSeriesMoved !");
//      notifyRedraw();
//      notifyValuesUpdated();
  }

  public void onDataSeriesUpdated(DataContext ctx)
  {

      debug("DataSeriesUpdated !");
//      notifyRedraw();
//      notifyValuesUpdated();
  }

I then loaded and reloaded, switched timeframes, changed bartypes, and scrolled back (to load more historical data), all like a madman :devilish:.

The only thing that ever makes it to my Study Log is the 'onLoad'-debug statement.

I have absolutely no clue why the others aren't caught by the platform.
I checked in the code of the 275 'standard' MW studies, but I spot no differences with my code.

Something else is preventing the onTick (and the others) from firing :unsure:

Another issue I am facing (may or may not be related to this one) is that one of my studies only draws its figures when I change the parameters. The full sequence goes like this:
  • I drop the study on my chart. I can see it is added because the 'onLoad' statement is printed, and the label (with the settings) appears in the top left corner of my Price Plot
  • No markers are drawn
  • I then click the label to open the parameter window.
  • I change a value (any value: a boolean, a MA method, a period value, ...)
  • Upon pressing 'Update' or 'Apply' my markers are plotted
Very annoying, since adding this Study to a template effectively renders it unusable: the Study's label is no longer visible when you add that template to a chart (only the template name is shown) and -since that particular Study plots no markers- it is impossible to click on a marker to get the parameter window.

I am starting to suspect we will need a MW-coder to look into this, because we, mortals, do not possess enough info to figure out what exactly is going on here. So I will add @MotiveWave_Jason and @MotiveWave_Joe.

Thanks all in advance for shedding light into the Darkness :)
 
Last edited:

Evolver

New member
Joined
May 2, 2020
Posts
3
Likes
0
I am also looking for the proper method that registers a tick in a Study. I am doing a tick-by-tick calculation and cannot seem to find the appropriate place where to hook in to the Study class.

Any help would be appreciated!
 

Spin

Well-known member
Joined
May 22, 2019
Posts
455
Likes
178
I did contact the MW-staff last Friday, and @MotiveWave_Joe answered me that this issue (among others) will be looked into

(y)
 

Spin

Well-known member
Joined
May 22, 2019
Posts
455
Likes
178
Update:

I needed onTick for my 'Improved ATR Study', but decided to give it a go without onTick. And it worked out.

The Study is ready now, except for the remark / quirk described in my previous post in this thread. I still have no clue as to why it will only plot the markers after I changed the Study Parameters.


So, what does it do ?
The Study first calculates the ATR for a period of the trader's choice (5 days in this example), and then starts plotting the ATR above & below the price when a new trading day (or hour or H4 or week ...) commences.

When price rises, the 'bottom ATR' also rises the same amount of pips and the same goes for the 'top ATR'. This makes is exceptionally easy to see how far price is likely to rise / drop on any given trading day 🤩

I use it to decide whether still to get into a trade (how many pips to go to the ATR ?) and to place Take Profit levels

(please click on the image below for an enlarged view)

228

227

I am secretly hoping for MW-crew to offer a hint as to why this quirk exists, so I can finish it and offer it on my site, so others can start using it as well.
 

Attachments

  • ATR_POC1.png
    ATR_POC1.png
    88.4 KB · Views: 5
Last edited:
Top