How to Calculate Price Properly

Custom indicators, trading strategies, data export and recording and more...
thomas_kroger
Posts: 2
Joined: Thu Jun 10, 2021 3:17 pm

How to Calculate Price Properly

Post by thomas_kroger » Sun Jun 20, 2021 9:03 pm

I am trying to write an addon that will draw a line based on the user's input in the settings menu.  I was using ES replay to test on.  If I want to draw the line at 4200,  I have to multiple 4200 by 4 for it to display on the heatmap at 4200.  I am assuming the 4 is the tick value of the instrument since ES is 0.25 a tick.

Code: Select all

 
@Override
public void onTrade(double price, int size, TradeInfo tradeInfo) {
double convertPrice = settings.lineValue * 4;
lastTradeIndicator.addPoint(convertPrice);
What do I need to replace the 4 with so it will calculate correctly for different futures?

Andry API support
Posts: 548
Joined: Mon Jul 09, 2018 11:18 am
Has thanked: 25 times
Been thanked: 85 times

Re: How to Calculate Price Properly

Post by Andry API support » Mon Jun 21, 2021 8:22 am

hi,
we need to distinguish the Primary chart and the Bottom chart here.
Primary chart has only one axis (price axis) which indicates an asset price. We may say that Primary chart is tied to an asset. So a Primary chart indicator accepts values in ticks (pips) of the asset. Where do we take pips? We need to take pips from the InstrumentInfo instance in the initialize method.

Code: Select all

    double pips;
    
    @Override
    public void initialize(String alias, InstrumentInfo info, Api api, InitialState initialState) {
        this.pips = info.pips;
Assume we want to plot a point at 4200. So we need to recalculate this value into pips:
value-in-pips = 4200/pips;

Code: Select all

    @Override
    public void onTrade(double price, int size, TradeInfo tradeInfo) {
        indicator.addPoint(value/pips);
    }

Bottom chart may have multiple axes and is not tied to an asset. A Bottom chart indicator accept values just as they are.

Code: Select all

    @Override
    public void onTrade(double price, int size, TradeInfo tradeInfo) {
        indicator.addPoint(value);
    }

thomas_kroger
Posts: 2
Joined: Thu Jun 10, 2021 3:17 pm

Re: How to Calculate Price Properly

Post by thomas_kroger » Mon Jun 21, 2021 1:16 pm

This is for Primary chart.  Thank you for posting for both.  That is helpful.

Post Reply