Warning mga on build results about Symbol change to SymbolName.

Created at 12 Feb 2020, 22:32
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!
TR

traderfxmaster007

Joined 09.07.2019

Warning mga on build results about Symbol change to SymbolName.
12 Feb 2020, 22:32


Hi I would like to make a simple Cbot with money management. I have zero knowledge of coding or programing. I just combined codes from other robots. I made a Cbot according to my preferred strategy although it is working well but when I click build one warning msg appears. Can anybody please help me to fix this.. thank you.

 

 

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, EURGBP |

| 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

 [Parameter("Instance Name", DefaultValue = "LEXtrend _R10")]

 public string InstanceName { get; set; }

 

[Parameter("Vol as %", DefaultValue = true)]

public bool volPercentBool { get; set; }

 

[Parameter("Risk %", DefaultValue = 2, MinValue = 1, Step = 1)]

public int volPercent { get; set; }

 

[Parameter("Vol Qty", DefaultValue = 2000, MinValue = 1000, Step = 1000)]

public int volQty { get; set; }

 

[Parameter("StopLoss Pips", DefaultValue = 23.0, Step = 0.1)]

public double StopLoss { get; set; }

 

[Parameter("Allowable Slippage", DefaultValue = 1.0, MinValue = 0.5, Step = 0.1)]

public double marketRangePips { get; set; }

 

[Parameter("Max Allowable Spread", 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 (14);

volume = CalculateVolume(StopLoss);

Comment = "Christopher GNeil" ;

}

 

/// This event handler is called every tick or every time the price changes for the symbol.

protected override void OnTick()

{

if (CalculateOnBar)

{return;}

ManagePositions();

}

 

/// 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();

}

 

/// 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.Last(1) > Bars.OpenPrices.Last(1) && Bars.ClosePrices.Last(1) > Ichimoku.KijunSen.Last(1) && dms.DIPlus.Last(1) > dms.DIMinus.Last(1) && dms.DIPlus.Last(1) > 40.0 &&

 (Bars.ClosePrices.Last(2) < Bars.OpenPrices.Last(2)    || Bars.ClosePrices.Last(2) < Ichimoku.KijunSen.Last(2) ||   dms.DIPlus.Last(2) < dms.DIMinus.Last(2) ||    dms.DIPlus.Last(2) <= 40.0  ) )

{   OpenPosition(TradeType.Buy);   }

 

if (Bars.ClosePrices.Last(2) > Bars.OpenPrices.Last(2) && 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.Last(1) < Bars.OpenPrices.Last(1) && Bars.ClosePrices.Last(1) < Ichimoku.KijunSen.Last(1) && dms.DIPlus.Last(1) < dms.DIMinus.Last(1) && dms.DIMinus.Last(1) > 40.0 &&

 (Bars.ClosePrices.Last(2) > Bars.OpenPrices.Last(2) || Bars.ClosePrices.Last(2) > Ichimoku.KijunSen.Last(2) || dms.DIPlus.Last(2) > dms.DIMinus.Last(2) || dms.DIMinus.Last(2) <= 40.0  ) )

{  OpenPosition(TradeType.Sell);   }

 

if (Bars.ClosePrices.Last(2) < Bars.OpenPrices.Last(2) && Bars.ClosePrices.Last(1) < Bars.OpenPrices.Last(1))

{  ClosePosition(TradeType.Buy);  }

}

 

}

 

 

/// Call custom class method to send a market order

private void OpenPosition(TradeType type)

{

 

/// open a new position

ExecuteMarketOrder(type, this.Symbol, volume, InstanceName, StopLoss, null, marketRangePips, Comment);

}

 

/// Standard event handler that triggers upon position closing.

private void ClosePosition(TradeType type)

{

var p = Positions.Find(InstanceName, SymbolName, type);

 

if (p != null)

{

ClosePosition(p);

}

}

 

#endregion

 

#region Position Information

 

/// Check for opened position

private bool IsPositionOpenByType(TradeType type)

{

var p = Positions.FindAll(InstanceName, SymbolName, type);

 

if (p.Count() >= 1)

{

return true;

}

 

return false;

}

 

#endregion

}

}

 

 

 


@traderfxmaster007
Replies

PanagiotisCharalampous
13 Feb 2020, 08:45

Hi,

You need to replace this line of code

   ExecuteMarketOrder(type, this.Symbol, volume, InstanceName, StopLoss, null, marketRangePips, Comment);

with

   ExecuteMarketRangeOrder(type, this.Symbol.Name, volume, marketRangePips, Symbol.Bid, InstanceName, StopLoss, null, Comment);

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

traderfxmaster007
13 Feb 2020, 10:44

RE:

PanagiotisCharalampous said:

Hi,

You need to replace this line of code

   ExecuteMarketOrder(type, this.Symbol, volume, InstanceName, StopLoss, null, marketRangePips, Comment);

with

   ExecuteMarketRangeOrder(type, this.Symbol.Name, volume, marketRangePips, Symbol.Bid, InstanceName, StopLoss, null, Comment);

Best Regards,

Panagiotis 

Join us on Telegram

 

thank you sir. i will try this.


@traderfxmaster007

traderfxmaster007
13 Feb 2020, 21:09

hi sir one follow up question. this Cbot working well in forex but not in gold. i put this cbot in 9 forex pairs and in gold. i put settings on risk % 2 and stoploss 23pips. why gold traded only 0.01 lot and closed due to stoploss with  net profit only less than $-2.00 i expect a loss of -20. how to make this Cbot work on forex and gold, silver and oil? thanks again.


@traderfxmaster007