objective of this code
- place all available symbols in marketwatch in mt4 in an array
- loop through the array to heck buy/sell condition
- take new position only in the symbol which does not exist in open orders list
- take close decisions if buy/sell condition is false
i am completely new to mql4 so i have made certain mistakes, i need help in fixing these mistakes and making the code memory efficient
the code
#property copyright ""
#property link ""
#property version "1.00"
#property strict
double a;
double b;
double c;
double as;
double bs;
double cs;
bool cb=false;
bool sb=false;
bool aop=false;
bool buyCondition = false;
bool sellCondition = false;
int order=0;
bool check=false;
bool bop=false;
bool a2op=false;
bool a3op=false;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- create timer
EventSetTimer(60);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//--- destroy timer
EventKillTimer();
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
}
//+------------------------------------------------------------------+
//| Timer function |
//+------------------------------------------------------------------+
void OnTimer()
{
//---
for(int i=0;i<SymbolsTotal(true);i++)
{
if (buyC(SymbolName(i,true))==true && BT(SymbolName(i,true))==false)
{aop=OrderSend(SymbolName(i,true),OP_BUY,0.01,Ask,0,0,0,"",0,0,Green);}
if (sellC(SymbolName(i,true))==true && BT(SymbolName(i,true))==false)
{bop=OrderSend(SymbolName(i,true),OP_SELL,0.01,Bid,0,0,0,"",0,0,Green);}
if (buyC(SymbolName(i,true))==false && BT(SymbolName(i,true))==true) closeOrd(SymbolName(i,true));
if (sellC(SymbolName(i,true))==false && BT(SymbolName(i,true))==true) closeOrd(SymbolName(i,true));
}
}
//+------------------------------------------------------------------+
bool buyC(string s1)
{
a = iClose(s1,0,0);
b = iMA(s1,0,10,0,MODE_SMA,PRICE_CLOSE,0);
c = iRSI(s1,0,14,PRICE_CLOSE,0);
if (a > b && c > 50)
buyCondition = true;
return(buyCondition);
}
bool sellC(string s2)
{
as = iClose(s2,0,0);
bs = iMA(s2,0,10,0,MODE_SMA,PRICE_CLOSE,0);
cs = iRSI(s2,0,14,PRICE_CLOSE,0);
if (as < bs && cs < 50)
sellCondition = true;
return(sellCondition);
}
bool BT(string S)
{
for(int x=0;x<SymbolsTotal(true);x++)
{
if(OrderSelect(x,MODE_TRADES) && (S == OrderSymbol()))
check = true;
}
return(check);
}
void closeOrd(string symb)
{
for(int Y=0;Y<SymbolsTotal(true);Y++)
{
if(OrderSelect(Y,MODE_TRADES) && (symb == OrderSymbol()))
if (OrderType()==OP_BUY)
cb = OrderClose(OrderTicket(),OrderLots(),MarketInfo(symb,MODE_BID),Green);
if (OrderType()==OP_SELL)
sb = OrderClose(OrderTicket(),OrderLots(),MarketInfo(symb,MODE_ASK),Green);
}
}
i am completely new to mql4 so i have made certain mistakes, i need help in fixing these mistakes and making the code memory efficient
New contributor
Preet Kanwaljit Singh Gill is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.