Moderator: admin
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
datetime last = 0;
double price = 0;
double lots = 0;
bool isBuy = true;
bool isSell = true;
OrdersIterator it();
it.WhenSymbol(_Symbol).WhenTrade();
while (it.Next())
{
datetime dt = it.GetOpenTime();
if (last < dt)
{
price = it.GetOpenPrice();
lots = OrderLots();
isBuy = it.IsBuy();
isSell = it.IsSell();
}
}
if (last == 0 && OrderType() == OP_BUY)
{
double point = MarketInfo(_Symbol, MODE_POINT);
int digits = (int)MarketInfo(_Symbol, MODE_DIGITS);
int mult = digits == 3 || digits == 5 ? 10 : 1;
double pipSize = point * mult;
double unitCost = MarketInfo(_Symbol, MODE_TICKVALUE);
double pips = isBuy ? ((close[0] - price) / pipSize)*10 : ((price - close[0]) / pipSize)*10;
double profit = ((lots * pips * unitCost)- (7 * lots));
Comment("Pips: " + DoubleToString(pips,0) + " $: " + DoubleToString(profit, 2));
}
else
if (last == 0 && OrderType() == OP_SELL)
{
double point = MarketInfo(_Symbol, MODE_POINT);
int digits = (int)MarketInfo(_Symbol, MODE_DIGITS);
int mult = digits == 3 || digits == 5 ? 10 : 1;
double pipSize = point * mult;
double unitCost = MarketInfo(_Symbol, MODE_TICKVALUE);
double pips = isSell ? ((price - close[0]) / pipSize)*10 : ((close[0] - price) / pipSize)*10;
double profit = ((lots * pips / unitCost)- (7 * lots));
Comment("Pips: " + DoubleToString(pips,0) + " $: " + DoubleToString(profit, 2));
}
return 0;
}
Users browsing this forum: No registered users and 40 guests