Need Help For Developing My Own cBo
Need Help For Developing My Own cBo
25 Apr 2016, 23:01
Hello,
i'm developing my first cBot..later i found that my cBot can be run in cAlgo but didnt take any position in backtesting..in the log showing "23/03/2016 12:00:03.079 | Crashed in OnTick with NullReferenceException: Object reference not set to an instance of an object."
Kindly tell me how to solve this problem. Thanks in advance.
Replies
Spotware
26 Apr 2016, 16:46
Dear Trader,
Please take a look at the following article from Microsoft regarding NullReferenceExceptions: https://msdn.microsoft.com/en-us/library/system.nullreferenceexception(v=vs.110).aspx
Please note that we do not provide coding assistance services. We more than happy to assist you with specific questions about cAlgo.API. You also can contact one of our Partners or post a job in Development Jobs section for further coding assistance.
@Spotware
BlowMe
25 Apr 2016, 23:03
My Void OnTick() Content
protected override void OnTick()
{
double Bid = Symbol.Bid;
double Ask = Symbol.Ask;
double Point = Symbol.TickSize;
if (rsi.Result.Last(0) > rsi.Result.Last(3))
{
if (EMA.Result.Last(0) > EMA.Result.Last(3) && EMA.Result.Last(0) > EMA.Result.Last(5))
{
if (_macd.Histogram.LastValue > 0.0 && _macd.Signal.IsRising() && _macd.Histogram.IsRising())
{
Close(TradeType.Sell);
Open(TradeType.Buy);
}
}
}
else if (rsi.Result.Last(0) < rsi.Result.Last(3))
{
if (EMA.Result.Last(0) < EMA.Result.Last(3) && EMA.Result.Last(0) < EMA.Result.Last(5))
{
if (_macd.Histogram.LastValue < 0.0 && _macd.Signal.IsFalling() && _macd.Histogram.IsFalling())
{
Close(TradeType.Buy);
Open(TradeType.Sell);
}
}
}
foreach (var position in Positions)
{
if (position.SymbolCode == Symbol.Code)
{
if (position.TradeType == TradeType.Buy)
{
if (position.Pips > target)
{
ModifyPosition(position, Bid - Tral_Stop * Point, position.TakeProfit);
if (LastResult.IsSuccessful)
Print("Modified Buy", Symbol);
}
}
if (position.TradeType == TradeType.Sell)
{
if (position.Pips > target)
{
ModifyPosition(position, Ask + Tral_Stop * Point, position.TakeProfit);
if (LastResult.IsSuccessful)
Print("Modified Sell", Symbol);
}
}
}
}
}
@BlowMe