Click here to Skip to main content
15,887,746 members
Home / Discussions / C#
   

C#

 
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 
QuestionExRichTextBox Pin
Star.jon24-Apr-13 21:45
Star.jon24-Apr-13 21:45 
AnswerRe: ExRichTextBox Pin
Marco Bertschi24-Apr-13 22:10
protectorMarco Bertschi24-Apr-13 22:10 
GeneralRe: ExRichTextBox Pin
Star.jon25-Apr-13 20:32
Star.jon25-Apr-13 20:32 
GeneralRe: ExRichTextBox Pin
Star.jon25-Apr-13 20:35
Star.jon25-Apr-13 20:35 
GeneralRe: ExRichTextBox Pin
Marco Bertschi25-Apr-13 21:49
protectorMarco Bertschi25-Apr-13 21:49 
Questionhow to detect SoundEffect stoped in xna Pin
payjo24-Apr-13 15:15
payjo24-Apr-13 15:15 
Questionsetup error in c# Pin
User349024-Apr-13 4:11
User349024-Apr-13 4:11 
AnswerRe: setup error in c# Pin
Keith Barrow24-Apr-13 5:05
professionalKeith Barrow24-Apr-13 5:05 
QuestionCallBack to consumer using RESTful / MVC / WCF Pin
jexes23-Apr-13 22:51
jexes23-Apr-13 22:51 
QuestionProgramming a Symbol Handheld Scanner Pin
bob18123-Apr-13 20:57
professionalbob18123-Apr-13 20:57 
AnswerRe: Programming a Symbol Handheld Scanner Pin
Pete O'Hanlon23-Apr-13 21:29
mvePete O'Hanlon23-Apr-13 21:29 
AnswerRe: Programming a Symbol Handheld Scanner Pin
Joe Woodbury24-Apr-13 8:19
professionalJoe Woodbury24-Apr-13 8:19 
Questionprinting students grades after finding them in files.. Pin
Magda634723-Apr-13 9:30
Magda634723-Apr-13 9:30 
AnswerRe: printing students grades after finding them in files.. Pin
Eddy Vluggen23-Apr-13 9:36
professionalEddy Vluggen23-Apr-13 9:36 

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.