The buying selling volume works perfect when seen in Daily timeframe, however it is not showing correct numbers in lower time frame - trading

So, I am creating an Buy/sell Volume indicator. It shows total buying and selling volume of the script. The indicator was working perfect and now I want to add a table that shows daily buying and selling volume when I am seeing lower time frame i.e, 1 min, 5 min and 10 min. I wrote the code and table shows correct value of volume when looking at daily time-frame, but when I change to lower-time-frame the numbers are not correct. I don't know if it is calculation problem or coding problem. If any one can help me, I will be very Thankfull.
I have attached image of what it is showing on daily time-frame. In image the table shows daily buying and selling volume and the screenshot is taken on daily time-frame.enter image description here
//#version=4
study("BS",format=format.price, precision=0)
buyVolume = iff( (high==low), 0, volume*(close-low)/(high-low))
plot(volume, style=plot.style_columns, color=color.red, title="SELL V")
plot(buyVolume, style=plot.style_columns, color=color.teal, title="BUY V")
volD = security(syminfo.tickerid, "D", volume)
buyVolume1 = iff( (high==low), 0, volD*(close-low)/(high-low))
sellvolume = volD - buyVolume1
string i_positionr = position.bottom_right
var tblr = table.new(i_positionr, 3, 3, frame_color=#151715, frame_width=1, border_width=2,
border_color=color.new(color.white, 100))
if barstate.islast
table.cell(tblr, 0, 1, 'Buy Volume', text_halign = text.align_center, bgcolor =
color.green, text_color = color.white, text_size = size.normal)
table.cell(tblr, 1, 1, 'Sell Volume', text_halign = text.align_center, bgcolor =
color.red, text_color = color.white, text_size = size.normal)
table.cell(tblr, 0, 2, tostring(buyVolume1,format.price) , text_halign = text.align_center,
bgcolor = color.green, text_color = color.white, text_size = size.normal)
table.cell(tblr, 1, 2, tostring(sellvolume,format.price) , text_halign = text.align_center,
bgcolor = color.red, text_color = color.white, text_size = size.normal)

Related

Multiple Line chart with 2 dataSets

I am trying to draw Multiple line chart using iOS-Charts danielgindi/Charts library by as show in picture.
Expected Output:
Data1 = [Jun: 34, Jul: 42, Aug: 32, Sep: 30, Oct: 38]
Data2 = [Oct: 38, Nov: 40, Dec: 32, Jan: 40]
let dataSet1 = LineChartDataSet(values: Data1, label: nil)
dataSet1.lineDashLengths =[0]
dataSet1.drawCirclesEnabled = false
let dataSet2 = LineChartDataSet(values: Data2, label: nil)
dataSet2.lineDashLengths =[10]
dataSet2.drawCirclesEnabled = true
let data = LineChartData(dataSets:[dataSet1, dataSet2])
lineChartView?.data = data
I want to draw the first set with solid line and second set with Dotted line.
I am using iOS Charts library. (MultiLineChartView)
The problem which I m facing is the dotted line also start at the beginning of x-Axis. (As shown below)
Could anyone help me on this please?
You must be having minimum and maximum for the x-Axis so you just have to set the starting x-axis for your second set to be the ending x-axis of the first data set. A very good example is included in the examples as CombinedChartViewController. Please try to run the demo and play with the x-Axis of any type of chart,
ChartDataEntry(x: 0.5, y: 30)

Unable to create a working sprite

