How to use /(divide)?

 

Hello...

Please advice me regarding the buffer calculation in the indicator.
I modified iExposure.mq4 to show profit factor.

but no data shown on the indicatorif added below code.

----------------------------------------------------------------------------------------------------------------------------------------------------

SymbolsSummaries[index][PROFITFACTOR]=SymbolsSummaries[index][GPROFIT] / SymbolsSummaries[index][GLOSS]; //add

// contents GPROFIT=200, GLOSS=100

there are no error on expert/journal tabs.
but it could be shown meaningful data if modified from / (divide) to *, + .- .
Why i cannot use /(divide) for caliculation?
Could you advice me how to show profit factor?

Thanks in advance

Edited:

Sorry to confuse you.

MQ4 file name is iHistory.mq4 not iExposure.mq4.

 

Show your code

 

phy.

Here you are..... check line 230. //add

Thanks,

//+------------------------------------------------------------------+
//| iExposure.mq4 |---> iHistory.mq4
//| Copyright ゥ 2007, MetaQuotes Software Corp. |
//| https://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright ゥ 2007, MetaQuotes Software Corp."
#property link "https://www.metaquotes.net/"

#property indicator_separate_window
#property indicator_buffers 1
//#property indicator_minimum 0.0
//#property indicator_maximum 0.1

#define SYMBOLS_MAX 1024

#define PROFITFACTOR 0//add
#define NETPROFIT 1
#define GPROFIT 2
#define GLOSS 3
#define DEALS 4
#define BUY_ORDERS 5
#define BUY_LOTS 6
#define SELL_ORDERS 7
#define SELL_LOTS 8
#define TOTAL_LOTS 9


extern color HeaderColor=Red;
extern color SymbolColor=Lime;
extern color TextColor=White;
extern int TextSize=10;
extern int RowSpacing=14;

string Name="History Summary";
string Symbols[SYMBOLS_MAX];
int SymbolsTotal=0;
double SymbolsSummaries[SYMBOLS_MAX][10];
int Lines=-1;
string Cols[9]={"Symbol",

"ProfitFactor",//add
"NetProfit",
"Profit",
"Loss",
"Dearls",
"BuyDeals",
"BuyLots",
"SellDeals",
"SellLots",
"TotalLots",
};

int Shifts[10]={ 5, 80, 160, 240, 320, 380, 450, 520, 590, 660, 720};

double MapBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void init()
{
IndicatorShortName(Name);
SetIndexBuffer(0,MapBuffer);
SetIndexStyle(0,DRAW_NONE);
IndicatorDigits(0);
SetIndexEmptyValue(0,0.0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void deinit()
{
int windex=WindowFind(Name);
if(windex>0) ObjectsDeleteAll(windex);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
void start()
{
string name;
int i,col,line,windex=WindowFind(Name);
//----
if(windex<0) return;
//---- header line
if(Lines<0)
{
for(col=0; col<10; col++)
{
name="Head_"+col;
if(ObjectCreate(name,OBJ_LABEL,windex,0,0))
{
ObjectSet(name,OBJPROP_XDISTANCE,Shifts[col]);
ObjectSet(name,OBJPROP_YDISTANCE,RowSpacing);
ObjectSetText(name,Cols[col],9,"Arial",HeaderColor);
}
}
Lines=0;
}
//----
ArrayInitialize(SymbolsSummaries,0.0);
int total=Analyze();
if(total>0)
{
line=0;
for(i=0; i<SymbolsTotal; i++)
{
if(SymbolsSummaries[i][DEALS]<=0) continue;
line++;
//---- add line
if(line>Lines)
{
int y_dist=RowSpacing*(line+1)+1;
for(col=0; col<10; col++)
{
name="Line_"+line+"_"+col;
if(ObjectCreate(name,OBJ_LABEL,windex,0,0))
{
ObjectSet(name,OBJPROP_XDISTANCE,Shifts[col]);
ObjectSet(name,OBJPROP_YDISTANCE,y_dist);
}
}
Lines++;
}
//---- set line

name="Line_"+line+"_0";
ObjectSetText(name,Symbols[i],9,"Arial",SymbolColor);

name="Line_"+line+"_1";
ObjectSetText(name,DoubleToStr(SymbolsSummaries[i][PROFITFACTOR],2),TextSize,"Arial",TextColor); //add

name="Line_"+line+"_2";
ObjectSetText(name,DoubleToStr(SymbolsSummaries[i][NETPROFIT],2),TextSize,"Arial",TextColor);
name="Line_"+line+"_3";
ObjectSetText(name,DoubleToStr(SymbolsSummaries[i][GPROFIT],2),TextSize,"Arial",TextColor);
name="Line_"+line+"_4";
ObjectSetText(name,DoubleToStr(SymbolsSummaries[i][GLOSS],2),TextSize,"Arial",TextColor);
name="Line_"+line+"_5";
ObjectSetText(name,DoubleToStr(SymbolsSummaries[i][DEALS],0),TextSize,"Arial",TextColor);
name="Line_"+line+"_6";
ObjectSetText(name,DoubleToStr(SymbolsSummaries[i][BUY_ORDERS],0),TextSize,"Arial",TextColor);
name="Line_"+line+"_7";
ObjectSetText(name,DoubleToStr(SymbolsSummaries[i][BUY_LOTS],2),TextSize,"Arial",TextColor);
name="Line_"+line+"_8";
ObjectSetText(name,DoubleToStr(SymbolsSummaries[i][SELL_ORDERS],0),TextSize,"Arial",TextColor);
name="Line_"+line+"_9";
ObjectSetText(name,DoubleToStr(SymbolsSummaries[i][SELL_LOTS],2),TextSize,"Arial",TextColor);
name="Line_"+line+"_10";
ObjectSetText(name,DoubleToStr(SymbolsSummaries[i][BUY_LOTS]+SymbolsSummaries[i][SELL_LOTS],2),TextSize,"Arial",TextColor);

}
}
//---- remove lines
if(total<Lines)
{
for(line=Lines; line>total; line--)
{

name="Line_"+line+"_0";
ObjectSetText(name,"");
name="Line_"+line+"_1";
ObjectSetText(name,"");
name="Line_"+line+"_2";
ObjectSetText(name,"");
name="Line_"+line+"_3";
ObjectSetText(name,"");
name="Line_"+line+"_4";
ObjectSetText(name,"");
name="Line_"+line+"_5";
ObjectSetText(name,"");
name="Line_"+line+"_6";
ObjectSetText(name,"");
name="Line_"+line+"_7";
ObjectSetText(name,"");
name="Line_"+line+"_8";
ObjectSetText(name,"");
name="Line_"+line+"_9";
ObjectSetText(name,"");
name="Line_"+line+"_10";
ObjectSetText(name,"");

}
}
//---- to avoid minimum==maximum
MapBuffer[Bars-1]=-1;
//----
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int Analyze()
{
double profit,bprofit,sprofit;
int i,index,type,total=OrdersHistoryTotal();
//----
for(i=0; i<total; i++)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) continue;
type=OrderType();
if(type!=OP_BUY && type!=OP_SELL) continue;
index=SymbolsIndex(OrderSymbol());
if(index<0 || index>=SYMBOLS_MAX) continue;
//----
//SymbolsSummaries[index][DEALS]++;

profit=OrderProfit()+OrderCommission()+OrderSwap();

if(profit>=0)SymbolsSummaries[index][GPROFIT]+=profit;
else SymbolsSummaries[index][GLOSS]+=profit;

SymbolsSummaries[index][NETPROFIT]=SymbolsSummaries[index][GPROFIT]+SymbolsSummaries[index][GLOSS];

SymbolsSummaries[index][PROFITFACTOR]=(SymbolsSummaries[index][GPROFIT])/(SymbolsSummaries[index][GLOSS]); //add HERE !


if(type==OP_BUY)
{
SymbolsSummaries[index][BUY_LOTS]+=OrderLots();
SymbolsSummaries[index][BUY_ORDERS]++;
}
if(type==OP_SELL)
{
SymbolsSummaries[index][SELL_LOTS]+=OrderLots();
SymbolsSummaries[index][SELL_ORDERS]++;
}

SymbolsSummaries[index][DEALS]=SymbolsSummaries[index][SELL_ORDERS]+SymbolsSummaries[index][BUY_ORDERS];
}
//----
total=0;
for(i=0; i<SymbolsTotal; i++)
{
if(SymbolsSummaries[i][DEALS]>0) total++;
}
//----
return(total);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int SymbolsIndex(string SymbolName)
{
bool found=false;
//----
for(int i=0; i<SymbolsTotal; i++)
{
if(SymbolName==Symbols[i])
{
found=true;
break;
}
}
//----
if(found) return(i);
if(SymbolsTotal>=SYMBOLS_MAX) return(-1);
//----
i=SymbolsTotal;
SymbolsTotal++;
Symbols[i]=SymbolName;
SymbolsSummaries[i][PROFITFACTOR]=0;//add
SymbolsSummaries[i][NETPROFIT]=0;
SymbolsSummaries[i][GPROFIT]=0;
SymbolsSummaries[i][GLOSS]=0;
SymbolsSummaries[i][DEALS]=0;
SymbolsSummaries[i][SELL_ORDERS]=0;
SymbolsSummaries[i][SELL_LOTS]=0;
SymbolsSummaries[i][BUY_ORDERS]=0;
SymbolsSummaries[i][BUY_LOTS]=0;
//----
return(i);
}


//+------------------------------------------------------------------+