Why Order failed with Error "Technical Error" ?

Created at 20 Feb 2020, 20:56
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
CA

capt.ichimuko

Joined 18.02.2020

Why Order failed with Error "Technical Error" ?
20 Feb 2020, 20:56


hi sir, please help me understand why some order failed with error technical, and other order successful. here i attached screenshot and code for my Cbot. please help me to resolve the issue. thanks.

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

/*
+---------------------------------------------------------------------------------------------------------------------------------+
| I recommend using this Cbot on Renko charts with 10 pips brick size for the following pairs only.	|
| EURUSD, GBPUSD, AUDUSD, USDJPY, EURJPY, GBPJPY, USDCHF & USDCAD		|
| LEXtrend Cbot has a knack of catching the trend and letting it run and cutting short its loser’s.	|
+---------------------------------------------------------------------------------------------------------------------------------+
*/

namespace cAlgo
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class LEXtrend : Robot
{
#region User defined parameters
public enum Instance { Fiber_EU, Cable_GU, Aussei_AU, Ninja_UJ, Yuppy_EJ, Guppy_GJ, Swissie_UF, Loonie_UC }

[Parameter("Instance Name", DefaultValue = " Fiber_EU")]
 public Instance InstanceName { get; set; }

[Parameter("LEX Period", DefaultValue = 14, MinValue = 7, MaxValue = 55)]
public int Period { get; set; }

[Parameter("LEX Threshold", DefaultValue = 17, MinValue = 10, MaxValue = 40)]
public int Threshold { get; set; }

[Parameter("LEX Extent", DefaultValue = 45, MinValue = 40, MaxValue = 100)]
public int Termination { get; set; }

[Parameter("Use Percentage Risk ?", Group = "Money Management", DefaultValue = true)]
public bool volPercentBool { get; set; }

[Parameter("Risk %", Group = "Money Management", DefaultValue = 1.5, MinValue = 1, Step = 0.1)]
public int volPercent { get; set; }

[Parameter("Volume Quantity", Group = "Money Management", DefaultValue = 2000, MinValue = 1000, Step = 1000)]
public int volQty { get; set; }

[Parameter("StopLoss Pips", Group = "Protection", DefaultValue = 20.0, Step = 1.0)]
public double StopLoss { get; set; }

[Parameter ("Risk Reward Ratio", Group = "Protection", DefaultValue = 7, MinValue = 2)]
public double Reward { get; set; }

[Parameter ("BreakEvenTrigger Pips", Group = "Protection", DefaultValue = 20, MinValue = 1)]
public double TriggerPips { get; set; }

[Parameter ("Locked in Profit", Group = "Protection", DefaultValue = 3.0, MinValue = 0.0)]
public double AddPips { get; set; }

[Parameter("Allowable Slippage", Group = "Filter", DefaultValue = 1.0, MinValue = 0.5, Step = 0.1)]
public double Slippage { get; set; }

[Parameter("Max Allowable Spread", Group = "Filter", DefaultValue = 2.0, MinValue = 0.1, MaxValue = 5.0)]
public double MaxSpread { get; set; }

[Parameter("Calculate OnBar ?", DefaultValue = true)]
public bool CalculateOnBar { get; set; }
#endregion

#region Indicator declarations
  private int volume;
  private IchimokuKinkoHyo Ichimoku;
  private DirectionalMovementSystem dms;
  private string Comment;
#endregion



#region Calculate Volume
private int CalculateVolume(double stopLossPips)
{
int result;
switch (volPercentBool)
{
case true:
double costPerPip = (double)((int)(Symbol.PipValue * 10000000)) / 100;
double posSizeForRisk = (Account.Balance * volPercent / 100) / (stopLossPips * costPerPip);
double posSizeToVol = (Math.Round(posSizeForRisk, 2) * 100000);
Print("costperppip = {0}, posSizeFoprRisk = {1}, posSizeLotsToVol = {2}", costPerPip, posSizeForRisk, posSizeToVol);
result = (int)Symbol.NormalizeVolumeInUnits(posSizeToVol, RoundingMode.ToNearest);
result = result > 150000 ? 150000 : result;
Print("{0}% of Account Balance used for Volume! Volume equals {1}", volPercent, result);
break;
default:
result = volQty;
Print("Volume Quantity Used! Volume equals {0}", result);
break;
}
return result;
}
#endregion

#region Standard event handlers
/// This is called when the robot first starts, it is only called once.
protected override void OnStart()
{
Ichimoku= Indicators.IchimokuKinkoHyo(9, 26, 52);
dms = Indicators.DirectionalMovementSystem (Period);
volume = CalculateVolume(StopLoss);
Comment = "Christopher G’Neil" ;
}

/// This event handler is called every tick or every time the price changes for the symbol.
protected override void OnTick()
{
if (CalculateOnBar)
{return;}
ManagePositions();

var positions = Positions.FindAll(InstanceName.ToString(), SymbolName);
foreach (var position in positions) 

if (position.Pips < TriggerPips)
{return; }
BreakEvenIfNeeded();
}

/// a special event handler that is called each time a new bar is drawn on chart.
/// if you want your robot to act only when the previous bar is closed, this standard handler is where you put your main trading code.
protected override void OnBar()
{
if (!CalculateOnBar)
{return;}
ManagePositions();

var positions = Positions.FindAll(InstanceName.ToString(), SymbolName);
foreach (var position in positions) 

if (position.Pips < TriggerPips)
{return; }
BreakEvenIfNeeded();
}

/// a handler that is called on stopping the cBot.
protected override void OnStop()
{
// unused
}

/// a special Robot class member that handles situations with errors.
protected override void OnError(Error error)
{Print("Error Code {0}", error.Code);}
#endregion

#region Position management

private void ManagePositions()
{
/// if there is no buy position open, open one and close any sell position that is open
if (!IsPositionOpenByType(TradeType.Buy))
{
if (Symbol.Spread < MaxSpread &&
Bars.ClosePrices.LastValue > Bars.OpenPrices.LastValue && Bars.ClosePrices.LastValue > Ichimoku.KijunSen.LastValue && dms.DIPlus.LastValue > dms.DIMinus.LastValue && dms.ADX.LastValue >= Threshold && dms.ADX.LastValue <= Termination)
{   OpenPosition(TradeType.Buy);   }

if ( (Bars.ClosePrices.Last(2) > Bars.OpenPrices.Last(2) && Bars.ClosePrices.Last(1) > Bars.OpenPrices.Last(1)) ||
( dms.ADX.LastValue > Termination && Bars.ClosePrices.Last(1) > Bars.OpenPrices.Last(1)) )
{   ClosePosition(TradeType.Sell);  }
}

/// if there is no sell position open, open one and close any buy position that is open
if (!IsPositionOpenByType(TradeType.Sell))
{
if (Symbol.Spread < MaxSpread &&
Bars.ClosePrices.LastValue < Bars.OpenPrices.LastValue && Bars.ClosePrices.LastValue < Ichimoku.KijunSen.LastValue && dms.DIPlus.LastValue < dms.DIMinus.LastValue && dms.ADX.LastValue >= Threshold && dms.ADX.LastValue <= Termination)
{  OpenPosition(TradeType.Sell);   }

if ( (Bars.ClosePrices.Last(2) < Bars.OpenPrices.Last(2) && Bars.ClosePrices.Last(1) < Bars.OpenPrices.Last(1)) ||
( dms.ADX.LastValue > Termination && Bars.ClosePrices.Last(1) < Bars.OpenPrices.Last(1)) )
{  ClosePosition(TradeType.Buy);  }
}
}

/// Call custom class method to move StopLoss to BreakEven
private void BreakEvenIfNeeded()
{
var positions = Positions.FindAll(InstanceName.ToString(), SymbolName);
foreach (var position in positions) 
{
var desiredNetProfitInDepositAsset = AddPips * Symbol.PipValue* position.VolumeInUnits;
var desiredGrossProfitInDepositAsset = desiredNetProfitInDepositAsset - position.Commissions *2 - position.Swap;
var quoteToDepositRate = Symbol.PipValue / Symbol.PipSize;
var priceDifference = desiredGrossProfitInDepositAsset / (position.VolumeInUnits * quoteToDepositRate);
var priceAdjustment = GetPriceAdjustmentByTradeType(position.TradeType, priceDifference);
var breakEvenLevel = position.EntryPrice + priceAdjustment;
var roundedBreakEvenLevel = RoundPrice(breakEvenLevel, position.TradeType);

ModifyPosition(position, roundedBreakEvenLevel, position.TakeProfit);
}
}

/// Call custom class method to send a market order || open a new position
private void OpenPosition(TradeType type)
{ExecuteMarketRangeOrder(type, this.Symbol.Name, volume, Slippage, Symbol.Bid,  InstanceName.ToString(), StopLoss, (StopLoss * Reward), Comment);}

/// Standard event handler that triggers upon position closing.
private void ClosePosition(TradeType type)
{
var p = Positions.Find(InstanceName.ToString(), SymbolName, type);
if (p != null)

{ClosePosition(p);}
}

/// Check for opened position
private bool IsPositionOpenByType(TradeType type)
{
var p = Positions.FindAll(InstanceName.ToString(), SymbolName, type);
if (p.Count() >= 1)

{return true;}
return false;
}

private double RoundPrice(double price, TradeType tradeType)
{
var multiplier = Math.Pow(10, Symbol.Digits);
if (tradeType == TradeType.Buy)
return Math.Ceiling(price * multiplier) / multiplier;

return Math.Floor(price * multiplier) / multiplier;
}

private static double GetPriceAdjustmentByTradeType(TradeType tradeType, double priceDifference)
{
if (tradeType == TradeType.Buy)
return priceDifference;

return - priceDifference;
}

#endregion
}
}


 

 


