Topics
Replies
Kevin
09 Dec 2013, 00:02
Adding "using System" solves the problem with the buy order, but another fault comes up with the sell order:
private void Sell()
{
DateTime expiry = Server.Time.AddMinutes(5);
PlaceLimitOrder(TradeType.Sell, Symbol, 10000, Symbol.Sell + 0.5 * Symbol.PipSize, null, null, null, expiry);
}
Error: 'cAlgo.API.Internals.Symbol' does not contain a definition for 'Sell" and no extension method 'Sell" accepting a first arguement or type 'cAlgo.API.Internals.Symbol' could not be found (are you missing a using directive o...
@Kevin
Kevin
06 Dec 2013, 01:39
Hi, thanks for that :) Yes much adjustent needed *fingers-crossed*.
I also want a similar robot that places trades based on the crossover of MacD and Signal lines, relative to each other. If the histo crosses above signal, buy. If it crosses down, sell. Simples. But I can't find anything on here. I found the HasCrossedBelow function but am not having much luck with it :(
Any help would be much appreciated and thanks again for the above.
@Kevin
Kevin
05 Dec 2013, 22:08
C# is completely new to me (how i've managed to get this far is a wonder). So could you write this for me pleeeeeeease :D
My total code at the moment is:
using cAlgo.API;
using cAlgo.API.Indicators;
namespace cAlgo.Robots
{
[Robot()]
public class 30k : Robot
{
private MacdHistogram _macd;
private Position _position;
[Parameter(DefaultValue = 30000, MinValue = 0)]
public int Volume { get; set; }
[Parameter("Period", DefaultValue = 12)]
public int Period { get; set; }
[Parameter("Long Cycle", DefaultValue = 22)]
public int LongCycle { get; set; }
[Parameter("Short Cycle", DefaultValue = 9)]
public int ShortCycle { get; set; }
protected override void OnStart()
{
_macd = Indicators.MacdHistogram(LongCycle, ShortCycle, Period);
}
protected override void OnBar()
{
if (Trade.IsExecuting)
return;
bool isLongPositionOpen = _position != null && _position.TradeType == TradeType.Buy;
bool isShortPositionOpen = _position != null && _position.TradeType == TradeType.Sell;
if (_macd.Histogram.LastValue > 0.0 && _macd.Signal.IsRising() && !isLongPositionOpen)
{
ClosePosition();
Buy();
}
if (_macd.Histogram.LastValue < 0.0 && _macd.Signal.IsFalling() && !isShortPositionOpen)
{
ClosePosition();
Sell();
}
}
private void ClosePosition()
{
if (_position != null)
{
Trade.Close(_position);
_position = null;
}
}
private void Buy()
{
Trade.CreateBuyMarketOrder(Symbol, Volume);
}
private void Sell()
{
Trade.CreateSellMarketOrder(Symbol, Volume);
}
protected override void OnTick()
{
foreach (var position in Account.Positions)
{
if (position.GrossProfit >= 24)
{
Trade.Close(position);
}
}
}
}
}
@Kevin
Kevin
05 Dec 2013, 20:13
Awesome, thanks! :D
I noticed you replied to my other post too and I have a similar problem with this in that I don't know how to add it to the code I already have.
Also, I can change the email address as that is quite clear, but where do I edit/add the account balance or percentage?
@Kevin
Kevin
05 Dec 2013, 20:09
I saw that (or something similar) but don't know how to introduce that to my code:
protected override void OnBar()
{
if (Trade.IsExecuting)
return;
bool isLongPositionOpen = _position != null && _position.TradeType == TradeType.Buy;
bool isShortPositionOpen = _position != null && _position.TradeType == TradeType.Sell;
if (_macd.Histogram.LastValue > 0.0 && _macd.Signal.IsRising() && !isLongPositionOpen)
{
ClosePosition();
Buy();
}
if (_macd.Histogram.LastValue < 0.0 && _macd.Signal.IsFalling() && !isShortPositionOpen)
{
ClosePosition();
Sell();
}
}
private void ClosePosition()
{
if (_position != null)
{
Trade.Close(_position);
_position = null;
}
}
private void Buy()
{
Trade.CreateBuyMarketOrder(Symbol, Volume);
}
private void Sell()
{
Trade.CreateSellMarketOrder(Symbol, Volume);
}
protected override void OnTick()
{
foreach (var position in Account.Positions)
{
if (position.GrossProfit >= 9)
{
Trade.Close(position);
}
}
}
}
}
@Kevin
Kevin
20 Apr 2015, 20:22
Thank you so much, this will be a great help! :D
@Kevin