I am unable to create a working animation sprite for this single area of my app.
I am using Corona SDK and have the following sprite:
This is names mainCharacter.png. I have a double sized version called mainCharacter#2x.png.
I have sheet options, 2 sequences, I'm building an image sheet and passing that to my sprite:
local playerSheetOptions =
{
width = 50,
height = 50,
numFrames = 17,
sheetContentWidth = 500,
sheetContentHeight = 100
}
local playerSequences = {
{
name = "idle",
start = 1,
count = 12,
time = 1200,
loopCount = 0,
loopDirection = "bounce"
},
{
name = "jump",
start = 13,
count = 5,
time = 600,
loopCount = 1
},
}
local playerSheet = graphics.newImageSheet( "resource/images/mainCharacter.png", playerSheetOptions )
local player = display.newSprite(gameSheet, playerSheet, playerSequences)
I am getting the following error:
display.newSprite() requires argument #2 to a table containing sequence data
If I print the relevant data:
print(gameSheet)
print(playerSheet)
print(playerSequences)
I get:
14:27:05.703 userdata: 12445228
14:27:05.703 userdata: 0CF42600
14:27:05.703 table: 0CF41FD0
Where am I going wrong? I have tried simplifying the sequences a lot, but still get the same thing.
Use
local player = display.newSprite(playerSheet, playerSequences)
instead of
local player = display.newSprite(gameSheet, playerSheet, playerSequences)
From Corona documentation
Once the image sheet(s) and sequences are set up, a new sprite object
can be created with the display.newSprite() API:
display.newSprite( [parent,] imageSheet, sequenceData )
For this API, the parent
parameter is optional and represents the display group in which to
insert the sprite. The imageSheet parameter defines the default image
sheet for the sprite, and sequenceData is the table that contains all
of the sequences for the sprite.
Read more about Sprite Animation.

Lua - Corona SDK - Text not appearing inside a display Object

I am trying to move a display object that is hiding over the right side of the screen, into the scene. It works wonderfully with images (i.e. the background), but not with texts (the coords seem correct from debugging them with print(), but they never display, I already tried the obj:toFront).
I thought that they may work inside display objects, so I put everything in a display Object: Nothing. Just the text? Neither. Anyone knows why/how to override this?
function tscreen:init()
local textGroup = display.newGroup()
local menuBackground = self:getBtn("src/bgMenu.png")
menuBackground.isVisible = false
menuBackground.anchorX = 0.5
menuBackground.anchorY = 0.5
self.menuBackground = menuBackground
local optionsText = {
parent = textGroup,
text = "Hello World",
x = centerX,
y = centerY,
width = 128,
font = native.systemFontBold,
fontSize = 14,
align = "center"
}
local workText = display.newText( optionsText )
workText:setFillColor( 1, 0, 0 )
setPos(textGroup, W, 0)
--setPos() is a custom function that assigns x and y coords
textGroup.isVisible = false
self.textGroup = textGroup
end
function tscreen:show()
local menuBackground = self.menuBackground
local textGroup = self.textGroup
local inTime = 1200
setPos(menuBackground, 2*W + centerX, centerY)
menuBackground.isVisible = true
setPos(textGroup, W, 0)
textGroup.isVisible = true
self:cancelTween(menuBackground)
self:cancelTween(textGroup)
menuBackground.tween = transition.to(menuBackground, {time = inTime, transition = easing.outExpo, x = centerX,
onComplete = function()
tscreen:cancelTween(menuBackground)
end
})
textGroup.tween = transition.to(textGroup, {time = inTime, transition = easing.outExpo, x = 0,
onComplete = function()
tscreen:cancelTween(textGroup)
print(getPos(textGroup), textGroup.width, textGroup.height)
end
})
end
I have the starters edition of Corona, so I don't have the recently implemented Composer API.
Maybe this isn't the most appropriate site to post this query since there already is a Corona SDK forum, but I'm trying anyway.
I'm not seeing anything wrong, but a group should not be necessary. Verify that the text can be seen ever: in the init(), do
local optionsText = {
text = "Hello World",
x = 0,
y = 100,
}
local workText = display.newText( optionsText )
workText:setFillColor( 1, 1, 1 )
If you can't see the text then something else is going on, maybe your init() is not being called or such. Once you see it, change the parameters to what you want (fill color etc), and test. If still works, add a transition, right after, in the init():
local easeXto100 = {
time = 2000,
transition = easing.outExpo,
x = 100,
onComplete = function() print('did you see text move from x=0 to 100?') end
}
transition.to(workText, easeXto100)
If you see it move, then move the relevant parts of code to your show(), if now it disappears this will give you clue.

