Please help code Price/EMA crossover cBot
Please help code Price/EMA crossover cBot
02 May 2013, 15:00
Hi, I am not a programmer in the least so can someone please post some code that creates a cBot which does the following:
1] Using data from the daily chart (or whichever time frame is defined);
2] When price crosses (above/below) the 50 period exponential moving average;
3] The cBot risk 1% of account balance to go long/short the equivelent amount of currency (NO stop loss orders are used in this "system").
4] Hence, the cBot would constantly have open positions in the market - e.g., when price crosses above the 50 EMA it buys, and when it crosses below it closes the existing long position, and goes short instead.
5] After a losing trade the cBot risks 2x the lots of the previous trade (Martingale) - e.g. if previous losing trade had 10,000 lots, the current trade would risk 20,000.
6] When a winning trade is reached at some point in the future the cBot goes back to risking 1%.
Also...Line-by-line annotations of what each line of code does are welcome! ;c) he he he...
I am very aware that this "system" does NOT make money (and does a very good job of losing it - especially in trendless environments), but I am trying to learn the basics of coding cBots in C#, and my programing skills are below novice level.
Much appreciate any help!
Replies
cAlgo_Fanatic
10 May 2013, 12:46
We will upload a robot for you based on your description in the Robots section.
Before we do this we need you to clarify your definition of Risk: "The cBot risk 1% of account balance to go long/short the equivelent amount of currency (NO stop loss orders are used in this "system"). "
You cannot have a risk 1% of account balance without stop loss or stop out.
@cAlgo_Fanatic
RaphBok
10 May 2013, 15:07
RE:
We will upload a robot for you based on your description in the Robots section.
Before we do this we need you to clarify your definition of Risk: "The cBot risk 1% of account balance to go long/short the equivelent amount of currency (NO stop loss orders are used in this "system"). "
You cannot have a risk 1% of account balance without stop loss or stop out.
Wow, this is GREAT news! =c) Thanks guys! This will really help me learn the cAlgo API as I have a very beginner level knowlege of C# anyway.
About the stop loss issue... I would prefer the cBot to auto set the stop loss 15 pips away from the fill price (so however many lots it would take to equal 1% of account balance). Also, a dropdown box in the left side panel that allows for the changing of stop loss size, and initial % risk size would be appreciated. Again, any useful annotations in the code would be much appreciated as well!
@RaphBok
tradermatrix
10 May 2013, 21:07
We can also (forum) enjoy this robot?
it would be useful to help us improve our understanding ...
cordially.
@tradermatrix
cAlgo_Fanatic
17 May 2013, 17:41
Hello,
The cBot has been uploaded here: /algos/robots/show/271
@cAlgo_Fanatic
RaphBok
17 May 2013, 21:56
RE:
Hello,
The cBot has been uploaded here: /algos/robots/show/271
Great! Thank you so much guys! I appreciate it =)
@RaphBok
RaphBok
18 May 2013, 08:45
RE:
We will upload a robot for you based on your description in the Robots section.
Before we do this we need you to clarify your definition of Risk: "The cBot risk 1% of account balance to go long/short the equivelent amount of currency (NO stop loss orders are used in this "system").
You cannot have a risk 1% of account balance without stop loss or stop out.
Hey, I have a question about the "...cannot have a risk 1%... without stop loss..." part... is it because of margin requirements (I assume), or because it cannot be coded in cAlgo - or perhaps, both? Thanks!
@RaphBok
cAlgo_Fanatic
20 May 2013, 09:17
It is by definition of risking a percent of your balance. If you only risk a certain percentage of your balance then you need to set stop loss. Otherwise you are risking 100%.
@cAlgo_Fanatic
RaphBok
24 May 2013, 12:13
RE:
Hello,
The cBot has been uploaded here: /algos/robots/show/271
Hi again. Can you please give me a parameter mod for this code that allows the user to choose between "long-only", "short-only", and "default (both)" types of positions using a drop down box (left panel section where currency pairs are added as an instance). I have only been able to partly figure out how to code this... I think =(
@RaphBok
cAlgo_Fanatic
24 May 2013, 12:17
You can use an integer (int) Value 0 for Long and 1 for Short for example and set the Min/Max Values.
[Parameter("0-Buy, 1-Sell", DefaultValue = 0, MinValue = 0, MaxValue = 1)] public int Mode { get; set; }
@cAlgo_Fanatic
RaphBok
24 May 2013, 22:10
RE:
You can use an integer (int) Value 0 for Long and 1 for Short for example and set the Min/Max Values.
[Parameter("0-Buy, 1-Sell", DefaultValue = 0, MinValue = 0, MaxValue = 1)] public int Mode { get; set; }
Thanks for the code, but I did sort of arrive at a similar workaround for the drop down box. The main issue I was having was "querying the attribute" (hopefully I'm using the terminology in correctly, lol) later on in the code. For example, the cBot skips all short selling signals, and only enters and exits long positions. I'm trying something like this in the properties section of the code:
protected int LongShortOnly
{
get { return Mode; }
}
@RaphBok
cAlgo_Fanatic
27 May 2013, 12:01
Well, the syntax for the property is correct, even though a little redundant. It will just return the value of Mode.
You could write a property like this instead:
protected bool LongOnly { get { return Mode == 0; } }
@cAlgo_Fanatic
RaphBok
27 May 2013, 16:06
RE:
Well, the syntax for the property is correct, even though a little redundant. It will just return the value of Mode.
You could write a property like this instead:
protected bool LongOnly { get { return Mode == 0; } }
Hmm... okay, well that solved the error message (says, "Build Succeeded" now), but its not working as it should. I made a property for each scenario ("LongOnly", and "ShortOnly"), and placed it in the properties section of the code right after "Current bar index", and also tried to "call the property" (if that's even possible, or correct?) using the code below, but I think that is where the problem is. Does it have to be "initialized"? Anyway, can you PLEASE reformat the cBot, and paste full code here? I'm confuuuused, and will never figure it out on my own =| THANKS!
protected int Shorts
{
get { return Mode - 1; }
}
@RaphBok
RaphBok
29 May 2013, 05:55
RE: RE:
Hmm... okay, well that solved the error message (says, "Build Succeeded" now), but its not working as it should. I made a property for each scenario ("LongOnly", and "ShortOnly"), and placed it in the properties section of the code right after "Current bar index", and also tried to "call the property" (if that's even possible, or correct?) using the code below, but I think that is where the problem is. Does it have to be "initialized"? Anyway, can you PLEASE reformat the cBot, and paste full code here? I'm confuuuused, and will never figure it out on my own =| THANKS!protected int Shorts
{
get { return Mode - 1; }
}
Any updates on this request? I would greatly appreciate it. LAST time I bug you guys for code - I promise! ;c)
@RaphBok
cAlgo_Fanatic
29 May 2013, 15:12
It is unclear what you need. If you use this property:
protected bool LongOnly { get { return Mode == 0; } }
To identify if the input is set for long only signals, then you would use an if statement somewhere in the OnTick() method:
if(LongOnly) { //... }
@cAlgo_Fanatic
RaphBok
29 May 2013, 20:34
RE:
It is unclear what you need. If you use this property:
protected bool LongOnly { get { return Mode == 0; } }To identify if the input is set for long only signals, then you would use an if statement somewhere in the OnTick() method:
if(LongOnly) { //... }
That did the trick! Thank you.
@RaphBok
DomnikInvest
01 Aug 2013, 18:28
RE:
Hello,
The cBot has been uploaded here: /algos/robots/show/271
This link don't work!?
@DomnikInvest
ctid299233
22 Feb 2017, 23:32
Any update on a working link please?
This one is a 404 not found: /algos/robots/show/271
Thanks!
@ctid299233
hichem
02 May 2013, 16:02
RE:
Hello,
You can go through the tutorials and the sample robots delivered with cAlgo.
There many examples from which you can learn.
@hichem