Horizontal Lines

Custom indicators, trading strategies, data export and recording and more...
trdr_bust
Posts: 2
Joined: Sat Mar 13, 2021 6:13 pm

Horizontal Lines

Post by trdr_bust » Sat Mar 13, 2021 7:15 pm

Hi,

I'm trying to plot Horizontal lines on the Primary.

I'm trying to use one of the demos, but I can't seem to get it to work. 

In onTrade, when I pass in the trade price, it works OK(green line):

Code: Select all

 
@Override
public void onTrade(double price, int size, TradeInfo tradeInfo) {
    level1.addPoint(price);
}
bm_works.PNG
bm_works.PNG (183.17 KiB) Viewed 8637 times


But when I pass in my own value, I don't see the line on the chart and the widget shows a pretty big value:
 

Code: Select all

 
 @Override
public void onTrade(double price, int size, TradeInfo tradeInfo) {
    double test = 61000.0;
        //level1.addPoint(price);
    level1.addPoint(test);
}
bm_nogo.PNG
bm_nogo.PNG (178.63 KiB) Viewed 8637 times

Has anyone done something like this?  An opening Range Indicator, Pivot Points, something like that?

I've read over the forums, found this link(which is what I'm attempting to do):
https://bookmap.com/forum/viewtopic.php ... ntal#p4547

Also found this, seems like the same suggestion that I'm trying:
https://bookmap.com/forum/viewtopic.php ... ontal#p571
Yes, drawing a line is in fact placing points using Level 1 API....

I must be missing something, thanks...

Whole thing:

Code: Select all

 
package com.bookmap.api.simple.demo.indicators;

import java.awt.Color;

import velox.api.layer1.annotations.Layer1ApiVersion;
import velox.api.layer1.annotations.Layer1ApiVersionValue;
import velox.api.layer1.annotations.Layer1SimpleAttachable;
import velox.api.layer1.annotations.Layer1StrategyName;
import velox.api.layer1.data.InstrumentInfo;
import velox.api.layer1.data.TradeInfo;
import velox.api.layer1.messages.indicators.Layer1ApiUserMessageModifyIndicator.GraphType;
import velox.api.layer1.simplified.Api;
import velox.api.layer1.simplified.CustomModule;
import velox.api.layer1.simplified.Indicator;
//import velox.api.layer1.simplified.IndicatorModifiable;
import velox.api.layer1.simplified.InitialState;
import velox.api.layer1.simplified.TradeDataListener;

@Layer1SimpleAttachable
@Layer1StrategyName("Last trade: livex46")
@Layer1ApiVersion(Layer1ApiVersionValue.VERSION2)
public class LastTradeDemoNoHistory implements CustomModule, TradeDataListener
{
    protected Indicator level1;
    //protected Indicator level2;
    

    @Override
    public void initialize(String alias, InstrumentInfo info, Api api, InitialState initialState) {
   
    level1 = api.registerIndicator("tag1", GraphType.PRIMARY);
    level1.setColor(Color.GREEN);
    //double test = 61000.0;
    //level1.addPoint(test);
    }
    
    @Override
    public void stop() 
    {
    }

    @Override
    public void onTrade(double price, int size, TradeInfo tradeInfo) {
    double test = 61000.0;
    level1.addPoint(test);
    //level1.addPoint(price);
    }
}



 

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

Re: Horizontal Lines

Post by Andry API support » Mon Mar 15, 2021 8:16 am

Hi,
Primary panel:
the price value must be in pips. You can get pips value from the InstrumentInfo info object you get in the #initialize method.
For example, if pips is 0.25 and you need to plot at 60_000 the price must be 60_000/0.25 = 240_000;
Bottom panel:
It plots at the price you are passing.

trdr_bust
Posts: 2
Joined: Sat Mar 13, 2021 6:13 pm

Re: Horizontal Lines

Post by trdr_bust » Sat Mar 20, 2021 7:22 pm

Yep, pips, got it, thanks

Works now, seems a bit heavy, I'd like to just draw the lines at a price level without having to respond to bar updates. "Backfilling" to provide the level when viewing history takes a while(idk 30 seconds, depending on how much history of course).

I guess to speed it up, i'd need to look at ScreenPainter.  I had a look, but got a little confused at how to convert a price level(in pips yep) to a screen coordinate.  If anyone has a demo on how to do this that to share, that would be cool.  I might have another go at the samples to see if I can figure it out....

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

Re: Horizontal Lines

Post by Andry API support » Mon Mar 22, 2021 2:07 pm

Hi, here is a small example with a screenSpacePainter drawing a single last trade line.
Attachments
SingleLineSspFactory.java
(4.96 KiB) Downloaded 204 times
SimplifiedDemoSSPSingleLine.java
(1.51 KiB) Downloaded 190 times

Post Reply