In Corona SDK how to add label(text) to images?

In corona SDK how to add label(text) to images
I have created my image as follow
local item = display.newImageRect('images/foo.png',70,70);
item.x = 50;
item.y = 50;
How to add a text to the image?
Many Thanks
To add text to the image, so it appears to "stick" to the image, you could create the object (as you have) and also the text object directly above it. Then, create a group and stick them both in it.
Here is an example of how that could be done:
local myGroup = display.newGroup()
local item = display.newImageRect('images/foo.png',70,70)
item.x = 50
item.y = 50
local text = display.newText( "My Text", 0, 0, "Helvetica", 18 )
text:setTextColor( 0, 0, 0, 255 )
-- insert items into group, in the order you want them displayed:
myGroup:insert( item )
myGroup:insert( text )
Then, to move it around, just modify the x/y of 'myGroup'.
Hope that helps!

Apply merge layers on multiple images without losing layers

My problem:
I want to make a lot of images that differ only in three text layers. I have already figured out, how to make the text changes with the Python-Fu Console. My next step is to put this text change code into a loop and add a png.file-save-png(...) to save the picture. In order to save as a PNG I have to merge all my layers (for each image), which is no problem with single_layer = pdb.gimp-image-merge-visible-layers(image,0). In order to keep working from here, I would need to to an undo, to get my old layers back.
Do I need to apply an UNDO Operation in GIMP from a script?
I couldn't find any hint on this feature. Maybe anyone knows how to do this, or has a workaround.
After a night of sleep, I figured out a workaround:
I reopened the base image file for each card in the loop, where all layers and text layers stayed intact. That prevented me from needing the undo.
By the way, here is my script for creating 4 * 13 playing cards (from ones own base_card.xcf):
basefile = "/home/[...]/base_card.xcf"
basesave = "/home/[...]/"
color_blue = [ (32.0 /255.0, 74.0/255.0,135.0/255.0,1.0),
(52.0 /255.0,101.0/255.0,164.0/255.0,1.0)]
color_red = [ (164.0/255.0, 0.0/255.0, 0.0/255.0,1.0),
(204.0/255.0, 0.0/255.0, 0.0/255.0,1.0)]
color_yellow = [ (196.0/255.0,160.0/255.0, 0.0/255.0,1.0),
(237.0/255.0,212.0/255.0, 0.0/255.0,1.0)]
color_green = [ ( 78.0/255.0,154.0/255.0, 6.0/255.0,1.0),
(115.0/255.0,210.0/255.0, 22.0/255.0,1.0)]
def createCard(color_list, color_name, number):
pdb.gimp_context_set_foreground(color_list[1])
image = pdb.gimp_file_load(basefile, basefile)
textlayers = image.layers[0:3]
for layer in textlayers:
pdb.gimp_text_layer_set_text(layer, number)
pdb.gimp_text_layer_set_color(layer, color_list[0])
layer = image.layers[3]
pdb.gimp_edit_bucket_fill(layer, 0, 0, 100, 0, 0, 30, 30)
layer = pdb.gimp_image_merge_visible_layers(image, 0)
savename = "%s%s_%s.png" % (basesave, color_name, number)
pdb.file_png_save(image, layer, savename, savename, 0, 0, 0, 0, 0, 0, 0)
image = None
for c in range(1,14):
createCard(color_blue, "BLUE", c)
for c in range(1,14):
createCard(color_yellow, "YELLOW", c)
for c in range(1,14):
createCard(color_red, "RED", c)
for c in range(1,14):
createCard(color_green, "GREEN", c)

Resources