Increasing lot size when current order is in negative profit.

 

Hello guys.


Iam trying to achieve increasing lot size for future order (long or short) when current order (long or short) is in negtavie profit. There can be maximum of two current orders in the same time.

I've got so far:

double LotSize=0.01;
bool CanOpenBuy=true;
bool CanOpenSell=true;

void OrdersOpen(){

   for( int i = 0 ; i < OrdersTotal() ; i++ ) {
      if( OrderSelect( i, SELECT_BY_POS, MODE_TRADES ) == false ) {
         Print("ERROR - Unable to select the order - ",GetLastError());
         break;
      }
      if( (OrderSymbol()==Symbol()) && (OrderType() == OP_BUY)){ CanOpenBuy=false;CanOpenSell=true;
                                 if(OrderProfit()<0){LotSize=0.02;}   
            }
      if( (OrderSymbol()==Symbol()) && (OrderType() == OP_SELL)){ CanOpenSell=false; CanOpenBuy=true;
                                 if(OrderProfit()<0){LotSize=0.02;} 
            }
       
   }
   return;
}

I do not know why, but increasing LotSize in this condition does not work. When I tried to print some string instead of increasing LotSize in same condition (OrderProfit()<0), it worked fine.
Why is the change LotSize value completly ignored?

And yes, I know martingale, there is no need to comment this "strategy". Just need to solve written above.

Thank you very much.

 
ramp:

Hello guys.


Iam trying to achieve increasing lot size for future order (long or short) when current order (long or short) is in negtavie profit. There can be maximum of two current orders in the same time.

I've got so far:

I do not know why, but increasing LotSize in this condition does not work. When I tried to print some string instead of increasing LotSize in same condition (OrderProfit()<0), it worked fine.
Why is the change LotSize value completly ignored?

And yes, I know martingale, there is no need to comment this "strategy". Just need to solve written above.

Thank you very much.

I have a question about your code: why is there a "return" statement at the end of the OrdersOpen() function? You are not returning any value, so I was wondering what its purpose is.
 
WindmillMQL:
I have a question about your code: why is there a "return" statement at the end of the OrdersOpen() function? You are not returning any value, so I was wondering what its purpose is.
Aaaaaahhh... Thank you man. It seems not to be good coding a long time, I cannot see simply basics then... :/ 

Already solved