ctrader 4.3 suspend this code
Created at 08 Jul 2022, 08:27
ctrader 4.3 suspend this code
08 Jul 2022, 08:27
i have a problem with this code in 4.3
but it works in 4.1
using cAlgo.API;
using System;
using Microsoft.Win32;
namespace cAlgo
{
// This sample indicator shows how to add a text box control on your chart
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class AWCalcVolume : Indicator
{
double risk;
double pip;
TextBox textBox3 = new TextBox();
[Parameter("Horizontal Alignment ", DefaultValue = HorizontalAlignment.Left)]
public HorizontalAlignment HAlignment { get; set; }
[Parameter("Vertical Alignment", DefaultValue = VerticalAlignment.Top)]
public VerticalAlignment VAlignment { get; set; }
[Parameter("Orientation", DefaultValue = Orientation.Horizontal)]
public Orientation Orientation1 { get; set; }
[Parameter("Color", DefaultValue = "Red")]
public string color { get; set; }
protected override void Initialize()
{
var mainStackPanel = new StackPanel
{
HorizontalAlignment = HAlignment,
VerticalAlignment = VAlignment,
Orientation = Orientation1
};
var StackPanel1 = new StackPanel
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
Orientation = Orientation.Vertical
};
var StackPanel2 = new StackPanel
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
Orientation = Orientation.Vertical,
Margin = 3
};
var StackPanel3 = new StackPanel
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
Orientation = Orientation.Vertical
};
var textBlock1 = new TextBlock
{
ForegroundColor = color,
HorizontalAlignment = HorizontalAlignment.Center,
Text = "Risk%"
};
var textBox1 = new TextBox
{
ForegroundColor = color,
HorizontalAlignment = HorizontalAlignment.Center,
Width = 50,
BorderThickness = 2,
BorderColor = color,
TextAlignment = TextAlignment.Center
};
var textBlock2 = new TextBlock
{
ForegroundColor = color,
HorizontalAlignment = HorizontalAlignment.Center,
Text = "SL(pips)"
};
var textBox2 = new TextBox
{
ForegroundColor = color,
HorizontalAlignment = HorizontalAlignment.Center,
Width = 50,
BorderThickness = 2,
BorderColor = color,
TextAlignment = TextAlignment.Center
};
var textBlock3 = new TextBlock
{
ForegroundColor = color,
HorizontalAlignment = HorizontalAlignment.Center,
Text = "Volume"
};
textBox3.ForegroundColor = color;
textBox3.HorizontalAlignment = HorizontalAlignment.Center;
textBox3.Width = 50;
textBox3.BorderThickness = 2;
textBox3.BorderColor = color;
textBox3.IsEnabled = false;
textBlock3.TextAlignment = TextAlignment.Center;
textBox1.TextChanged += TextBox1_TextChanged;
textBox2.TextChanged += TextBox2_TextChanged;
StackPanel1.AddChild(textBlock1);
StackPanel1.AddChild(textBox1);
StackPanel2.AddChild(textBlock2);
StackPanel2.AddChild(textBox2);
StackPanel3.AddChild(textBlock3);
StackPanel3.AddChild(textBox3);
mainStackPanel.AddChild(StackPanel1);
mainStackPanel.AddChild(StackPanel2);
mainStackPanel.AddChild(StackPanel3);
Chart.AddControl(mainStackPanel);
}
private void TextBox1_TextChanged(TextChangedEventArgs obj)
{
risk = Convert.ToDouble(obj.TextBox.Text);
}
private void TextBox2_TextChanged(TextChangedEventArgs obj)
{
pip = Convert.ToDouble(obj.TextBox.Text);
}
public override void Calculate(int index)
{
textBox3.Text = CalcVolume(risk, pip);
}
public string CalcVolume(double r, double p)
{
return Math.Round(Symbol.VolumeInUnitsToQuantity(Account.Balance * r / 100 / (pip * Symbol.PipValue)), 2).ToString();
}
}
}
Replies
IRCtrader
08 Jul 2022, 12:32
RE:
PanagiotisCharalampous said:
Hi khoshroomahdi,
You need to be more specific regarding what is not working.
Best Regards,
Panagiotis
Arguments out of range error in logs.
@IRCtrader
PanagiotisCharalampous
08 Jul 2022, 11:56
Hi khoshroomahdi,
You need to be more specific regarding what is not working.
Best Regards,
Panagiotis
Join us on Telegram and Facebook
@PanagiotisCharalampous