how fix expert CCI
how fix expert CCI
26 Jun 2014, 09:08
hi,,
i want learn calgo
and i try this cod
bool isLongPositionOpen = positionBuy != null && positionBuy.TradeType == TradeType.Buy;
bool isShortPositionOpen = positionSell != null && positionSell.TradeType == TradeType.Sell;if (_cci.Result.HasCrossedBelow(0.0, 1) && !isShortPositionOpen)
{
var result = ExecuteMarketOrder(TradeType.Sell, Symbol, GetVolume, "SELLCCI", StopLoss, TakeProfit);positionSell = result.Position;
}
else if (_cci.Result.HasCrossedAbove(0.0, 1) && !isLongPositionOpen)
{
var result2 = ExecuteMarketOrder(TradeType.Buy, Symbol, GetVolume, "BUYCCI", StopLoss, TakeProfit);
positionBuy = result2.Position;
}
i want if cci up 0 and close candle index 1 open buy
like this in mql4 :
double CCI = iCCI(Symbol(),0,20,0,1);
double CCI2 = iCCI(Symbol(),0,20,0,2);
if(CCI2 < 0 && CCI > 0)
{
Comment("BUY");
}
if(CCI2 > 0 && CCI < 0)Comment("SELL");
thank you
Replies
breakermind
27 Jun 2014, 09:03
( Updated at: 21 Dec 2023, 09:20 )
RE:
Hi,
search solutions do not expect the final solution - if you want to learn
Check line by line why conditions dont work and use Print("CCI1 " + _cci + "" + ...)
search robot which already works and compare :)
but working! conditions check it alone:
cBots is a waste of time ... :)
Regards
@breakermind
breakermind
27 Jun 2014, 13:26
RE:
Invalid said:
Why not to use VS instead of Print?
Not everyone needs to know what is VS, and second for what everything is ok in calgo debugger if you can read and think ;)
@breakermind
RootFX
29 Jun 2014, 00:42
( Updated at: 21 Dec 2023, 09:20 )
RE: RE:
breakermind said:
Hi,
search solutions do not expect the final solution - if you want to learn
Check line by line why conditions dont work and use Print("CCI1 " + _cci + "" + ...)
search robot which already works and compare :)but working! conditions check it alone:
cBots is a waste of time ... :)
Regards
thank you breakermind
i will try this after open market
thank you again :)
@RootFX
RootFX
30 Jun 2014, 03:33
( Updated at: 21 Dec 2023, 09:20 )
hi i try this
and show this result
and i change
_cci = Indicators.CommodityChannelIndex(Periods);
i set this in method onBar()
and show this result
I do not know where is the problem !!!
in MQL4 it's very easy but in calgo I do not understand the problem
this expert :
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)] public class z_cci : Robot { [Parameter("Volume", DefaultValue = 10000)] public int Volume { get; set; } [Parameter("Periods", DefaultValue = 20, MinValue = 1)] public int Periods { get; set; } [Parameter("Label", DefaultValue = "labelname")] public string label { get; set; } [Parameter("TP", DefaultValue = 50, MinValue = 10)] public int TP { get; set; } [Parameter("SL", DefaultValue = 0, MinValue = 0)] public int SL { get; set; } private CommodityChannelIndex _cci; private Position _position; protected override void OnStart() { _cci = Indicators.CommodityChannelIndex(Periods); } protected override void OnBar() { // _cci = Indicators.CommodityChannelIndex(Periods); _position = Positions.Find(label); bool isLongPositionOpen = _position != null && _position.TradeType == TradeType.Buy; bool isShortPositionOpen = _position != null && _position.TradeType == TradeType.Sell; Print("CCI ===> "+ _cci.Result.LastValue ); if (_cci.Result.HasCrossedAbove(0.0, 2) && _cci.Result.HasCrossedBelow(0.0, 1) && !isShortPositionOpen) { ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, label, SL, TP); } if (_cci.Result.HasCrossedBelow(0.0, 2) && _cci.Result.HasCrossedAbove(0.0, 1) && !isLongPositionOpen) { ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, label, SL, TP); } } protected override void OnStop() { // Put your deinitialization logic here } } }
any body can fix this expert and show what problem
thank you
@RootFX
RootFX
01 Jul 2014, 04:10
i try this and it's Work 100% :)
protected override void OnBar() { // Put your core logic here bool isLongPositionOpen = pos != null && pos.TradeType == TradeType.Buy; bool isShortPositionOpen = pos != null && pos.TradeType == TradeType.Sell; if (cci.Result.Last(2) < 0 && cci.Result.Last(1) > 0 && !isLongPositionOpen) { var result = ExecuteMarketOrder(TradeType.Buy, Symbol, GetVolume, Label, StopLoss, TakeProfit); pos = result.Position; } else if (cci.Result.Last(2) > 0 && cci.Result.Last(1) < 0 && !isShortPositionOpen) { var result = ExecuteMarketOrder(TradeType.Sell, Symbol, GetVolume, Label, StopLoss, TakeProfit); pos = result.Position; } }
thank you
@RootFX
breakermind
26 Jun 2014, 23:31
RE:
Hi,
try like this:
i dont test it :)
Bye
@breakermind