Array Question.

 

Hi everybody,

My questione is simple but I struggled enough with the implicit recoursivity of processing every tick. I need to create an array containing for every indexes my different values of AccountBalance as they appears to be in the backtesting window. In order to calculate some moving averages of it, with iMAOnArray method.

Acc[0] = AccountBalance();

     // retrieving info from trade history
      int hstTotal=OrdersHistoryTotal();
      for(int i=1;i<=hstTotal;i++)
          {
           //---- check selection result
           if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false)
       
              break;
     
           else
              {
              OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
              
                Acc[i]= Acc[i-1]+ OrderProfit( ) ;

              
              }
           }
Ok. Acc[0] is correct, but if I print Acc[1] or previous I do not obtain the previos AccountBalance value.

Thanks a lot,

SA

 

 
     // retrieving info from trade history
      int hstTotal=OrdersHistoryTotal();
      double Acc[hstTotal+1];
      Acc[0] = AccountBalance();
      for(int i=1;i<=hstTotal;i++)
          {
           //---- check selection result
           if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false)
       
              break;
     
           else
              {
 
              //order is allready selected no need to select it again
                Acc[i]= Acc[i-1]+ OrderProfit( ) ;
 
              
              }
           }
 
Liliput wrote >>

Thanks a lot,

but if you test it, will find it doesn't work better.

In fact, after a ArraySetAsSeries( Acc, true), here what happens.

If my last 3 balance values are: 9119.56, 9052.15, 9350.71, Acc[0] returns correctly 9119.56, but Acc[1] returns 9148.46, Acc[2] 9158.09, Acc[3] 9196.62.

I do not know how and where returns figures so different, they could be from the Balance of trades not closed yet.

Fixing that with

OrderSelect(i,SELECT_BY_TICKET,MODE_TRADES)

nothing better again, remains only the zero-index as different from zero and correct, the others element of the array seem to be all zeros.

Perhaps, It's only a my erroneous impression due to erroneous inferences by printing. With this code, in fact, moving averages seem to work:

   // retrieving info from trade history
      int hstTotal=OrdersHistoryTotal();
      double Acc[2000];
      
      Acc[0] = AccountBalance();
      

        for(int i=1;i<=hstTotal;i++)

          {
           //---- check selection result
           if(OrderSelect(i,SELECT_BY_TICKET,MODE_TRADES)==false)
       
              break;
     
           else
              {

              //order is already selected no need to select it again
                Acc[i]= Acc[i-1]+ OrderProfit( ) ;

              
              }
           }
//followed by....
ArraySetAsSeries( Acc, true);

The fact is I do not still have the 100% of certainty.

Help...

SA

 

It is the same you just get the array from first to last indexed...try



      for(int i=hstTotal;i>=0;i--)
          {
           ......
 
Liliput wrote >>

It is the same you just get the array from first to last indexed...try


My Question remains open and my wishes unfulfilled. The problem is unresolved :-(

The question is reasonable simple: HOW TO GET AN ARRAY OF ACCOUNTBALANCE VALUES.

Thanks anyway for your attention,

SA