Programming logic help - page 2

 
GumRai:

What speculation?

if you declare a variable in a function it will only be local to that function.

if you declare it before init() it can be accessed in all functions and will keep its value in between program runs.

I dont use any void, int or other types of secondary functions only the start(), it wont work for start neither because i have bunch of variables in init and they work fine?

Even before i was trying to implement this moving average strategy they worked fine.Actually they were not declared in the init they were declared outside any function only set their values in the init :D

 

Ok i resolved the issue, it was hard work.The solution is the following:

An auxiliary variable to which would have the same values as STATUS variable but would be overwritten earlier

And a BUYALLOW and SELLALLOW boolean

//outside all functions
bool BALLOW=false;
bool SALLOW=false;
string AUX="X";
  if(OrdersTotal()!=0){
  TotalNumberOfOrders = OrdersTotal();
for(PositionIndex = TotalNumberOfOrders - 1; PositionIndex >= 0 ; PositionIndex --)  // 
   {
   if( ! OrderSelect(PositionIndex, SELECT_BY_POS, MODE_TRADES) ) continue;   //
   
   if( OrderMagicNumber() == magic      
      && OrderSymbol() == Symbol()     )     
         //
{  

if(AUX=="B") SALLOW=true;

if(AUX=="S") BALLOW=true;

}}}

///////--------------------------------------==================================
if(OrdersTotal()==0){
  TotalNumberOfOrders = OrdersHistoryTotal();
for(PositionIndex = TotalNumberOfOrders - 1; PositionIndex >= 0 ; PositionIndex --)  // 
   {
   if( ! OrderSelect(PositionIndex, SELECT_BY_POS, MODE_HISTORY) ) continue;   //
   
   if( OrderMagicNumber() == magic      
      && OrderSymbol() == Symbol()     )     
         //
{  

if(AUX=="B") SALLOW=true;

if(AUX=="S") BALLOW=true;

}}}
//////////----------------------------------=========================================
if(OrdersHistoryTotal()==0){SALLOW=true;BALLOW=true;}
/////////---------------------------------------=====================================

and set the

SALLOW=false;

after putting the sell order and the

BALLOW=false;

after putting the buy

 
Proximus:

I dont use any void, int or other types of secondary functions only the start(), it wont work for start neither because i have bunch of variables in init and they work fine?

Even before i was trying to implement this moving average strategy they worked fine.Actually they were not declared in the init they were declared outside any function only set their values in the init :D

"Actually they were not declared in the init they were declared outside any function only set their values in the init :D"

Isn't that exactly what I have been saying in all my posts in this thread??

 

if you want local variables to retain their values make them static. You could have used static bool flags in the start() function.

 
SDC: if you want local variables to retain their values make them static.
And if you need them to reset on deinit/init cycle?
Reason: