I am a newbie, so please forgive me if my questions are very elementary.
I am writing a function that will scan all open orders and if conditions are met, for each of them opens an hedge grid every "x" pips (i.e. if I have a buy order, it creates SellStop orders every "x" pips).
The grid is opened correctly, BUT, everytime, altready processed orders are taken in account, so it creates again an hedge grid.
I put a LastCoverageLong variable that stores the OpenOrderTime of last processed orders, and I check it when selection the orders to cover, but it get reset at the begin of the function... I can't understand why.
can you please help?
thanks a lot
void ApriReteCopertura(double argSizeHedgePerc,int argAmpiezzaGriglia)
if(OrderOpenTime()>LastCoperturaLong ) //HERE I CHECK THE ORDER OPEN TIME WITH THE LAST TIME OF COVERAGE, LastCoperturaLong is set to initial value
Alert("In entrata OPT ",OrderOpenTime()," Last ",LastCoperturaLong);
double SizeHedge=NormalizeDouble(((OrderLots()*argSizeHedgePerc)/100),2); //to do: sistemare i digit dei lotti
double OpPr = OrderOpenPrice()-d*argAmpiezzaGriglia*UsePoint;
double SL = OpPr+argAmpiezzaGriglia*UsePoint;
double TP = OpPr-argAmpiezzaGriglia*UsePoint;
string Comm=StringConcatenate("Rete per ",OrderTicket());
//Alert("range: ", zNormalize(OrderOpenPrice()-OrderStopLoss())," quanti ", quanti, " SizeHedge ", +SizeHedge," Apertura: ", OpPr, " SL: ", SL, " TP: ", TP);
} //fine del FOR
LastCoperturaLong=OrderOpenTime(); //HERE I UPDATE THE LastCoperturaLong with the OpenTime of last processed order...
Alert("in uscita ","OPT ",OrderOpenTime()," Last ",LastCoperturaLong);
} //fine funzione ApriReteCopertura
local variable is reset at the end on function loop.
yes, that is exactly what is happening. so what should I do to prevent this? how to define and manage it as global variable?
If I define as global variable, should I pass it to the function when call it? and should the function return back a value?
just to let you know, I solved using globlal variable, passing it to the function and expecting back a datetime result that is stored in the global variable.
this is working now, thanks