Indicator problem

 

Hello everybod

I hope someone can help me or point me in the right direction. I want to code an indicator that shows the history of the account balance. The logic is fine but it does not spread over the whole chart.

I hope this screenshot makes clearer what i need. 

 

 

My lack of english makes it hard to search via the right keywords. 

Thanks to everyone

 
CETAR:

Hello everybod

I hope someone can help me or point me in the right direction. I want to code an indicator that shows the history of the account balance. The logic is fine but it does not spread over the whole chart.

I hope this screenshot makes clearer what i need. 

 

 

My lack of english makes it hard to search via the right keywords. 

Thanks to everyone

 


Without the code not even Google-Glass can help us to help you.

(Please, there is SRC-button for the code.)

 
//+------------------------------------------------------------------+
//|                                           ShowAccountHistory.mq4 |
//|                                                                  |
//|                                              https://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 1

extern double Deposit=1000;
double Buf[];
int x;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
   {
   IndicatorSetDouble(INDICATOR_MAXIMUM,Deposit*4);
   IndicatorSetDouble(INDICATOR_MINIMUM,0);
   SetIndexBuffer(0,Buf);
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1,clrRed); 
   return(INIT_SUCCEEDED);
   }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
   {
   Buf[OrdersHistoryTotal()+1]=Deposit;
   if(OrdersHistoryTotal()>x){
      x=OrdersHistoryTotal();
      for(int i=OrdersHistoryTotal();i>=0;i--){
         int check=OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
         Buf[i]=Buf[i+1]+OrderProfit();}}
   return(0);
   }
//+------------------------------------------------------------------+
 
int check=OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
       Buf[i]=Buf[i+1]+OrderProfit();}}
  1. What happens when the select fails? What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  2. What are you looping through ALL orders but only incrementing buf by the earliest one each bar? Shouldn't Buf[i] be the same as Buf[i+1] unless an order was closed during that bar?
 
WHRoeder:
  1. What happens when the select fails? What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  2. What are you looping through ALL orders but only incrementing buf by the earliest one each bar? Shouldn't Buf[i] be the same as Buf[i+1] unless an order was closed during that bar?

to 1.
i guess something like this would be safer?

         if(!(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)))
            Buf[i]=Buf[i+1]+OrderProfit();
         else
            Alert("Error #: ",GetLastError()," in Order select function.");

 

to 2. 
sorry i didnt really understand your question.
could you rephrase your question? my english is not that good.
I will try to explain why i wrote it like this with comments

int start()
   {
   Buf[OrdersHistoryTotal()+1]=Deposit;
     //make Buf[] as big as it needs to be, setting the starting value of the account
   if(OrdersHistoryTotal()>x){
        //x set in start, if another order is closed Buf[] would be calculated again
      x=OrdersHistoryTotal();
        //x set to "new" number of closed trades  
      for(int i=OrdersHistoryTotal();i>=0;i--){
           //set i to highest so calculates oldest closed order first, then decrement to 0 to get values of all closed orders
         if(!(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)))
           //check if orderselect works; thanks to you :) if true
            Buf[i]=Buf[i+1]+OrderProfit();
              //Buf for selected order gets value of order before plus profit
         else
           //if order select fails
            Alert("Error #: ",GetLastError()," in Order select function.");
              //shows error
   return(0);
   }
 

*Edit

if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
 
CETAR:

 The logic is fine but it does not spread over the whole chart.

 


The logic is not fine.

You need to find the bar that relates to the time of your first deposit and total deposit+profit/loss on all orders closed before the start of the next bar.

If the first bar on the chart is later than the deposit time, then you will need to total the deposit+profit/loss on all orders closed before the start of the next bar.

Then for every bar after, find the  profit/loss on any trades closed during the lifetime of that bar and add that to the previous value. (Or total deposit+profit/loss on all orders closed before the start of the next bar.)

As WHRoeder said

Shouldn't Buf[i] be the same as Buf[i+1] unless an order was closed during that bar? 

 

Highlighted

If you do it this way, you will also need to code to take into account any bars missing from the chart 

 

OK i got it now :)

thanks to all 

Reason: