Function to return OrderProfit()

Post Reply
User avatar
ROOI
Trader
Posts: 15
Joined: Thu Sep 19, 2013 2:49 pm

Function to return OrderProfit()

Post by ROOI »

Hi

Thank you for the time you take to read this

To start I am complete noob although I have started the learning process and have a rough understanding of most of the concepts.I am able use pre-written function with slight success and have founds a lot of very good functions here so I thank all involved for that.

My current problem is I am trying to get the value of the Profit of an open buy order.

Currently my code looks like this and I get one error and I was wondering if someone could give me push into the right direction.Thank you very much

Rooi
:D

Code: Select all

double Balance_of_open_buy()                                           
{
       for(int i=0;i<OrdersTotal();i++)
   
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderMagicNumber()==Magic_Number && OrderSymbol()==Symbol())
      
         if(OrderType()== OP_BUY) 
         return (OrderProfit());
      
}
Just thankful to be alive and to be able to learn. I'm a trader slowly learning to code and I apologize in advance for the stupid questions.I always try to find the answer myself before asking for help.
User avatar
milanese
TechAdmin
Posts: 3293
Joined: Wed Jan 09, 2013 9:02 am
Location: btr rdx, r8 +

Function to return OrderProfit()

Post by milanese »

Try this:

Code: Select all

double GetProfitPairBUY(string strSymbol, int nMagic)
  {
   double profit=0;
   
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(!OrderSelect(i,SELECT_BY_POS)) continue;
      if(OrderMagicNumber()!=nMagic) continue;
      if(OrderSymbol()!=strSymbol) continue;
      if(OrderType()==OP_BUY)

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

   return(profit);
  }
Cheers :)

Tommaso
Global Prime is the official SHF broker :yahoo:
Searching for Servers and Workstations with individual configuration?
Just PM
:smile: Click here to go to the BoardKnowledgeBase
NOTE: Cookies and JavaScript are required for the using the board, with full functionality
User avatar
ROOI
Trader
Posts: 15
Joined: Thu Sep 19, 2013 2:49 pm

Function to return OrderProfit()

Post by ROOI »

milanese » Sat Aug 01, 2015 8:33 am wrote:Try this:

Code: Select all

double GetProfitPairBUY(string strSymbol, int nMagic)
  {
   double profit=0;
   
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(!OrderSelect(i,SELECT_BY_POS)) continue;
      if(OrderMagicNumber()!=nMagic) continue;
      if(OrderSymbol()!=strSymbol) continue;
      if(OrderType()==OP_BUY)

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

   return(profit);
  }
Cheers :)

Tommaso
:yahoo:
Thank you very very much.I will try it

Rooi
:D
Just thankful to be alive and to be able to learn. I'm a trader slowly learning to code and I apologize in advance for the stupid questions.I always try to find the answer myself before asking for help.
User avatar
ROOI
Trader
Posts: 15
Joined: Thu Sep 19, 2013 2:49 pm

Function to return OrderProfit()

Post by ROOI »

Hi Tommaso

Thank you for your great help with the function

I wanted to see the result of the function you have genoursly helped me with so I wanted to use the Alert() and check the value of the profit on each tick but it doesn't compile and gives me the error : wrong parameters count

Am I trying to do something impossible or am I missing something small.

If it is something big please say so and I will go try and study some more about this in google

Once again I am very thankful for any pointers or help with this

Rooi
:D

Code: Select all

void OnTick()
  {
//---
     if(total_buy_orders()<=max_orders) // I have tested this statement and it works
     market_buy_order();         //  One buy opens and no more so the if-statement seems to work effectively 
     
     if(total_buy_orders()>=1)    // This statement works because I can use Alert on each tick when I use a constant but I want to Alert the Profit at each tick it doesn't
     Alert( GetProfitPairBUY());  // When I write it like this it says error " 'GetProfitPairBUY' - wrong parameters count	" 
Just thankful to be alive and to be able to learn. I'm a trader slowly learning to code and I apologize in advance for the stupid questions.I always try to find the answer myself before asking for help.
User avatar
milanese
TechAdmin
Posts: 3293
Joined: Wed Jan 09, 2013 9:02 am
Location: btr rdx, r8 +

Function to return OrderProfit()

Post by milanese »

ROOI » Sat Aug 01, 2015 9:20 am wrote:Hi Tommaso

Thank you for your great help with the function

I wanted to see the result of the function you have genoursly helped me with so I wanted to use the Alert() and check the value of the profit on each tick but it doesn't compile and gives me the error : wrong parameters count

Am I trying to do something impossible or am I missing something small.

If it is something big please say so and I will go try and study some more about this in google

Once again I am very thankful for any pointers or help with this

Rooi
:D

Code: Select all

void OnTick()
  {
//---
     if(total_buy_orders()<=max_orders) // I have tested this statement and it works
     market_buy_order();         //  One buy opens and no more so the if-statement seems to work effectively 
     
     if(total_buy_orders()>=1)    // This statement works because I can use Alert on each tick when I use a constant but I want to Alert the Profit at each tick it doesn't
     Alert( GetProfitPairBUY());  // When I write it like this it says error " 'GetProfitPairBUY' - wrong parameters count	" 
you have to call the function in this way:

GetProfitBUY(Symbol(),MagicNumber);

Cheers :)

Tommaso
Global Prime is the official SHF broker :yahoo:
Searching for Servers and Workstations with individual configuration?
Just PM
:smile: Click here to go to the BoardKnowledgeBase
NOTE: Cookies and JavaScript are required for the using the board, with full functionality
User avatar
ROOI
Trader
Posts: 15
Joined: Thu Sep 19, 2013 2:49 pm

Function to return OrderProfit()

Post by ROOI »

milanese » Sat Aug 01, 2015 10:48 am wrote:
ROOI » Sat Aug 01, 2015 9:20 am wrote:Hi Tommaso

Thank you for your great help with the function

I wanted to see the result of the function you have genoursly helped me with so I wanted to use the Alert() and check the value of the profit on each tick but it doesn't compile and gives me the error : wrong parameters count

Am I trying to do something impossible or am I missing something small.

If it is something big please say so and I will go try and study some more about this in google

Once again I am very thankful for any pointers or help with this

Rooi
:D

Code: Select all

void OnTick()
  {
//---
     if(total_buy_orders()<=max_orders) // I have tested this statement and it works
     market_buy_order();         //  One buy opens and no more so the if-statement seems to work effectively 
     
     if(total_buy_orders()>=1)    // This statement works because I can use Alert on each tick when I use a constant but I want to Alert the Profit at each tick it doesn't
     Alert( GetProfitPairBUY());  // When I write it like this it says error " 'GetProfitPairBUY' - wrong parameters count	" 
you have to call the function in this way:

GetProfitBUY(Symbol(),MagicNumber);

Cheers :)

Tommaso
:!!:

Was a bit tough in the in the start but found a work around.I knew there needed to be 2 inputs but could not figure it out.

Thank you very much.Now I can implement your nice code :good:

Enjoy your weekend

Rooi
:D
Just thankful to be alive and to be able to learn. I'm a trader slowly learning to code and I apologize in advance for the stupid questions.I always try to find the answer myself before asking for help.
Post Reply

Return to “Coders Hangout”