MI
Topics
19 Oct 2012, 19:21
3933
4
18 Sep 2012, 14:27
4965
7
11 Sep 2012, 18:59
5216
5
07 Sep 2012, 12:27
3921
3
05 Sep 2012, 17:53
6569
6
31 Aug 2012, 16:32
3991
5
Replies
misado
20 Sep 2012, 16:17
I've changed it but still have error 11!
// // The "Sample CCI Robot" will create a buy order when the Commodity Channel Index indicator crosses the level 1, // and a Sell order when the CCI indicator crosses the level -1. The order is closed be either a Stop Loss, defined in // the "Stop Loss" parameter, or by the opposite CCI crossing signal (buy orders close when CCI crosses the -1 level // and sell orders are closed when CCI crosses the 1 level). // // The robot can generate only one Buy or Sell order at any given time. // // ------------------------------------------------------------------------------------------------- using System; using cAlgo.API; using cAlgo.API.Indicators; namespace cAlgo.Robots { [Robot] public class CCIRobot : Robot { [Parameter("Source")] public DataSeries Source { get; set; } [Parameter("Periods", DefaultValue = 21)] public int Periods { get; set; } [Parameter("Stop Loss (pips)", DefaultValue = 10)] public int StopLoss { get; set; } [Parameter("Volume", DefaultValue = 10000, MinValue = 0)] public int Volume { get; set; } private Position position; private CommodityChannelIndex cci; protected override void OnStart() { cci = Indicators.CommodityChannelIndex(Periods); } protected override void OnTick() { if (Trade.IsExecuting) return; if (cci.Result.LastValue > 1 && (_position == null || _position.TradeType == TradeType.Sell)) { OpenPosition(TradeType.Buy); } if (cci.Result.LastValue < -1 && (_position == null || _position.TradeType == TradeType.Buy)) { OpenPosition(TradeType.Sell); } } private void OpenPosition(TradeType command) { if (position != null) { Trade.Close(position); position = null; } Trade.CreateMarketOrder(command, Symbol, Volume); } protected override void OnPositionOpened(Position openedPosition) { position = openedPosition; Trade.ModifyPosition(openedPosition, GetAbsoluteStopLoss(openedPosition, StopLoss), 1); } { position = openedPosition; Trade.ModifyPosition(openedPosition, GetAbsoluteStopLoss(openedPosition, StopLoss), -1); } private double GetAbsoluteStopLoss(Position position, int stopLossInPips) { return position.TradeType == TradeType.Buy ? position.EntryPrice - Symbol.PipSize * stopLossInPips : position.EntryPrice + Symbol.PipSize * stopLossInPips; } } }
@misado
misado
05 Sep 2012, 12:14
Hi
thanks a lot for your fast and good support.
First item why calgo works so slowly: "How many instances of indicator/robots have you got opened at the same time?" - Exactly that was the problem, now its solved and calgo works absolutely perfect.
Second item: The double indi works fine and the logic behind seems to me much more easiert than mt4.
Another question:
I've downloaded the indi "AdaptiveCG" but I can't compile it, so it doesn't work!?
@misado
misado
26 Oct 2012, 11:39
2 solutions
Hi,
a mon avis there are 2 solutions to get right results:
What do you mean?
And as general question:
what is the best size for this system? 5 pips for SL/TP or 10, 50...?
Mike
@misado