Help, on Trade Counter - page 3

 
Adebayo Samson Adewuyi:
No solution yet  programmers your assistance is needed plz am so stuck on this

You have been told the solution.

Keith Watford:

You should have a globalscope or static variable to count the trades and set it to 0 initially (or the value of  OrdersTotal()).

Whenever a new trade is opened increase the counter by 1.

If   OrdersTotal()==0 reset it to 0.

but you say that it is too difficult to understand.

I am unable to see how it could be explained in a simpler way.

 
Keith Watford:

You have been told the solution.

but you say that it is too difficult to understand.

I am unable to see how it could be explained in a simpler way.

okay, thanks for been trying to help.

let me explain all over again what i did and maybe you can probably point out where am getting wrong. i will explein and give the code

firstly i have a global variable "limit" which i set to 0(Zero) i.e "int  Limit=0;

then  i did a function to count only sell orders "CountSell" only, am tryin to count Position types differently so am using "SELL" to get the correct code then ill do for BUY later


so below is just the variable and the function  only, just to save long pasting of entire codes since that's where am having the issue,

this is just how I fully understand your explanations you can help correct if am not getting it right

thanks

int Limit=0;






//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

int CountSell()

  {
    Limit=0;
    int i;
   for( i=0; i<=OrdersTotal(); i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         if(OrderMagicNumber()==Magic_Number_1 &&  OrderSymbol()==Symbol() && OrderType()==OP_SELL)
             Limit++;
     }

   return Limit;
  }
//+------------------------------------------------------------------+
 
Adebayo Samson Adewuyi:

firstly i have a global variable "limit" which i set to 0(Zero) i.e "int  Limit=0;

then  i did a function to count only sell orders "CountSell" only, am tryin to count Position types differently so am using "SELL" to get the correct code then ill do for BUY later

Where did I say to count sell( or buy) orders?

Keith Watford:

You should have a globalscope or static variable to count the trades and set it to 0 initially (or the value of  OrdersTotal()).

Whenever a new trade is opened increase the counter by 1.

If   OrdersTotal()==0 reset it to 0.


Whenever your EA opens a trade, increase the counter
 
Keith Watford:

Where did I say to count sell( or buy) orders?

Whenever your EA opens a trade, increase the counter

I will surely need to differentiate order types for the project am running that's why am implementing that from scratch so i wont have further issues when it comes to that.

 

Here is a very simple code

void OnTick()
  {

   static int counter = 0;
   counter=MathMax(counter,OrdersTotal());
   if(OrdersTotal()==0)
      counter=0;
//---
  }
 
Keith Watford:

Here is a very simple code

Thanks a bunch, your code works perfectly. Thanks once again

counter is now very okay.

i was hoping the counter will solve my main program issue  and now its clear  i need to look for another solution, but i learnt something new and thanks to you for that its a progress towards my goal

 
Adebayo Samson Adewuyi:

Thanks a bunch, your code works perfectly. Thanks once again

counter is now very okay.

i was hoping the counter will solve my main program issue  and now its clear  i need to look for another solution, but i learnt something new and thanks to you for that its a progress towards my goal

It's a simple code, but it may not work perfectly in all cases.

eg. if between calls a trade is closed and a new one is opened, OrdersTotal() will have the same value and the new trade will not be counted.

That is why in my earlier solution, the counter is incremented when a new trade is opened.

 
Keith Watford:

It's a simple code, but it may not work perfectly in all cases.

eg. if between calls a trade is closed and a new one is opened, OrdersTotal() will have the same value and the new trade will not be counted.

That is why in my earlier solution, the counter is incremented when a new trade is opened.

yeah i think that's where the problem is

Reason: