Click here to Skip to main content
15,904,339 members
Home / Discussions / C#
   

C#

 
GeneralRe: Data in XmlFiles or in Database Pin
jschell27-Apr-13 11:21
jschell27-Apr-13 11:21 
GeneralRe: Data in XmlFiles or in Database Pin
Jasmine250128-Apr-13 6:26
Jasmine250128-Apr-13 6:26 
GeneralRe: Data in XmlFiles or in Database Pin
jschell29-Apr-13 7:45
jschell29-Apr-13 7:45 
GeneralRe: Data in XmlFiles or in Database Pin
Jasmine250129-Apr-13 13:13
Jasmine250129-Apr-13 13:13 
GeneralRe: Data in XmlFiles or in Database Pin
jschell30-Apr-13 9:44
jschell30-Apr-13 9:44 
GeneralRe: Data in XmlFiles or in Database Pin
Jasmine250130-Apr-13 11:30
Jasmine250130-Apr-13 11:30 
GeneralRe: Data in XmlFiles or in Database Pin
jschell1-May-13 8:22
jschell1-May-13 8:22 
GeneralRe: Data in XmlFiles or in Database Pin
Jasmine25011-May-13 9:03
Jasmine25011-May-13 9:03 
GeneralRe: Data in XmlFiles or in Database Pin
jschell2-May-13 7:57
jschell2-May-13 7:57 
GeneralRe: Data in XmlFiles or in Database Pin
Jasmine25012-May-13 9:02
Jasmine25012-May-13 9:02 
GeneralRe: Data in XmlFiles or in Database Pin
jschell3-May-13 11:02
jschell3-May-13 11:02 
GeneralRe: Data in XmlFiles or in Database Pin
Jasmine25013-May-13 11:40
Jasmine25013-May-13 11:40 
GeneralRe: Data in XmlFiles or in Database Pin
jschell6-May-13 8:11
jschell6-May-13 8:11 
GeneralRe: Data in XmlFiles or in Database Pin
Jasmine25016-May-13 8:26
Jasmine25016-May-13 8:26 
GeneralRe: Data in XmlFiles or in Database Pin
jschell7-May-13 9:27
jschell7-May-13 9:27 
AnswerRe: Data in XmlFiles or in Database Pin
RedDk26-Apr-13 11:54
RedDk26-Apr-13 11:54 
GeneralRe: Data in XmlFiles or in Database Pin
Eddy Vluggen26-Apr-13 22:36
professionalEddy Vluggen26-Apr-13 22:36 
AnswerRe: Data in XmlFiles or in Database Pin
Eddy Vluggen26-Apr-13 23:32
professionalEddy Vluggen26-Apr-13 23:32 
GeneralRe: Data in XmlFiles or in Database Pin
Frygreen27-Apr-13 0:31
Frygreen27-Apr-13 0:31 
AnswerRe: Data in XmlFiles or in Database Pin
PIEBALDconsult27-Apr-13 12:31
mvePIEBALDconsult27-Apr-13 12:31 
QuestionRunning a loop, try to get both [i] value (todayvalue), and [i - 1] value (yesterdays value) Pin
lordoftrades25-Apr-13 0:47
lordoftrades25-Apr-13 0:47 
AnswerOT Pin
Keith Barrow25-Apr-13 2:56
professionalKeith Barrow25-Apr-13 2:56 
Hi Espen, first of something a bit OT:

if (0 <= mov10value - mov50value  &&  0 <= mov20value - mov50value)

I'd personally put the constant after the condition, some people do it (especially hardcore ex c++ devs), but the compiler will warn if you perform a potentially accidental assignment-->
if (mov10value - mov50value > 0 &&  mov20value - mov50value > 0)

This can be further simplified to:

if (mov10value > mov50value &&  mov20value > mov50value)

Which makes the conditional much easier to read, you'll need to check I've done what you needed. I'd stick an else before the second if as they seem to be mutually exclusive, if not ignore.

I'd rename the variables, to MovingAverage10, 50 etc. it'll make the code clearer to C# bodies, you'll get something like this:

C#
if (MovingAverage10 > MovingAverage50  &&  MovingAverage20 > MovingAverage50)
    {
        BrokerMarket(IQ_ActionType.BUY, symbolIndex, 100, IQ_TIF.DAY, "Buy");
    }
if ( MovingAverage50 > MovingAverage20 && MovingAverage50 - MovingAverage20 <= 0.3 && PositionExists(IQ_TradeStatus.OPEN, symbolIndex))
    {
        int[] positionIndexes = PositionIndexList(IQ_TradeStatus.OPEN, symbolIndex);
        double quantity = PositionQuantity(positionIndexes[0]);
        BrokerMarket(IQ_ActionType.SELL, symbolIndex, quantity, IQ_TIF.DAY, "Sell");
    }


As for calculating the avergages, the -1 index should work, as long as you aren't on index 0 obviously.

Personally I'd avoid arrays unless I want to specify that I know the length of this list isn't going to change. I'd suggest a generic List<T> instead. Assuming you have are using .net 3.5 & we have the previous 100 days data in a List<double> called quantities, ending at today:

C#
public static double GetMovingAverage(List<double> quantities, int daysToTake)
        {
            if (quantities.Count < daysToTake)
            {
                //throw exception
            }

            var qualifyingQuantities = quantities.Skip(quantities.Count - daysToTake).Take(daysToTake);
            return quantities.Average();
        }



Don't feel like I've answered you Unsure | :~ hope this helps.
“Education is not the piling on of learning, information, data, facts, skills, or abilities - that's training or instruction - but is rather making visible what is hidden as a seed”
“One of the greatest problems of our time is that many are schooled but few are educated”


Sir Thomas More (1478 – 1535)

GeneralRe: OT Pin
lordoftrades25-Apr-13 3:37
lordoftrades25-Apr-13 3:37 
GeneralRe: OT Pin
Keith Barrow25-Apr-13 6:26
professionalKeith Barrow25-Apr-13 6:26 
GeneralRe: OT Pin
lordoftrades25-Apr-13 20:29
lordoftrades25-Apr-13 20:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.