Who can code this please?
Created at 29 Oct 2013, 13:30
Who can code this please?
29 Oct 2013, 13:30
I am a new user of cAlgo trading platform and will like to begin by using a simple robot to trade my new account.
I'll appreciate if an experienced cAlgo coder can help me in writing for this simple strategy:
1. When the current price is higher than the previous one i.e IsRising;
2. And price is greater than or equal to EMA(2) i.e 2 period exponential moving average;
3. And spread is less than 5.0;
4. Place a market order of 2 standard lots with stop loss set at -20 and take profit set at +20
Thanks.
cAlgoFx
29 Oct 2013, 15:57
//Robot by cAlgoFx//
///////////////////
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Requests;
using cAlgo.Indicators;
using System.Linq;
namespace cAlgo.Robots
{
[Robot()]
public class EMA2 : Robot
{
[Parameter(DefaultValue = 20000, MinValue = 10000)]
public int Volume { get; set; }
[Parameter("Code", DefaultValue = 555, MinValue = 555)]
public int code { get; set; }
private Position position;
private MovingAverage _ema2;
protected override void OnStart()
{
_ema2 = Indicators.MovingAverage(MarketSeries.Close, 2, MovingAverageType.Exponential);
}
protected override void OnBar()
{
var count_pos = Account.Positions.Count(position => position.Label == code.ToString() && position.SymbolCode == Symbol.Code);
bool buy = MarketSeries.Close.IsRising() && MarketSeries.Close.LastValue >= _ema2.Result.LastValue;
bool sell = MarketSeries.Close.IsFalling() && MarketSeries.Close.LastValue <= _ema2.Result.LastValue;
if (count_pos < 1 && Symbol.Spread < 5)
{
if (buy)
{
var request = new MarketOrderRequest(TradeType.Buy, Volume)
{
Label = code.ToString(),
SlippagePips = 5,
StopLossPips = 20,
TakeProfitPips = 20
};
Trade.Send(request);
}
else if (sell)
{
var request = new MarketOrderRequest(TradeType.Sell, Volume)
{
Label = code.ToString(),
SlippagePips = 5,
StopLossPips = 20,
TakeProfitPips = 20
};
Trade.Send(request);
}
}
}
}
}
@cAlgoFx