|
Hi
I have a loop where I try to pull stockdata, i'm getting moving averages for each day in the loop.
The basic idea is to enter a trade if MA20 is crossing MA50, and MA10 is above MA50.
I've written this test in VBA in Excel, then it was easy to define yesterdays value, it todays value was set by i, yesterday was i - 1.
But in C# I don't know how to solve it, I've just started to write in this language....
if (0 <= mov10value - mov50value && 0 <= mov20value - mov50value)
{
BrokerMarket(IQ_ActionType.BUY, symbolIndex, 100, IQ_TIF.DAY, "Buy");
}
if (0 <= mov50value - mov20value && mov50value - mov20value <= 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");
}
Any help would be appreciated.
Kind regards
Espen
|
|
|
|
|
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:
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:
public static double GetMovingAverage(List<double> quantities, int daysToTake)
{
if (quantities.Count < daysToTake)
{
}
var qualifyingQuantities = quantities.Skip(quantities.Count - daysToTake).Take(daysToTake);
return quantities.Average();
}
Don't feel like I've answered you 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)
|
|
|
|
|
Thank you very much Keith, it cleared out quite some things for me, and I see that my logic sense has been totally lost some time.
I still have some questions on how to solve the case regarding the "yesterdays moving average".
Maybe this explains it better: I'm trying to detect when MA20 is crossing above MA50 (given that MA10 already is above). I need to know that MA20 was below MA50 yesterday to be sure that it has crossed as I'm not interested in the days when it stays above.
The MovingAverages are some sort preset scripts in a software that I use (IQBroker)
public void OnInitialize(int indicatorKey)
{
_MovingAverage10Keys = new int[SymbolCount()];
_MovingAverage20Keys = new int[SymbolCount()];
_MovingAverage50Keys = new int[SymbolCount()];
_indicatorKeys = new int[SymbolCount()];
for (int i = 0; i < SymbolCount(); i ++)
{
_indicatorKeys[i] = IndicatorCopy(indicatorKey, i);
_MovingAverage10Keys[i] = IndicatorSMA(_indicatorKeys[i], 10);
_MovingAverage20Keys[i] = IndicatorSMA(_indicatorKeys[i], 20);
_MovingAverage50Keys[i] = IndicatorSMA(_indicatorKeys[i], 50);
ChartIndicator(i, 0, IQ_YAxis.MERGE_RIGHT, _indicatorKeys[i], IQ_LineType.LINE, 1, IQ_Color.GREEN);
ChartIndicator(i, 0, IQ_YAxis.MERGE_RIGHT, _MovingAverage10Keys[i], IQ_LineType.LINE, 1, IQ_Color.RED);
ChartIndicator(i, 0, IQ_YAxis.MERGE_RIGHT, _MovingAverage20Keys[i], IQ_LineType.LINE, 1, IQ_Color.ORANGE);
ChartIndicator(i, 0, IQ_YAxis.MERGE_RIGHT, _MovingAverage50Keys[i], IQ_LineType.LINE, 1, IQ_Color.BLUE);
}
}
#endregion</pre>
Here's the If-part of the code:
{
double MovingAverage10 = IndicatorValue(_MovingAverage10Keys[symbolIndex]);
double MovingAverage20 = IndicatorValue(_MovingAverage20Keys[symbolIndex]);
double MovingAverage50 = IndicatorValue(_MovingAverage50Keys[symbolIndex]);
if (MovingAverage10 > MovingAverage50 && MovingAverage20 > MovingAverage50)
{
BrokerMarket(IQ_ActionType.BUY, symbolIndex, 10, IQ_TIF.DAY, "Buy");
}
if (MovingAverage20 < MovingAverage50 && MovingAverage50 - MovingAverage20 <= 0.8 && 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");
}
}
#endregion</pre>
I start to realize that the transition from VBA to C# is pretty tough
Kind regards
Espen
|
|
|
|
|
lordoftrades wrote: Maybe this explains it better: I'm trying to detect when MA20 is crossing above MA50 (given that MA10 already is above). I need to know that MA20 was below MA50 yesterday to be sure that it has crossed as I'm not interested in the days when it stays above.
Assuming you've calc'd the averages in psuedo code I'd do something like:
double MovingAverage10 = IndicatorValue(_MovingAverage10Keys[symbolIndex]);
double MovingAverage20 = IndicatorValue(_MovingAverage20Keys[symbolIndex]);
double MovingAverage50 = IndicatorValue(_MovingAverage50Keys[symbolIndex]);
double YesterdayMovingAverage10 = IndicatorValue(_MovingAverage10Keys[symbolIndex-1]);
double YesterdayMovingAverage20 = IndicatorValue(_MovingAverage20Keys[symbolIndex-1]);
double YesterdayMovingAverage50 = IndicatorValue(_MovingAverage50Keys[symbolIndex-1]);
public bool NeedToSell()
{
if(MovingAverage10 < MovingAverage50 || MovingAverage10 < MovingAverage20)
return false;
if (MovingAverage20 <= MovingAverage50)
return false;
return YesterdayMovingAverage20 < YesterdayMovingAverage50
}
lordoftrades wrote: I start to realize that the transition from VBA to C# is pretty tough
Darn tootin' I went the other way when I worked at the Uni, took me a while (well, to VB6) to wrap my head around it. The code you have looks quite procedural, my guess is it will simplify if you get the OO goodness right, but without knowing the problem domain it is hard to help.
“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)
|
|
|
|
|
Good morning Keith
I see that the sum of our problems related to the transition to/from VB6 and C# could have been eliminated if we had playd the cards correct.
I got it to work now, than you very much for taking time to help me out.
I'm now ready to paint myself into a new corner
Have a nice day
Kind regards
Espen
|
|
|
|
|
I use ExRichTextBox picw access after the value of the negative? Why is that?
The Rtf result is:
{\rtf1\ansi\ansicpg936\deff0\deflang1033\deflangfe2052{\fonttbl{\f0\fnil\fcharset0 Tahoma;}}
\viewkind4\uc1\pard\lang2052\f0\fs21{\pict\wmetafile8\picw-27521\pich502\picwgoal21552\pichgoal285
0100090000033ca00000000026a000000000050000000b0200000000050000000c02f6017f9426
a00000430f2000cc00000013009d0500000000f6017f9400000000280000009d05000013000000......
You can see the picw-27521 .Why?
|
|
|
|
|
Can you post the code behind it?
It seems like you get the raw RTF encoding instead of the RTF text.
|
|
|
|
|
StringBuilder _rtf = new StringBuilder();
int picw = (int)Math.Round((_image.Width / xDpi) * HMM_PER_INCH);
int pich = (int)Math.Round((_image.Height / yDpi) * HMM_PER_INCH);
int picwgoal = (int)Math.Round((_image.Width / xDpi) * TWIPS_PER_INCH);
int pichgoal = (int)Math.Round((_image.Height / yDpi) * TWIPS_PER_INCH);
_rtf.Append(@"{\pict\wmetafile8");
_rtf.Append(@"\picw");
_rtf.Append(picw);
_rtf.Append(@"\pich");
_rtf.Append(pich);
_rtf.Append(@"\picwgoal");
_rtf.Append(picwgoal);
_rtf.Append(@"\pichgoal");
_rtf.Append(pichgoal);
_rtf.Append(" ");
private const int MM_TEXT = 1;
private const int MM_LOMETRIC = 2;
private const int MM_HIMETRIC = 3;
private const int MM_LOENGLISH = 4;
private const int MM_HIENGLISH = 5;
private const int MM_TWIPS = 6;
private const int MM_ISOTROPIC = 7;
private const int MM_ANISOTROPIC = 8;
private const string FF_UNKNOWN = "UNKNOWN";
private const int HMM_PER_INCH = 2540;
private const int TWIPS_PER_INCH = 1440;
using (Graphics _graphics = this.CreateGraphics()) {
xDpi = _graphics.DpiX;
yDpi = _graphics.DpiY;
}
The above is code!
|
|
|
|
|
private const int MM_TEXT = 1;
private const int MM_LOMETRIC = 2;
private const int MM_HIMETRIC = 3;
private const int MM_LOENGLISH = 4;
private const int MM_HIENGLISH = 5;
private const int MM_TWIPS = 6;
private const int MM_ISOTROPIC = 7;
private const int MM_ANISOTROPIC = 8;
private const string FF_UNKNOWN = "UNKNOWN";
private const int HMM_PER_INCH = 2540;
private const int TWIPS_PER_INCH = 1440;
using (Graphics _graphics = this.CreateGraphics()) {
xDpi = _graphics.DpiX;
yDpi = _graphics.DpiY;
}
|
|
|
|
|
This is nice. But I can't see a RichTextBox anywhere in you code?
|
|
|
|
|
how to detect SoundEffect stoped in xna?
|
|
|
|
|
Hi,
i want to make setup my project in c# but i have this error
Error 27 File 'log4net.dll' targeting 'AMD64' is not compatible with the project's target platform 'x86' C:\Users\user\Documents\Visual Studio 2010\Projects\WindowsFormsApplication3\Insurance Management Setup\Insurance Management Setup\Insurance Management Setup.vdproj Insurance Management Setup
Also i want to be run the setup in 32 bit and 64 bit platform
What is the solution ??
modified 24-Apr-13 10:37am.
|
|
|
|
|
zebra88 wrote: Error 27 File 'log4net.dll' targeting 'AMD64' is not compatible with the project's target platform 'x86' C:\Users\user\Documents\Visual Studio 2010\Projects\WindowsFormsApplication3\Insurance Management Setup\Insurance Management Setup\Insurance Management Setup.vdproj Insurance Management Setup
Why this is happening is described in the error message: you are trying to deploy the AMD (AMD64) targeted dll against a Generic x86 (x86) application.
zebra88 wrote: What is the solution ??
Personally, I'd start by downloading the Log4Net Source and building alongside the app so it always builds against the same version as the app. You could also get the generic version of the dll and deploy that, but as you require 32-bit deployment as well it might get messy.
As for 32/64 bit deployment, the simplest thing to do is to set up both 32 and 64 bit versions of your build configuration and swapping to produce 32 and 64-bit versions of your MSIs. You could also consider two installer projects for each, but it depends on your circumstances. If you want a single installer where the user chooses which version as part of the installation process, then that is beyond my ken I'm afraid.
“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)
|
|
|
|
|
Hi all ,
I'm creating MVC4 controller that accepts Uri as parameter from the caller (wrapped in the AppMessage class with other info ) , this uri represents callBack link (WCF service / web page/ ) so this link is used to send the success of execution block of the controller body . I want the client to be notified so he can perform some acts when this confirmation is recieved by the requested uri .
public class AppMessage
{
public Uri CallbackUri { get; set; }
public string data1 {get;set;} ....
}
and the controller looks like
public ActionResult Send(AppMessage message)
{
NotifyByURi(message.Uri)
}
I would love to hear what is the best way to implement such thing (Web service deuplix communication / SignalR .... what else ?)
|
|
|
|
|
Has anyone done any programming around a Symbol Scanner, specifically an LS4208? What I am looking to do is remotely program the scanner so our system techs won't have to use the paper guide to program them. I have the SDK, and have a ruff idea about how to do it. However, I can't seem to find the attribute to set the scanner to USB IBM Hand-held. Does anyone happen to know which attribute this is?
Thanks,
|
|
|
|
|
Your best bet is to ask this question on the support forums for that product. It's highly unlikely that anyone here just happens to have knowledge of that particular product in that level of detail.
|
|
|
|
|
I've worked with Symbol scanners, but don't remember the specifics you are talking about. All I can say is to check the SDK docs (since contacting Motorola generally gets you nowhere.) One my former employers, Wavelink, makes awesome software to do what you want.
|
|
|
|
|
Im trying to create a program where there are two files for two separate classes.. after the user enters the course they want to show the grades and students name of the program searches through that file and gets all the students averages for each category then prints the final grade at the end. Right now I'm getting an error for "unexpected symbol public"on line 17 and "unexpected symbol }" at line 101
using System;
using System.IO;
namespace IntroCS
{
class GradeFiles
{
public static void Main(string[] args)
{
public static int codeIndex(string code, string[] categories)
{
string fileName = UIF.PromptLine ("Please enter the comp course with no spaces: ");
string categoryFileName = "categories_" + fileName + ".txt";
var reader = new StreamReader (categoryFileName);
string input = reader.ReadLine ();
string[] category = input.Split (',');
for (int i = 0; i < category.Length; i++)
category [i] = category [i].Trim ();
input = reader.ReadLine ();
string[] weights = input.Split (',');
for (i = 0; i < weights.Length; i++)
weights [i] = weights [i].Trim ();
input = reader.ReadLine ();
string[] number = input.Split (',');
for (i = 0; i < number.Length; i++)
number [i] = number [i].Trim ();
string studentFileName = "students_" + fileName + ".txt";
var reader2 = new StreamReader (studentFileName);
while (!reader2.EndOfStream) {
string student = reader2.ReadLine ();
int[] totalGrade = new int[category.Length];
string [] studentData = student.Split (',');
string studentFile = ("studentData[0]" + fileName + ".data");
var reader3 = new StreamReader (studentFile);
}
while (!reader3.EndOfStream) {
string grade = reader3.ReadLine ();
string [] gradeValue = grade.Split (',');
}
for (int i = 0; i < category.Length; i++) {
if (category [i].Trim ().StartsWith (code)) {
return i;
}
}
return -1;
{
int totalGrade = 0;
for (int i = 0; i < totalGrade.Length; i++){
totalGrade[i] = totalGrade[i]/number[i]*weights[i];
}
{
int totalGradeScore = 0;
int weightScore = 0;
for (int i = 0; i < totalGrade.Length; i++){
totalGradeScore += totalGrade [i];
weightScore += weights [i];
}
int avg;
avg = totalGradeScore/weightScore;
//writer.WriteLine avg = totalGradeScore/weightScore;
writer.WriteLine(avg);
writer.Close();
return avg;
}
}
}
}}}
|
|
|
|
|
1 using System;
2 using System.IO;
3
4 namespace IntroCS
5 {
6 class GradeFiles
7 {
8
9 public static void Main(string[] args)
10 {
11
12
13
14
15
16
17 public static int codeIndex(string code, string[] categories)
18 {
You've declare a method on line 9, it's body starting on line 10. Line 17 is a new method; you can't put a method in another method. Put a "}" on line 12, and call your method on line 11
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
1. class a{
public int add(int x)
{
return x;
}
}
2. class b {
public double add(int x, int y, int z)
{
return x+y+z;
}
}
m little confused about overriding and overloading
can anyone tells wht happn in the above methods is it overloading or overriding????
|
|
|
|
|
Arun kumar Gautam wrote: it overloading or overriding????
According to the code you have neither.
Polymorphism (search for overridden methods)[^]
Overloading[^]
The first would require one class to subclass and have a method with the same name AND input parameters (and the virtual/override keywords in c#). The second requires two methods with the same name but different input parameters (these can be in the same class or inheritance hierarchy). If b subclassed a or vice versa add would be overloaded, but there would be no overriding.
Perhaps you copied the code from the question down incorrectly?
“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)
|
|
|
|
|
Override is when a class will "override" or implement it's own version of a method in a parent class.
Overload is when the same named function has different signatures. In your example, if both add functions were in the same class it would be overloaded.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
|
but according to the concept of overloading the number of parameters and data type of parameters in two functions must have to be different
and according to the concept of overriding the number of parameters and datatype of parameters must have to be same in two functions
so i think if the number of parameters and data type of parameters are different of two functions than it must be the overloading so it doesnt matter whether these two function are in same class or in derived class
|
|
|
|
|
Arun kumar Gautam wrote: but according to the concept of overloading the number of parameters and / or data type of parameters in two functions must have to be different
You've missed other important characteristics: The method must be have the same name (for both overloading and overriding).
Overloading happen when you have methods with different parameters, with or without a subclass/superclass but both methods need to be in the same class hierarchy (including the same class - which has a hierarchy of 1). Neither of your add methods do this as they they are in unrelated classes, so you don't have overloading.
Overriding requires class hierarchy where a method supersedes (overrides) it's equivalent (i.e. having same name, parameters) in class higher up in the hierarchy. As you don't have any subclassing/super classing you can't have overriding in your example.
So that takes us back to your original question. Either you have copied the code across incorrectly, or the questioner doesn't know what they are doing/has made a mistake (which is a real possibility, I'm not being facetious).
“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)
|
|
|
|
|