Help, on Trade Counter

 
int SellCount()
  {
   
   int No=0;
   int Total=0;
   int CurTicket=0;
   int LastTicket=0;

// if(OrdersTotal()>0 && OrderType()==OP_SELL && OrderMagicNumber()==Magic_Number_1)
//  {
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS)==true && OrderMagicNumber()==Magic_Number_1)
        {
         // CurOPenTime=OrderOpenTime();
         CurTicket=OrderTicket();

         if(OrderType()==OP_SELL && CurTicket!=LastTicket)  //&& CurOPenTime!=LastOpenTime
           {

            // if(OrderCloseTime()==CurOPenTime)
            LastTicket=CurTicket;
            No++;
           

           }
         // }

        }
     }
   return No;
  }

hello

 am working on a counter that increases only, when trade picked, and reset back only when OrdersTotal()==0

i.e counter should be 5 if i have 5 opened trades and should remain at 5 if 1 or more trades are closed.

if  i have 10 opened orders counter should read 10 and if 5 were closed counter should remain at 10 and if 2 more trades were opened counter should be at 12 (despite total orders are 7) and reset back to 0 (zero) when i have no opened orders


i tried some some functions but not working it reduces when some orders were closed, Here is a function for SELL orders only


thanks

 

Show the code that you have tried and maybe somebody can assist, use the code button (Alt+S) when pasting code.

Is this for MQL4 or 5 ?

 
Keith Watford:

Show the code that you have tried and maybe somebody can assist, use the code button (Alt+S) when pasting code.

Is this for MQL4 or 5 ?

i updated the trend 

its MQL4

thanks

 
Adebayo Samson Adewuyi:

i updated the trend 

its MQL4

What does " i updated the trend " mean?

I know that it is not obvious, but topics concerning MT4 and MQL4 have their own section.

In future please post in the correct section.

I will move your topic to the MQL4 and Metatrader 4 section.

 
Keith Watford:

What does " i updated the trend " mean?

I know that it is not obvious, but topics concerning MT4 and MQL4 have their own section.

In future please post in the correct section.

I will move your topic to the MQL4 and Metatrader 4 section.

thanks 

i appreciate that 

what i meant by have updated the trend is that i attached my code as you have suggested earlier on

 
Adebayo Samson Adewuyi:

hello

 am working on a counter that increases only, when trade picked, and reset back only when OrdersTotal()==0

i.e counter should be 5 if i have 5 opened trades and should remain at 5 if 1 or more trades are closed.

if  i have 10 opened orders counter should read 10 and if 5 were closed counter should remain at 10 and if 2 more trades were opened counter should be at 12 (despite total orders are 7) and reset back to 0 (zero) when i have no opened orders


i tried some some functions but not working it reduces when some orders were closed, Here is a function for SELL orders only


thanks

I think that you are going about it the wrong way.

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.

 
Keith Watford:

I think that you are going about it the wrong way.

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.

it reduces whenever some trades were closed, but i need it to retain its value 

 
Keith Watford:

I think that you are going about it the wrong way.

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.

Adebayo Samson Adewuyi:

it reduces whenever some trades were closed, but i need it to retain its value 

Read carefully and concentrate on what I have written. If you follow the logic the value will not reduce unless there are no open orders.

 
Keith Watford:

Read carefully and concentrate on what I have written. If you follow the logic the value will not reduce unless there are no open orders.

could you please explain better ?

 
Adebayo Samson Adewuyi:

could you please explain better ?

I think that it is totally clear. I don't know how I could explain it better.

 
Keith Watford:

I think that it is totally clear. I don't know how I could explain it better.

but its not working,

no Problem thanks for the reply, i will continue trying 

Reason: