Description
- 保有ポジションのPips数をチャート内に表示します
- ()内は金額ですが設定で非表示にできます
- 合計収益(手数料込)が負のときはピンク、正のときは水色になります
- Shows the pips of the position in the chart.
- () is the price, but you can hide it in the settings.
- When the total netprofit are negative, they are pink, and when they are positive, they are light blue.
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
using System.Collections.Generic;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class PositionPipsCounter : Indicator
{
[Parameter("金額表示", DefaultValue = true)]
public bool priceSwitch { get; set; }
[Parameter("位置を上に移動", DefaultValue = false)]
public bool upperPosition { get; set; }
List<ChartStaticText> positionTextList = new List<ChartStaticText>();
private int moveDistance;
protected override void Initialize()
{
if (upperPosition == true)
{
moveDistance = 4;
}
else
{
moveDistance = 2;
}
TimeSpan timeSpan = new TimeSpan(0, 0, 0, 0, 1);
Timer.Start(timeSpan);
}
protected override void OnTimer()
{
double totalPips = 0;
double totalNetprofit = 0;
string text;
int positionCount = 0;
//ポジションの数
foreach (var position in Positions)
{
if (position.SymbolName.Equals(Chart.SymbolName))
{
positionCount++;
}
}
foreach (var positionText in positionTextList)
{
Chart.RemoveObject(positionText.Name);
}
foreach (var position in Positions)
{
if (position.SymbolName.Equals(Chart.SymbolName))
{
text = position.Pips.ToString("F1");
if (priceSwitch)
{
text += " (" + String.Format("{0:#,0}", position.NetProfit) + ") ";
}
for (int i = 0; i < positionCount + moveDistance; i++)
{
text += "\n";
}
totalPips += position.Pips;
totalNetprofit += position.NetProfit;
var PipsCountText = Chart.DrawStaticText("Pips Counter" + positionCount.ToString(), text, VerticalAlignment.Bottom, HorizontalAlignment.Left, Color.White);
positionTextList.Add(PipsCountText);
if (position.NetProfit < 0)
{
PipsCountText.Color = Color.Pink;
}
else if (position.NetProfit > 0)
{
PipsCountText.Color = Color.Aqua;
}
positionCount--;
}
}
text = "---\n total : ";
text += totalPips.ToString("F1");
if (priceSwitch)
{
text += " (" + String.Format("{0:#,0}", totalNetprofit) + ") ";
}
for (int i = 0; i < moveDistance - 1; i++)
{
text += "\n";
}
var totalText = Chart.DrawStaticText("Pips Counter Total", text, VerticalAlignment.Bottom, HorizontalAlignment.Left, Color.White);
if (totalNetprofit < 0)
{
totalText.Color = Color.Pink;
}
else if (totalNetprofit > 0)
{
totalText.Color = Color.Aqua;
}
}
public override void Calculate(int index)
{
}
}
}
summer
Joined on 10.08.2020
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: Position Pips Counter.algo
- Rating: 5
- Installs: 2372
- Modified: 13/10/2021 09:55
Note that publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section, please use the Copyright Infringement Notification form to submit a claim.
Comments
Log in to add a comment.
No comments found.