Description
The indicator shows the all kind of stats of your account. See screenshot. The indicator shows the all kind of stats of your account. See screenshot. The indicator shows the all kind of stats of your account. See screenshot.
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
//using cAlgo.Lib;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class AccountStatsIndicator : Indicator
{
private double totalVolume = 0;
private double totalPips = 0;
private double totalVWP = 0;
private double pipsToTP = 0;
private double pipsToSL = 0;
private double gain = 0;
private double totalNetPL = 0;
private double procEquity = 0;
private double htotalVolume = 0;
private double htotalPips = 0;
private double targetPips = 0;
private double htotalVWP = 0;
private double htotalNetPL = 0;
private double profitBreakdown = 0;
private double startingBalance = 1000;
private double hgain = 0;
private int _totBuy, _totSell;
private double _avg_buy, _avg_sell;
protected override void Initialize()
{
Timer.Start(2);
}
private void GetAveragePrice(out double _avg_buy, out double _avg_sell)
{
double Result = Symbol.Bid;
//double AveragePrice = 0;
long bCount = 0, sCount = 0;
double _aBuy = 0, _aSell = 0;
double _swap = 0;
_totBuy = 0;
_totSell = 0;
_avg_buy = 0;
_avg_sell = 0;
foreach (Position _pos in Positions)
{
if (_pos.SymbolCode == Symbol.Code)
{
_swap = _pos.Swap;
if (_pos.TradeType == TradeType.Buy)
{
_aBuy += (_pos.EntryPrice * _pos.Volume);
bCount += _pos.Volume;
// if (TypeOfTrade == TradeType.Buy)
_totBuy++;
_aBuy += Math.Abs(_pos.Commissions);
if (_swap < 0)
_aBuy += Math.Abs(_swap);
}
else
{
_aSell += (_pos.EntryPrice * _pos.Volume);
sCount += _pos.Volume;
_totSell++;
_aSell -= Math.Abs(_pos.Commissions);
if (_swap < 0)
_aSell -= Math.Abs(_swap);
}
}
}
if (_aBuy > 0 && bCount > 0)
{
_avg_buy = Math.Round(_aBuy / bCount, Symbol.Digits);
// Print("avg {0}", Result);
}
if (_aSell > 0 && sCount > 0)
{
_avg_sell = Math.Round(_aSell / sCount, Symbol.Digits);
// Print("avg {0}", Result);
}
return;
}
protected override void OnTimer()
{
double ask = Math.Round(Symbol.Ask, 5);
double bid = Math.Round(Symbol.Bid, 5);
double spread = Math.Round(Symbol.Spread / Symbol.PipSize, 5);
procEquity = Math.Round(100 * (1 - (Account.Balance - Account.Equity) / Account.Balance), 2);
var procEquityDD = Math.Round((100 - procEquity), 2);
if (procEquityDD < 0)
procEquityDD = 0.0;
string text = string.Format("Symbol Spread : {0,0} \n\n Account Equity % : {1,0} \n Account Equity Drawdown % : {2,0}", spread, procEquity, procEquityDD);
ChartObjects.DrawText("spread", "\t" + text, StaticPosition.TopRight, Colors.White);
GetAveragePrice(out _avg_buy, out _avg_sell);
foreach (var pos in Positions)
{
if (pos.SymbolCode == Symbol.Code)
{
totalVolume += pos.Volume;
totalPips += pos.Pips;
totalVWP += (pos.Pips * pos.Volume);
totalNetPL += pos.NetProfit;
if (pos.TradeType == TradeType.Buy)
{
pipsToTP = (double)(pos.TakeProfit - Symbol.Bid) / Symbol.PipSize;
pipsToSL = (double)(Symbol.Bid - pos.StopLoss) / Symbol.PipSize;
targetPips = (double)(pos.TakeProfit - _avg_buy) / Symbol.PipSize;
}
else
{
pipsToTP = (double)(Symbol.Ask - pos.TakeProfit) / Symbol.PipSize;
pipsToSL = (double)(pos.StopLoss - Symbol.Ask) / Symbol.PipSize;
targetPips = (double)(_avg_sell - pos.TakeProfit) / Symbol.PipSize;
}
}
}
gain = Math.Round(100 * (((Account.Balance + totalNetPL) / Account.Balance) - 1), 5);
string text1 = string.Format("\n\n\n\n\nExposure: \nSymbol Volume : {0,0} \nSymbol Pips : {1,0} \nTarget Pips : {2,0} \nVolume Weighted Pips : {3,0} \nPips To TP : {4,0} \nPips To SL : {5,0} \nSymbol Net P&L : {6,0} \n Symbol Gain % : {7,0}", totalVolume, Math.Round(totalPips, 1), Math.Round(targetPips, 1), Math.Round(totalVWP / totalVolume, 1), Math.Round(pipsToTP, 1), Math.Round(pipsToSL, 1), Math.Round(totalNetPL, 2), gain);
ChartObjects.DrawText("TWD1", "\t" + text1, StaticPosition.TopRight, Colors.White);
totalVolume = 0;
totalPips = 0;
totalNetPL = 0;
targetPips = 0;
gain = 0;
procEquity = 0;
pipsToTP = 0;
pipsToSL = 0;
totalVWP = 0;
foreach (var deal in History)
{
if (deal.SymbolCode == Symbol.Code)
{
htotalVolume += deal.Volume;
if (deal.TradeType == TradeType.Buy)
{
htotalPips += (deal.ClosingPrice - deal.EntryPrice) / Symbol.PipSize;
htotalVWP += ((deal.ClosingPrice - deal.EntryPrice) / Symbol.PipSize) * deal.Volume;
}
else
{
htotalPips += (deal.EntryPrice - deal.ClosingPrice) / Symbol.PipSize;
htotalVWP += ((deal.EntryPrice - deal.ClosingPrice) / Symbol.PipSize) * deal.Volume;
}
htotalNetPL += deal.NetProfit;
}
}
hgain = Math.Round(100 * (((startingBalance + htotalNetPL) / startingBalance) - 1), 2);
profitBreakdown = Math.Round(100 * ((((Account.Balance - startingBalance) + htotalNetPL) / (Account.Balance - startingBalance)) - 1), 2);
string text2 = string.Format("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nHistory: \nSymbol Volume : {0,0} \nSymbol Pips : {1,0} \nVolume Weighted Pips : {2,0} \nSymbol Net P&L : {3,0} \nSymbol Gained % : {4,0} \nSymbol Profit Breakdown % : {5,0}", htotalVolume, Math.Round(htotalPips, 1), Math.Round(htotalVWP / htotalVolume, 1), Math.Round(htotalNetPL, 2), hgain, profitBreakdown);
ChartObjects.DrawText("TWD2", "\t" + text2, StaticPosition.TopRight, Colors.White);
htotalVolume = 0;
htotalPips = 0;
htotalNetPL = 0;
htotalVWP = 0;
hgain = 0;
}
public override void Calculate(int index)
{
}
}
}
AV
AVFXBOOK
Joined on 27.04.2016
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: Account Stats Indicator.algo
- Rating: 5
- Installs: 2952
- Modified: 13/10/2021 09:54
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.
The History column works but the Exposure column does not. When I open position it doesn't show anything, just zeroes everywhere. Does anyone have the same problem? Any idea how to fix it?