forex software

Create and Test Forex Strategies

forex software

Skip to forum content

Forex Forum

Forex Software, Forex Strategies, Expert Advisors Generator

You are not logged in. Please login or register.


Forex Forum → Portfolio Expert → How to get Total History Profit from Portfolio ea?

Pages 1

You must login or register to post a reply

RSS topic feed

Posts: 8

Topic: How to get Total History Profit from Portfolio ea?

Hi,

how can i get the total Profit of an Portfolio EA?

On normal Eas this kind of code is working well.

double Total_History_Profit()
  {
   double totalhistoryprofit=0;
   int total=OrdersHistoryTotal();
   for(int i=0;i<total;i++)
     {
      if(OrderSelect(i,SELECT_BY_POS, MODE_HISTORY)==true)
        {
         if(OrderSymbol()==Symbol()&& OrderMagicNumber()==Magic_Number)
         if(OrderType()==OP_SELL || OrderType()==OP_BUY)
           {
            totalhistoryprofit+= OrderSwap()+OrderProfit();
           }
        }
     }
   return(totalhistoryprofit);
  }  

But cause Portfolio have different magicnumbers.. What did i have to put in this line instead of Magic_Number?

         if(OrderSymbol()==Symbol()&& OrderMagicNumber()==Magic_Number)

Re: How to get Total History Profit from Portfolio ea?

A Portfolio Expert opens positions with different Magic numbers for each included strategy.

We are currently developing a tool in EA Studio that will be able to calculate the stats form a particular date. It will help you for that case.

On the other hand, if you need to calculate the profit in the expert, you have to take into account all used magic numbers.

The positions' Magic Number calculation is:

int GetMagicNumber(int strategyIndex)
  {
   int magic=1000*Base_Magic_Number+strategyIndex;
   return (magic);
  }

The strategyIndex is from 0 to the count of the strategies - 1.

..

Now I think that probably adding trading info in the Portfolio Expert is a good idea. It may be like in the FSB Pro's experts and to plot on the chart something like:
Total strategies: 32
Long  positions count: 11, lots: 0.11, profit: 333
Short positions count: 03, lots: 0.03, profit: -24

3 (edited by deadlef 2018-09-28 19:26:01)

Re: How to get Total History Profit from Portfolio ea?

Popov wrote:

A Portfolio Expert opens positions with different Magic numbers for each included strategy.

We are currently developing a tool in EA Studio that will be able to calculate the stats form a particular date. It will help you for that case.

On the other hand, if you need to calculate the profit in the expert, you have to take into account all used magic numbers.

The positions' Magic Number calculation is:

int GetMagicNumber(int strategyIndex)
  {
   int magic=1000*Base_Magic_Number+strategyIndex;
   return (magic);
  }

The strategyIndex is from 0 to the count of the strategies - 1.

..

Now I think that probably adding trading info in the Portfolio Expert is a good idea. It may be like in the FSB Pro's experts and to plot on the chart something like:
Total strategies: 32
Long  positions count: 11, lots: 0.11, profit: 333
Short positions count: 03, lots: 0.03, profit: -24

yes i saw that this calculation. but when i try to implement it in my functions it gives me errors..
something lik GetMagicNumber() dont work on my process

we have to put the calculated magicnumber as global variable than it might be work.. but i dont know how to solve this..

Re: How to get Total History Profit from Portfolio ea?

hmm can nobody help out how i can get the calculated magicnumbers for that .. Cause when i change base magicnumber it also should be than in my Profit calculation.

i have tried that but dont work

         if(OrderSymbol()==Symbol()&& OrderMagicNumber()== GetMagicNumber());

Re: How to get Total History Profit from Portfolio ea?

You can check if a position magic number is from that portfolio expert by this way:

const int magicNumber = OrderMagicNumber();
if (1000 * Base_Magic_Number <= magicNumber && magicNumber < (1000 * Base_Magic_Number + 100))
 {
  // Do the things here
 }

Re: How to get Total History Profit from Portfolio ea?

Popov wrote:

You can check if a position magic number is from that portfolio expert by this way:

const int magicNumber = OrderMagicNumber();
if (1000 * Base_Magic_Number <= magicNumber && magicNumber < (1000 * Base_Magic_Number + 100))
 {
  // Do the things here
 }

I tried it out put your example like this in code.

double Total_History_Profit()
  {
   const int magicNumber = OrderMagicNumber();
   double totalhistoryprofit=0;
   int total=OrdersHistoryTotal();
   for(int i=0;i<total;i++)
     {
      if(OrderSelect(i,SELECT_BY_POS, MODE_HISTORY)==true)
        {
         if (1000 * Base_Magic_Number <= magicNumber && magicNumber < (1000 * Base_Magic_Number + 100))
         if(OrderSymbol()==Symbol())
         if(OrderType()==OP_SELL || OrderType()==OP_BUY)
           {
            totalhistoryprofit+= OrderSwap()+OrderProfit();
           }
        }
     }
   return(totalhistoryprofit);
  }  

also like this isnt working well.

double Total_History_Profit()
  {
   const int magicNumber = OrderMagicNumber();
   double totalhistoryprofit=0;
   int total=OrdersHistoryTotal();
   for(int i=0;i<total;i++)
     {
      if(OrderSelect(i,SELECT_BY_POS, MODE_HISTORY)==true)
        {
         if(OrderSymbol()==Symbol() && (1000 * Base_Magic_Number <= magicNumber && magicNumber < (1000 * Base_Magic_Number + 100)))
         if(OrderType()==OP_SELL || OrderType()==OP_BUY)
           {
            totalhistoryprofit+= OrderSwap()+OrderProfit();
           }
        }
     }
   return(totalhistoryprofit);
  }  

But i get the complete history Total Profit not only from the magicnumbers.
What about when i use portfolio 4 times. One Basic Magicnumber 400...one 401..one 402.. So if the code runs on basic numver 402 and the code is

(1000 * Base_Magic_Number <= magicNumber && magicNumber < (1000 * Base_Magic_Number + 100)

so when an has a smaller basenumber it will count all together.

Re: How to get Total History Profit from Portfolio ea?

Move  "const int magicNumber = OrderMagicNumber();" within the "if(OrderSelect(i,SELECT_BY_POS, MODE_HISTORY)==true)".

Like that:

   for(int i=0;i<total;i++)
     {
      if(OrderSelect(i,SELECT_BY_POS, MODE_HISTORY)==true)
        {
         const int magicNumber = OrderMagicNumber();
         if(OrderSymbol()==Symbol() && (1000 * Base_Magic_Number <= magicNumber && magicNumber < (1000 * Base_Magic_Number + 100)))

Re: How to get Total History Profit from Portfolio ea?

Popov wrote:

Move  "const int magicNumber = OrderMagicNumber();" within the "if(OrderSelect(i,SELECT_BY_POS, MODE_HISTORY)==true)".

Like that:

   for(int i=0;i<total;i++)
     {
      if(OrderSelect(i,SELECT_BY_POS, MODE_HISTORY)==true)
        {
         const int magicNumber = OrderMagicNumber();
         if(OrderSymbol()==Symbol() && (1000 * Base_Magic_Number <= magicNumber && magicNumber < (1000 * Base_Magic_Number + 100)))

Yes nice it works. Thank you..

Posts: 8

Pages 1

You must login or register to post a reply

Forex Forum → Portfolio Expert → How to get Total History Profit from Portfolio ea?

Similar topics in this forum