How do I double volume when balance doubles?

 

I want to double the volume as soon as balance doubles, I tried the following code OnTick but it doesn't change the volume even after balance is over 20000. I also understand that this code will keep on adding 2.5 to the volume every tick as long as balance stays above 20000. 

How do I write the code to achieve what I stated? Thank you in advance. 

   double balance=AccountInfoDouble(ACCOUNT_BALANCE);  
   if (balance > 20000)
     {
      VL = (VL + 2.5);
     }
 
I cannot tell how or where VL is declared or defined, but it would need the type specifier static to keep it's value over the turn of a function call.

So either it is locally defined, or it is within the global namespace.

Search the docs for "static" variables.
 
Dominik Egert:
I cannot tell how or where VL is declared or defined, but it would need the type specifier static to keep it's value over the turn of a function call.

So either it is locally defined, or it is within the global namespace.

Search the docs for "static" variables.

VL is defined globally, I set it as static but still it remains unchanged even after balance doubles. If a variable is defined globally and given a value globally can it not be changed? as it will revert to its globally defined value?

 
35117153:

I want to double the volume as soon as balance doubles, I tried the following code OnTick but it doesn't change the volume even after balance is over 20000. I also understand that this code will keep on adding 2.5 to the volume every tick as long as balance stays above 20000. 

How do I write the code to achieve what I stated? Thank you in advance. 

your code is true and should work!

extern double VL=0.1;
void OnTick()
   {

   double balance=AccountInfoDouble(ACCOUNT_BALANCE); 
   if(balance>20000)
	VL*=2;
   }

try this one

i checked and its working

 
Mohsen Bjp:

your code is true and should work!

try this one

i checked and its working

or 

VL+=2.5;

and dont forget OnTick() function

 
Mohsen Bjp:

your code is true and should work!

try this one

i checked and its working

I found a much better way to do this using a while loop. The following code upsizes by executing the same trade again for each time the balance increases by 10000. It also automatically downsizes by not executing the trades if balance lowers.

void UpsizingLONG()
{
double balance=AccountInfoDouble(ACCOUNT_BALANCE);
double BID=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
double ASK=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
     
     while(balance > 20000)
     {
     balance = (balance-10000);
     trade.Buy(buyorderVL,_Symbol,ASK,ASK - buyorderSL,ASK + buyorderTP);
    
     }
                
}
 
35117153:

I found a much better way to do this using a while loop. The following code upsizes by executing the same trade again for each time the balance increases by 10000. It also automatically downsizes if balance lowers.

***

Please insert the code correctly: when editing a message, press the button   Codeand paste your code into the pop-up window.