Topics
Replies
whis.gg
09 Jun 2016, 21:28
Hi. You can draw rectangle by using lines. See the sample.
private void DrawRectangle(string objectName, int x, double y, int width, double height, Colors color, int thickness, LineStyle style)
{
ChartObjects.DrawLine(objectName + "a", x, y, x + width, y, color, thickness, style);
ChartObjects.DrawLine(objectName + "b", x + width, y, x + width, y + height, color, thickness, style);
ChartObjects.DrawLine(objectName + "c", x + width, y + height, x, y + height, color, thickness, style);
ChartObjects.DrawLine(objectName + "d", x, y + height, x, y, color, thickness, style);
}
private void RemoveRectangle(string objectName)
{
ChartObjects.RemoveObject(objectName + "a");
ChartObjects.RemoveObject(objectName + "b");
ChartObjects.RemoveObject(objectName + "c");
ChartObjects.RemoveObject(objectName + "d");
}
@whis.gg
whis.gg
04 Jun 2016, 14:54
var longPosition = Positions.FindAll(Label, Symbol, TradeType.Buy);
This variable holds array of all positions found.
longPosition.Length returns you number of items in the array.
Personally I would use LINQ query.
int numberOfLongPositions = Positions.Where(pos => pos.Label == Label)
.Where(pos => pos.Symbol == Symbol)
.Where(pos => pos.TradeType == TradeType.Buy)
.Count();
int numberOfShortPositions = Positions.Where(pos => pos.Label == Label)
.Where(pos => pos.Symbol == Symbol)
.Where(pos => pos.TradeType == TradeType.Sell)
.Count();
@whis.gg
whis.gg
04 Jun 2016, 14:27
RE:
tmc. said:
Hi, you might want to try my method. It doesn't include commissions though.
private long Volume(int riskPercent, int stopLossPips) { double risked = Account.Balance * riskPercent / 100; double volume = risked / stopLossPips / Symbol.PipValue; return Symbol.NormalizeVolume(volume, RoundingMode.ToNearest); }
@whis.gg
whis.gg
04 Jun 2016, 14:27
Hi, you might want to try my method. It doesn't include commissions though.
private long Volume(int riskPercent, int stopLossPips)
{
double risked = Account.Balance * riskPercent / 100;
double volume = risked / stopLossPips / Symbol.PipValue;
return Symbol.NormalizeVolume(volume, RoundingMode.ToNearest);
}
@whis.gg
whis.gg
26 May 2016, 21:40
I believe you can't. However, you can save the information into comment or expiration time.
DateTime expiration = Time.AddYears(1);
string comment = Time.ToString();
TradeResult order = PlaceLimitOrder(TradeType.Buy, Symbol, 1000, 1, "", null, null, expiration, comment);
if (order.IsSuccessful)
{
DateTime orderExpiration = (DateTime)order.PendingOrder.ExpirationTime;
DateTime timeFromExpiration = orderExpiration.AddYears(-1);
Print("From expiration: " + timeFromExpiration);
DateTime timeFromComment = DateTime.Parse(order.PendingOrder.Comment);
Print("From comment: " + timeFromComment);
}
Log:
26/05/2016 18:39:31.984 | cBot "New cBot" was started successfully for EURUSD, h1. 26/05/2016 18:39:32.015 | Placing Limit Order to Buy 1000 EURUSD (Price: 1.00000, ExpireTime: 26/05/2017 18:39:32) 26/05/2016 18:39:32.155 | → Placing Limit Order to Buy 1000 EURUSD (Price: 1.00000, ExpireTime: 26/05/2017 18:39:32) SUCCEEDED, PendingOrder OID18905301 26/05/2016 18:39:32.155 | From expiration: 26/05/2016 18:39:32 26/05/2016 18:39:32.155 | From comment: 26/05/2016 18:39:32 26/05/2016 18:39:32.187 | cBot "New cBot" was stopped for EURUSD, h1.
@whis.gg
whis.gg
23 May 2016, 11:15
RE: RE:
moneybiz said:
tmc. said:
I came across same issue with offset giving me wrong values. Try following snippet, it worked for me.
TimeSpan offset = TimeZoneInfo.Local.GetUtcOffset(DateTime.UtcNow);Doesn't this give your local time offset from UTC? It doesn't have anything to do with server's UTC offset.
Oh sorry, I misread your issue. Try the following.
Print(TimeZone.GetUtcOffset(Server.Time));
@whis.gg
whis.gg
23 May 2016, 00:28
Let me know if it returns same values as original indicator.
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class SlopeDirectionalLine : Indicator
{
[Parameter("Period", DefaultValue = 80)]
public int Period { get; set; }
[Parameter("Type", DefaultValue = MovingAverageType.Weighted)]
public MovingAverageType MAType { get; set; }
[Output("Result", Color = Colors.White)]
public IndicatorDataSeries Result { get; set; }
[Output("UpTrend", PlotType = PlotType.DiscontinuousLine, Color = Colors.Green)]
public IndicatorDataSeries UpTrend { get; set; }
[Output("DnTrend", PlotType = PlotType.DiscontinuousLine, Color = Colors.Red)]
public IndicatorDataSeries DnTrend { get; set; }
private MovingAverage ma1, ma2;
protected override void Initialize()
{
ma1 = Indicators.MovingAverage(MarketSeries.Close, Period, MAType);
ma2 = Indicators.MovingAverage(MarketSeries.Close, Period / 2, MAType);
}
public override void Calculate(int index)
{
Result[index] = 2 * ma2.Result[index] - ma1.Result[index];
bool isUpTrend = Result[index] > Result[index - 1];
if (isUpTrend)
{
UpTrend[index] = Result[index];
}
else
{
DnTrend[index] = Result[index];
}
}
}
}
@whis.gg
whis.gg
12 May 2016, 13:53
if (position.Pips >= BreakEvenPips)
{
if (position.TradeType == TradeType.Buy)
{
var newStopLoss = position.EntryPrice + BreakEvenGain * Symbol.PipSize;
if (position.StopLoss != newStopLoss)
ModifyPosition(position, newStopLoss, null);
}
else if (position.TradeType == TradeType.Sell)
{
var newStopLoss = position.EntryPrice - BreakEvenGain * Symbol.PipSize;
if (position.StopLoss != newStopLoss)
ModifyPosition(position, newStopLoss, null);
}
}
Not tested.
@whis.gg
whis.gg
29 Apr 2016, 17:44
Hi Diego!
Maybe Inter-Market v4 (5TF + Prev. Data) by GoldnOil750 is what you are looking for.
If you need to code something specific, don't hesitate to contact me via email and I will give you a quote.
@whis.gg
whis.gg
29 Apr 2016, 15:48
Hi, just a sample. Edit the code according to your needs.
using System;
using cAlgo.API;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class RRR : Indicator
{
public override void Calculate(int index)
{
if (Positions.Count == 0)
return;
Position position = Positions[Positions.Count - 1];
double TakeProfitPips = Math.Abs((double)position.EntryPrice - (double)position.TakeProfit) * Symbol.PipSize;
double StopLossPips = Math.Abs((double)position.EntryPrice - (double)position.StopLoss) * Symbol.PipSize;
string text;
if (TakeProfitPips >= StopLossPips)
text = string.Format("1:{0}", Math.Round(TakeProfitPips / StopLossPips, 1));
else
text = string.Format("{0}:1", Math.Round(StopLossPips / TakeProfitPips, 1));
ChartObjects.DrawText("RRR", text, StaticPosition.TopRight, Colors.Red);
}
}
}
@whis.gg
whis.gg
28 Apr 2016, 17:02
Hi, you need to create another parameter and use it in the initialization of indicators.
Sample code:
[Parameter("Fast Source")]
public DataSeries FastSource { get; set; }
[Parameter("Slow Source")]
public DataSeries SlowSource { get; set; }
protected override void OnStart()
{
fastMa = Indicators.MovingAverage(FastSource, FastPeriods, MAType);
slowMa = Indicators.MovingAverage(SlowSource, SlowPeriods, MAType);
}
@whis.gg

whis.gg
10 Jun 2016, 15:08
using System.Linq; protected override void OnTick() { while (Account.MarginLevel <= StopOutPercent) { ClosePosition(Positions.OrderByDescending(x => x.GrossProfit).Last()); } }This one simulates stop out.
@whis.gg