Your code can be drastically reduced by using an array
First though, what is the point of all the ok1, ok2 etc? They are intermediate variables that are not used anywhere else
//--- input parametersexternint magicnumber=1202;
double BuyArray[71]; //Array index is 0 to 70string GV_Name="newvaluezynga";
//+------------------------------------------------------------------+//| Expert initialization function |//+------------------------------------------------------------------+intOnInit()
{
for(int x=0;x<70;x++)
{
BuyArray[x]=GlobalVariableGet(GV_Name+(string)x);
}
//---return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| Expert deinitialization function |//+------------------------------------------------------------------+voidOnDeinit(constint reason)
{
//---
}
//+------------------------------------------------------------------+//| Expert tick function |//+------------------------------------------------------------------+voidOnTick()
{
int BuyCnt=0;
int SellCnt=0;
int BuyStopCnt=0;
int SellStopCnt = 0;
int BuyLimitCnt = 0;
int SellLimitCnt= 0;
int cnt=OrdersTotal();
for(int i=0; i<cnt; i++)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
if(OrderSymbol()!=Symbol()) continue;
if(OrderMagicNumber()!=magicnumber) continue;
int type= OrderType();
if(type == OP_BUY) BuyCnt++;
if(type == OP_SELL) SellCnt++;
if(type == OP_BUYSTOP) BuyStopCnt++;
if(type == OP_SELLSTOP) SellStopCnt++;
if(type == OP_BUYLIMIT) BuyLimitCnt++;
if(type == OP_SELLLIMIT) SellLimitCnt++;
}
if(BuyCnt==0)
{
//Code to open initial orderdouble value;// Calculated value that needs to be stored in the array and Global Variable
BuyArray[1]=value;
GlobalVariableSet(GV_Name+(string)1,value);
}
else
{
OpenBuy(BuyCnt+1);
}
//---
}
//+------------------------------------------------------------------+void OpenBuy(int index)
{
double previous_value=BuyArray[index-1];
//Code to open orderdouble value;// Calculated value that needs to be stored in the array and Global Variable
BuyArray[index]=value;
GlobalVariableSet(GV_Name+(string)index,value);
}
//+------------------------------------------------------------------+
I didn't check, but I think that all trades after the initial trade follow the same logic, so only 1 function is required
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
To reduce the lines is indeed what i want.
And i am sorry that i wasn't clear about that.
Your code can be drastically reduced by using an array
First though, what is the point of all the ok1, ok2 etc? They are intermediate variables that are not used anywhere else
I didn't check, but I think that all trades after the initial trade follow the same logic, so only 1 function is required
Gumrai
thank you for your time.
This is new for me working with array so i try to let the program to run.
again thanks a lot
For some of this code block, where you are trying to see order type, you can also use switch/case logic.