Help to code Lists
Help to code Lists
28 Jul 2017, 02:57
Hello,
Please I need your help to code two lists to storage some information from the Sell & Buy positions like the folowing example
Sell List
TradeType EntryPrice EntryTime Pips NetProfit
Buy List
TradeType EntryPrice EntryTime Pips NetProfit
Adding every new order as appropiate in decending order of EntryPrice and keep it until the order(s) is close
Thank you very much for your attention
IR
Replies
ivan-rifo
01 Aug 2017, 06:14
Dear cTrader Team,
Thank you very much for your help all the information is very hepfull for me. I'm less than a beginner in coding so i really appreciate your answer.
And would like to take the oportunity to make another question if you can help me again.
I'm trying to fill an array with the numbers of an interval just like the following example.
Min value: 1.16660
Max value: 1.16680
Total of elements: 22
"Min value", "Max Value" and "Total of elements" are variables
and expecting the array it fills like this
{ 1.16660,1.16661,1.16662,1.16663,1.16664,1.16665,1.16666,1.16667,1.16668,1.16669,1.16670,1.16671,1.16672,1.16673,1.16674,1.16675,1.16676,1.16677,1.16677,1.16678,1.16679,1.16680}
I generated this code, just test it out in visual studio first.
int NE = new int();
int[] N_array = new int [NEM_S];
for (int i = minv; i <= maxv; i ++)
{
N_array[NE] = i;
}
foreach(int element in Sell)
{
System.Console.WriteLine(element);
}
But just printed out {1.16680,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} and i can't find my mistake.
Again thank you very much for your help
IR
@ivan-rifo
Spotware
01 Aug 2017, 09:39
Hi ivan-rifo,
The problem is that in the loop you use NE as your array's index, which is always 0. Therefore the values are always assigned to N_array[0]. In the loop you need use i for the array's index and then introduce another variable that will start at 1.16660 will increase by 0.00001 in each loop. Let us know if you need any further assistance.
Best Regards,
cTrader Team
@Spotware
ivan-rifo
02 Aug 2017, 00:59
RE: Thank you very much again
Spotware said:
Hi ivan-rifo,
The problem is that in the loop you use NE as your array's index, which is always 0. Therefore the values are always assigned to N_array[0]. In the loop you need use i for the array's index and then introduce another variable that will start at 1.16660 will increase by 0.00001 in each loop. Let us know if you need any further assistance.
Best Regards,
cTrader Team
Dear cTrader Team
Always your answer are very helpfull for me so Thank you very much for your help.
IR
@ivan-rifo
emeeder1
26 Mar 2021, 20:56
where are 'List' Stored?
This is old post, but relevant to my question. Maybe someone can explain this for me?
In the List function, is the resulting list saved somewhere on local computer? what happens to data saved to list when disconnected or if Ctrader restarted? is List functions available in both indicator and Bot?
Primarily i want to store data permanently so it does not get lost when ctrader turned off.
Also: if List is not saved locally, is there a function available that can access local data on computer (excel table, database...)?
Thanks :)
@emeeder1
amusleh
26 Mar 2021, 22:40
RE: where are 'List' Stored?
emeeder1 said:
This is old post, but relevant to my question. Maybe someone can explain this for me?
In the List function, is the resulting list saved somewhere on local computer? what happens to data saved to list when disconnected or if Ctrader restarted? is List functions available in both indicator and Bot?
Primarily i want to store data permanently so it does not get lost when ctrader turned off.
Also: if List is not saved locally, is there a function available that can access local data on computer (excel table, database...)?
Thanks :)
cTrader automate API is written in C# and is based on .NET framework, you can use all .NET libraries inside your cTrader indicator/cBot.
The .NET collections including list is stored in your system memory and when your .NET program in our case indicator/cBot is terminated the memory will be cleaned up and you will not have access to it next time your .NET program runs.
To save data permanently you have to write it on the disk, you can easily write anything you want to on files via .NET file stream object.
If you need code examples please Google reading/writing files C# and you will find lots of code samples.
@amusleh
Spotware
28 Jul 2017, 09:22
Dear ivan-rifo
.Net Framework has a List class that will allow you to implement what you need. See below an example of how you can add your positions in a list and order them by EntryPrice in a descending order
In order to use lists you will need to reference System.Collections.Generic namespace. See below an example
Let us know if the above information is helpful to you.
Best Regards,
cTrader Team
@Spotware