how to make Global variable can be change at any Section

 
extern int Opp = 0;

void start()
  {
if(OrderSelect(SELECT_BY_POS,MODE_TRADES)==true)
   {
    if(
       MathFloor(OrderProfit()/OrderLots()/MarketInfo(OrderSymbol(),MODE_TICKVALUE)) < -50 &&
       OrdersTotal() == 1 &&
       OrderMagicNumber() == MAGICMA )
    {
     Opp = MathFloor(OrderProfit()/OrderLots()/MarketInfo(OrderSymbol(),MODE_TICKVALUE));
     Comment("Top Opposite points is : ",Opp);
     
     return(Opp);
    }
    return(0);
   }
if(OrderSelect(SELECT_BY_POS,MODE_TRADES)==true)
    {
     if(MathFloor(OrderProfit()/OrderLots()/MarketInfo(OrderSymbol(),MODE_TICKVALUE)) <= -30)
     {
      Opp = 0 ;
      return (Opp);
     }
     return(0);
    }
}

Dear's,

Kindly i need to know how to make global variable to change by any section as if trade between -3 to -5 Opp = 0 else put the lowest value of trade and put it in Opp



Please advice

BR

Semotallica

 

You need a Loop which gives you Positions before OrderSelect().

    for(i=OrdersTotal()-1; i>=0; i--){
        if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)){
 
Thanks Ubzen for your support but this not the issue the issue it i can't a sign a value for globe variable
 

What value do you get for:

Comment("Top Opposite points is : ",Opp);
And what do you think it should be?
 
  1. if(OrderSelect(SELECT_BY_POS,MODE_TRADES)==true)
    Bogus
  2. Can't use tick value by itself
 
semotallica:

Dear's,

Kindly i need to know how to make global variable to change by any section as if trade between -3 to -5 Opp = 0 else put the lowest value of trade and put it in Opp


It is not clear exactly what you mean but I have had a go below. Please note ubzen's comment that you have given the wrong parameters to the OrderSelect() function.

extern int Opp = 0;
int tradeMin= 123456789;

int start(){
   
   if( !OrderSelect(0,SELECT_BY_POS,MODE_TRADES) )
      return( 0 );
 
   // so we now have a valid selected order
   
   int trade = MathFloor( OrderProfit()/ (OrderLots()*MarketInfo(OrderSymbol(),MODE_TICKVALUE)) );
   
   if( tradeMin > trade )
       tradeMin = trade;
       
   if( trade >= -50 && trade <= -30 )
      Opp = 0;
   else
      Opp = tradeMin;
      
   return( 0 );
}
 
dabbler:

It is not clear exactly what you mean

I didn't understand either . . . so I didn't reply . . it occurs to me that returning anything from start is pretty much pointless though (especially when it is type void) . . . maybe the OP meant to use a different function name and this was meant to be a custom function . .
 
Many Thanks the problem was solved by your assisted and thanks for all for helping me :)dabbler
Reason: