Page 1 of 1

Point me in the right direction (csv file read)

PostPosted: Sun Oct 02, 2016 5:04 am
by Cactus
Hello friendly people, could you point me in the right direction with the code I want to create:
I will like to add it to an existing strategy.

* User to select a .csv file to read that contains many price levels for particular asset.
**** Can a strategy be specified file path like indicators?
* When my strategy gives a signal, loop through the list on the .csv file, and if the candlestick (on specified timeframe) open below any of the prices but is currently above the same price it opened below, sell. Conversely, if the candlestick (on specified timeframe) open above any price from the .csv file but is currently below that price, buy.

So in short, if my strategy gives an arrow signal to trade, check if price is crossing any of the levels in the .csv file looking at the candlestick, and only then allow to trade if there's both an arrow and the price is crossing the level. Hope this is clear and you could provide me with some code examples to achieve this. I have both the strategy providing the signals and the .csv file but missing the functionality to join them together by making the strategy read the file and loop automatically through the list of prices and trade only when both conditions are met.

The code I need help with is in bold Thanks

Re: Point me in the right direction (csv file read)

PostPosted: Mon Oct 10, 2016 5:36 am
by Georgiy
Hi Cactus,

Please see recommendations below:
1. The way to add a file parameter:
Code: Select all
indicator.parameters:addFile("file", "File", "", "");


2.The way to handle all strings:
Code: Select all
local handle, error = io.open(instance.parameters.file, "r");
for line in handle:lines() do
core.host:trace(tostring(line));
end
handle:close();


3.The way to separate a string into values:
http://www.fxcodebase.com/bin/beta/IndicoreSDK-3.0/help/web-content.html#core.parseCsv.html

Re: Point me in the right direction (csv file read)

PostPosted: Thu Oct 13, 2016 3:01 pm
by Cactus
That's great thank you for your time with providing this information