@capt.ichimuko
Replies

PanagiotisCharalampous
21 Feb 2020, 09:02

Hi capt.ichimuko,

This is probably caused by the market range. The orders that receive the technical error message cannot be opened with the set market range.

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

capt.ichimuko
21 Feb 2020, 10:25

thank you for the response sir. please confirm that there is no problem with the codes?


@capt.ichimuko

PanagiotisCharalampous
21 Feb 2020, 10:47

Hi capt.ichimuko,

I do not see anything else that could cause this. Thy increasing your slippage and let us know if you still experience the error.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

capt.ichimuko
21 Feb 2020, 12:55

RE:

PanagiotisCharalampous said:

Hi capt.ichimuko,

I do not see anything else that could cause this. Thy increasing your slippage and let us know if you still experience the error.

Best Regards,

Panagiotis 

Join us on Telegram

thanks for your assistance sir, okay i will increase my market range/ slippage. thank you again.


@capt.ichimuko

capt.ichimuko
21 Feb 2020, 22:06 ( Updated at: 21 Dec 2023, 09:21 )

hi sir, i have another error. i know its its about break even function. but i don't know how to correctly code it. can you please tell me how? please see attached photo. thanks.

 


@capt.ichimuko

PanagiotisCharalampous
24 Feb 2020, 08:26

Hi capt.ichimuko,

In order to help you, you need to provide us with specific steps to reproduce this message, preferably on backtesting (cBot parameters, dates etc). However if you need help with developing this cBot, it would be better to post a Job or contact a Consultant.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous