Topics
Replies
tatorzth
12 Oct 2020, 10:28
RE:
PanagiotisCharalampous said:
HI WB,
You first need to explain what are you trying to do since your code does not make sense to me.
Best Regards,
Panagiotis
Hi Panagiotis,
i just want to convert my Print() function to show all value on the graph.
c# is new to me, sorry for this inconvenience.
Regards,
WB
@tatorzth
tatorzth
12 Oct 2020, 10:12
RE:
PanagiotisCharalampous said:
HI WB,
There are several issues in your code
1) text variable is not declared.
2) For the x coordinate, the method takes as input the date or the bar index. The VBuy input you are using doesn't make much sense.
Best Regards,
Panagiotis
Hi Panagiotis,
thanks for your help.
please advise to me the correct code to show VBuy value on the chart.
Regards,
WB
@tatorzth
tatorzth
12 Oct 2020, 09:49
RE:
PanagiotisCharalampous said:
HI WB,
You need to provide the complete code and let us know what is the problem.
Best Regards,
Panagiotis
Hi Panagiotis
my idea is just want to replace Print() by DrawText() function
please see my code below
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace WBX
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class WBX : Robot
{
[Parameter("Quantity (Lots)", Group = "Volume", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]
public double Quantity { get; set; }
[Parameter("MA Type", Group = "Moving Average")]
public MovingAverageType MAType { get; set; }
[Parameter("Source", Group = "Moving Average")]
public DataSeries SourceSeries { get; set; }
[Parameter("Periods", Group = "Moving Average", DefaultValue = 10)]
public int Periods { get; set; }
[Parameter("Range", DefaultValue = 3)]
public int Range { get; set; }
[Parameter("Multiorder range", DefaultValue = 3)]
public int MultiRange { get; set; }
[Parameter("TP", DefaultValue = 3)]
public int TP { get; set; }
[Parameter("SL", DefaultValue = 3)]
public int SL { get; set; }
[Parameter("Max Trade", DefaultValue = 3, MinValue = 1, Step = 1)]
public int MaxTrade { get; set; }
[Parameter("Trade direction : Buy", DefaultValue = false)]
public bool Buy { get; set; }
[Parameter("Trade direction : Sell", DefaultValue = false)]
public bool Sell { get; set; }
public int NumberofTrade;
public int VBuy;
public int VSell;
public double NextOrderAllow;
private MovingAverage Ma;
private const string label = "MA Trend cBot";
protected override void OnStart()
{
Ma = Indicators.MovingAverage(SourceSeries, Periods, MAType);
var Position = Positions.Find("SampleMA", SymbolName);
VBuy = Convert.ToInt32((10000 * (Ma.Result.LastValue - Symbol.Ask)));
VSell = Convert.ToInt32((10000 * (Symbol.Bid - Ma.Result.LastValue)));
var highPrice = VBuy;
var openTime = MarketSeries.OpenTime.LastValue;
var text = Chart.DrawText("text1", "High is here", openTime, highPrice, Color.Red);
Chart.DrawText("text1", "High is here", VBuy, VSell, Color.Red);
if (Position == null)
{
NextOrderAllow = 0;
}
else if (VBuy > 0)
{
NextOrderAllow = Symbol.Ask - (MultiRange * 0.0001);
}
else if (VSell > 0)
{
NextOrderAllow = Symbol.Bid + (MultiRange * 0.0001);
}
}
protected override void OnTick()
{
Ma = Indicators.MovingAverage(SourceSeries, Periods, MAType);
VBuy = Convert.ToInt32((10000 * (Ma.Result.LastValue - Symbol.Ask)));
VSell = Convert.ToInt32((10000 * (Symbol.Bid - Ma.Result.LastValue)));
Chart.DrawText("text1", "Value", VBuy, VSell, Color.Red);
text.VerticalAlignment = VerticalAlignment.Bottom;
text.HorizontalAlignment = HorizontalAlignment.Center;
if (Buy == true)
{
if (VBuy > Range)
{
if (NextOrderAllow == 0)
{
Open(TradeType.Buy);
NextOrderAllow = Symbol.Ask - (MultiRange * 0.0001);
}
else if (Symbol.Ask < NextOrderAllow)
{
Open(TradeType.Buy);
NextOrderAllow = Symbol.Ask - (MultiRange * 0.0001);
}
}
if (VBuy > 0)
{
Print("Trade direction : Buy ", VBuy);
Print("Next entry order allow : ", NextOrderAllow);
}
}
if (Sell == true)
{
if (VSell > Range)
{
if (NextOrderAllow == 0)
{
Open(TradeType.Sell);
NextOrderAllow = Symbol.Bid + (MultiRange * 0.0001);
}
else if (Symbol.Bid > NextOrderAllow)
{
Open(TradeType.Sell);
NextOrderAllow = Symbol.Bid + (MultiRange * 0.0001);
}
}
if (VSell > 0)
{
Print("Trade direction : Sell ", VSell);
Print("Next entry order allow : ", NextOrderAllow);
}
}
}
private void Open(TradeType tradeType)
{
var Position = Positions.Find("SampleMA", SymbolName, tradeType);
var volumeInUnits = Symbol.QuantityToVolumeInUnits(Quantity);
if (Position == null)
{
NextOrderAllow = 0;
ExecuteMarketOrder(tradeType, SymbolName, volumeInUnits, "SampleMA", SL, TP);
NumberofTrade = 1;
}
else if (MaxTrade > NumberofTrade)
{
ExecuteMarketOrder(tradeType, SymbolName, volumeInUnits, "SampleMA", SL, TP);
NumberofTrade = NumberofTrade + 1;
}
}
}
}
@tatorzth
tatorzth
12 Oct 2020, 09:27
RE:
PanagiotisCharalampous said:
HI WB,
You can use the DrawText() method.
Best Regards,
Panagiotis
Hi Panagiotis
something wrong with my code please help me review this
VBuy = Convert.ToInt32((10000 * (Ma.Result.LastValue - Symbol.Ask)));
VSell = Convert.ToInt32((10000 * (Symbol.Bid - Ma.Result.LastValue)));
Chart.DrawText("text1", "High is here", VBuy, VSell, Color.Red);
text.VerticalAlignment = VerticalAlignment.Bottom;
text.HorizontalAlignment = HorizontalAlignment.Center;
please advise
@tatorzth
tatorzth
05 Nov 2020, 11:12
RE: RE: Text or Font Size
researchscrap said:
How can i modify below code to show my calculation value (var, int and double) ?
ChartObjects.DrawText("text1", "TEXT", StaticPosition.TopRight, Colors.Yellow);
ChartObjects.DrawText("text2", "\nTEXT", StaticPosition.TopRight, Colors.Yellow);
sorry for stupid question. i am self learning cbot programing because few people use this application in my country.
Regards,
WB
@tatorzth