Total earnings of past transactions on the chart screen at MT 4

 

I wanted to create an indicator that displays the total earnings of past transactions on the chart screen at MT 4, I created the following sample file, but when I activate the indicator on the chart screen the numbers will change and be displayed.

I think Assignment operator is a problem.

But I do not know how to improve.


I would be pleased if you could give us reasons and suggestions for improvement.

I kindly thank you.


test.mq4

#property strict
#property indicator_chart_window

double a;
double b;

int start(){

for(int i=1; i <= OrdersHistoryTotal(); i++){
if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) == false) break;

if(OrderType() == OP_BUY || OrderType() == OP_SELL){

a = OrderProfit();
}

b += a;
}

Test("test",20,20);
ObjectSetText("test",DoubleToStr(b,1),10,"", White);

return(0);
}

void Test(string name, int x, int y){

ObjectCreate(name, OBJ_LABEL, 0, 0, 0);
ObjectSet(name, OBJPROP_CORNER, 0);
ObjectSet(name, OBJPROP_XDISTANCE, x);
ObjectSet(name, OBJPROP_YDISTANCE, y);
ObjectSet(name, OBJPROP_BACK, FALSE);

}
 

Forum on trading, automated trading systems and testing trading strategies

When you post code please use the CODE button (Alt-S)!

Use the CODE button

 
セルゲイ・ゴルベフ:

Sorry.It Changed.

#property strict
#property indicator_chart_window

double a;
double b;

int start(){

for(int i=1; i <= OrdersHistoryTotal(); i++){
if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) == false) break;

if(OrderType() == OP_BUY || OrderType() == OP_SELL){

a = OrderProfit();
}

b += a;
}

Test("test",20,20);
ObjectSetText("test",DoubleToStr(b,1),10,"", White);

return(0);
}

void Test(string name, int x, int y){

ObjectCreate(name, OBJ_LABEL, 0, 0, 0);
ObjectSet(name, OBJPROP_CORNER, 0);
ObjectSet(name, OBJPROP_XDISTANCE, x);
ObjectSet(name, OBJPROP_YDISTANCE, y);
ObjectSet(name, OBJPROP_BACK, FALSE);

}
 
               
for(int i=1; i <= OrdersHistoryTotal(); i++){
   if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) == false) break;
                  
   if(OrderType() == OP_BUY || OrderType() == OP_SELL){
      a = OrderProfit();
             
   }
   b += a;
  1. Set your variable b to zero before the loop. That is why it keeps changing.
  2. Add a to it inside the if block.
  3. Profit is OrderProfit + OrderSwap + OrderCommission.
  4. Do you want profit for all orders on all charts, or only for the chart's symbol, (add symbol filter?)
  5. Position indexes are zero through OrdersHistoryTotal - 1. You are dropping the first entry.
  6. Run your code through the styler so you can see the flow.
 
whroeder1:
  1. Set your variable b to zero before the loop. That is why it keeps changing.
  2. Add a to it inside the if block.
  3. Profit is OrderProfit + OrderSwap + OrderCommission.
  4. Do you want profit for all orders on all charts, or only for the chart's symbol, (add symbol filter?)
  5. Position indexes are zero through OrdersHistoryTotal - 1. You are dropping the first entry.


Thank you very much!!

It is solved.

 
Sergey Golubev:

I won 500 000.00USD on my Demo account... How much can I transfer to my Real account??

 
RonaldoSantos015:

I won 500 000.00USD on my Demo account... How much can I transfer to my Real account??

  • Demo account is using virtual money.
  • Real account is using real money.

Vistual money can not be transferred to the real money.

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

MetaTrader 5 Help - Open an Account - 

Two types of accounts are available in the trading platform: demonstration (demo) and real. Demo accounts provide the opportunity to work in a training mode without real money, allowing to test a trading strategy. They feature all the same functionality as the live ones. The difference is that demo accounts can be opened without any investment and, therefore, one cannot expect to profit from them.

Open an Account - Getting Started - MetaTrader 5
Open an Account - Getting Started - MetaTrader 5
  • www.metatrader5.com
Two types of accounts are available in the trading platform: demonstration (demo) and real. Demo accounts provide the opportunity to work in a training mode without real money, allowing to test a trading strategy. They feature all the same functionality as the live ones. The difference is that demo accounts can be opened without any investment...
 

Damn..😭😭😭 

Perhaps i need an investor.

 
RonaldoSantos015:

Damn..😭😭😭 

Perhaps i need an investor.

You can find the broker proposing real accounts in cent (in this case: 10 dollars = 1,000 in Metatrader).
Because 10 dollars is real money, and at least - you will try/feel/know about how to trade with real money in psychological point of view for example.

 
Sergey Golubev:

You can find the broker proposing real accounts in cent (in this case: 10 dollars = 1,000 in Metatrader).
Because 10 dollars is real money, and at least - you will try/feel/know about how to trade with real money in psychological point of view for example.

Thanks sergey, till next time sir...😊😊
Reason: