Label at price and time on a chart

If you need an Indicator or Signal developed or translated from other language, please post all Indicator development REQUESTS to this section here.

Moderator: admin

Label at price and time on a chart

Postby Strauss.c.m » Thu Apr 22, 2021 9:35 am

Hi
I am trying to display a text label on a chart from within an indicator, at the current time and just above or below the current price when a Bollinger band is breached

I have used core.host:execute("drawLabel1", .... and I have step traced my code and the line executes during the trace but when I install and run it nothing is displayed when it should be. I want to display a literal when the price moves outside a Bollinger band

I notice in the indicor SDK 3 help on the public method host:execute("drawLabel1", ...) page that there is a note at the bottom which says "Note: This function is optional and may be not supported by the host application." Could this be the reason I am not getting anything on the chart? I am running Marketscope 2.0 . I also looks like the system is slowed a bit when I run the indicator

I used the example from help and tailored it

My code for when price breaks above the top band is as follows:
if source:tick(-1) > TL:tick(-1) and -- The Top Line is being breached
G_TL_DISPLAYED ~= period then -- and not yet displayed this candle
G_TL_DISPLAYED = period; -- Set the "displayed" indicator for this candle
G_LAST_BREACH = G_TL; -- Stored for when price gets to the Mid-Line
--------------------------------------------------------------------------------
-- calculate the position to display the literal and display it
--------------------------------------------------------------------------------
G_ID = G_ID + 1; -- increment the label ID
core.host:execute("drawLabel1",
G_ID,
core.now(), -- the current local time and date
core.CR_CHART,
source:tick(-1) + (G_TL_PIP_GAP /10000), -- The gap to create above the current price and is correct
core.CR_CHART,
core.H_Right,
core.V_Bottom,
G_FONT, -- Used Arial and during trace is C40A31DD
G_FONT_COLOUR, -- used red and during trace is 255.000000
G_TL_LITERAL); -- contains TL during trace test as it should
end

I created G_FONT in Prepare as follows
----------------------------------------------
-- Create the text font
----------------------------------------------
G_FONT = core.host:execute("createFont",
instance.parameters.FONT_NAME,
instance.parameters.FONT_SIZE,
instance.parameters.FONT_ITALIC,
instance.parameters.FONT_BOLD);

Could somebody please be so kind as to help me as i am very new to indicore and rather embarrassed to ask
If have attached the indicator in case you want to run it

Hoping for a response
Strauss.c.m
 
Posts: 9
Joined: Mon Jan 02, 2012 4:29 am

Re: Label at price and time on a chart

Postby Apprentice » Fri Apr 23, 2021 3:34 am

Can you attach the complete file?
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Label at price and time on a chart

Postby Strauss.c.m » Fri Apr 23, 2021 9:07 am

Good afternoon Apprentice
I have found a way to set the text display in the help system
I now use
Label_TL:set(period,
source.high[period],
G_TL_LITERAL,
string.format(Tooltip_Format, source.high[period]));
This seems to work well except for when I initially load the indicator.

I am attaching the full lua and I am attaching 2 screen shots.

The first screen shot shows when I initially load the indicator (in BB_Just_Loaded.PNG) and you will see that it displays a whole lot of "B"'s which are mostly wrong

In the second one (in After_Load_Running_Correctly.PNG) after the crosshairs it displays the "B"'s as they should be displayed plus 1 ML when it reaches the midline and then the correct "T"'s
It would appear that the TL:tick(-1) is not updated correctly during the load of the chart

If this can be corrected it would be awesome, as the "B"'s are displayed all the way back to the start of the chart, but if not then I would appreciate assistance to suppress the display of text till it reaches the first candle from when I load it

If I set the display indicator.parameters:addBoolean("DISPLAY_TEXT" to false then only the bands and midline are displayed as I would expect

Sorry for the inconvenience but I am still new at Lua but am an old programmer

Your assistance is greatly appreciated
Attachments
Cms_BB_Text.lua
the lua code
(20.76 KiB) Downloaded 134 times
BB_Just_Loaded.PNG
The initial load
After_Load_Running_Correctly.PNG
Running correctly
Strauss.c.m
 
Posts: 9
Joined: Mon Jan 02, 2012 4:29 am

Re: Label at price and time on a chart

Postby Apprentice » Fri Apr 23, 2021 11:49 am

Your request is added to the development list.
Development reference 404.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Label at price and time on a chart

Postby Strauss.c.m » Fri Apr 23, 2021 1:30 pm

Hi Apprentice
Thanks a stack for your previous example of BB Cross.lua
I understand what you have done and will use it as a template to work from
much appreciated
you can close this one as well
Thanks again
Strauss.c.m
 
Posts: 9
Joined: Mon Jan 02, 2012 4:29 am

Re: Label at price and time on a chart

Postby Strauss.c.m » Thu May 06, 2021 5:32 am

Good morning Apprentice
i have tried my best with my limited lua knowledge and have gone a long way but not been able to get a 100% result

I have attached 4 .lua files and 4 related .PNG files showing the problems I encountered. You will notice a verticle line on all the .PNG files which is where I started the indicators

As you will see from the file names I have tried 4 different routes
1. BB_Text_Core_Bar_Source_Close
2. BB_Text_Core_Bar_Source_Low
3. BB_Text_Core_Bar_tick-1
4. BB_Text_Core_Tick_tick-1

1. The core.Bar indicators load all the candles including those prior to starting the indicator, correctly except for a few which are wrong.
1.1. source.close sometimes misses some, before and after starting the indicator, as the price moves back inside during the candle i.e. the price close is inside the band during the same candle as the breach occurs
1.2. source.low / high sometimes show a breach of the band that did not happen, when the price goes right up to the band but does not breach it, and then when the price moves away, the band closes, past where the low / high was and that triggers the breach. This mainly happens with larger timeframes, which are the important ones

2. The core.Tick indicators work perfectly after the period that the indicator is started, but prior to that the source:tick(-1) values are all the same, as you can see in the tooltip, resulting in a lot of spurious breaches being reflected even though the bands are drawn correctly as they use the periods tick values for their calculations

My questions are as follows
1. Is it possible to obtain the individual tick values, if cor.Bar is the source, even if there is a bit of an overhead. I am hoping so, given that the last band moves, as the price moves, during the timeframe, before the close

OR

2. Is it possible to somehow update the core.Bar or core.Tick, tick(-1) values, per tick, for all the periods prior to starting the indicator

Your assistance will be greatly appreciated
Attachments
BB_Text_Core_Bar_Source_Close.PNG
BB_Text_Core_Bar_Source_Close.lua
(32.89 KiB) Downloaded 134 times
BB_Text_Core_Bar_Source_Low.PNG
BB_Text_Core_Bar_Source_Low.lua
(30.36 KiB) Downloaded 127 times
BB_Text_Core_Bar_tick-1.PNG
BB_Text_Core_Bar_tick-1.lua
(32.8 KiB) Downloaded 130 times
BB_Text_Core_Tick_tick-1.PNG
BB_Text_Core_Tick_tick-1.lua
(26.09 KiB) Downloaded 122 times
Strauss.c.m
 
Posts: 9
Joined: Mon Jan 02, 2012 4:29 am

Re: Label at price and time on a chart

Postby Apprentice » Fri May 07, 2021 4:04 am

Your request is added to the development list.
Development reference 449.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Label at price and time on a chart

Postby Apprentice » Sat May 08, 2021 7:00 am

Unfortunately, we can only load a limited number of tick data.

You can try to load tick data for each candle.
Will work on smaller time frames. (m1, m5)
Not feasible about higher time frames.

You can try to use a helper indicator that will use high/low,
which you will use as the source for the final indicator.
You will probably need to use core.UpdateAll
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Label at price and time on a chart

Postby Strauss.c.m » Fri May 21, 2021 12:10 pm

Hi Apprentice
Thanks for your input
I have found another way to work around the problem in the absence of some of the tick data detail
Thanks for your input and the best with your cource
Regards
Christopher
Strauss.c.m
 
Posts: 9
Joined: Mon Jan 02, 2012 4:29 am


Return to Indicator and Signal Requests

Who is online

Users browsing this forum: Bing [Bot] and 18 guests