I can imagine that you are getting a LOT of unwanted prints
if(previousfast<previousslow && currentfast>currentslow)
//^buy
ticket1 = OrderSend(Symbol(),OP_BUY,lotsize,Ask,3,Ask-(stoploss),Ask+(takeprofit),"EA Jim Dandy MA Trade",magicnumber,0,Green);
if(ticket1<0)
Print("Order Failed #",GetLastError());
else
Print("Order success1");
You have to put in the brackets
if(previousfast<previousslow && currentfast>currentslow)
//^buy
{
ticket1=OrderSend(Symbol(),OP_BUY,lotsize,Ask,3,Ask-(stoploss),Ask+(takeprofit),"EA Jim Dandy MA Trade",magicnumber,0,Green);
if(ticket1<0)
Print("Order Failed #",GetLastError());
else
Print("Order success1");
}
otherwise this will be executed every tick
if(ticket1<0)
Print("Order Failed #",GetLastError());
else
Print("Order success1");
Keith Watford:
if(previousfast<previousslow && currentfast>currentslow)
//^buy
ticket1 = OrderSend(Symbol(),OP_BUY,lotsize,Ask,3,Ask-(stoploss),Ask+(takeprofit),"EA Jim Dandy MA Trade",magicnumber,0,Green);
if(ticket1<0)
Print("Order Failed #",GetLastError());
else
Print("Order success1");
if(previousfast<previousslow && currentfast>currentslow)
//^buy
{
ticket1=OrderSend(Symbol(),OP_BUY,lotsize,Ask,3,Ask-(stoploss),Ask+(takeprofit),"EA Jim Dandy MA Trade",magicnumber,0,Green);
if(ticket1<0)
Print("Order Failed #",GetLastError());
else
Print("Order success1");
}
if(ticket1<0)
Print("Order Failed #",GetLastError());
else
Print("Order success1");Also you don't seem to have anything in your code to only check on a new bar.
thanks man, could you suggest code to only check new bar?
I can imagine that you are getting a LOT of unwanted prints
if(previousfast<previousslow && currentfast>currentslow)
//^buy
ticket1 = OrderSend(Symbol(),OP_BUY,lotsize,Ask,3,Ask-(stoploss),Ask+(takeprofit),"EA Jim Dandy MA Trade",magicnumber,0,Green);
if(ticket1<0)
Print("Order Failed #",GetLastError());
else
Print("Order success1");
You have to put in the brackets
if(previousfast<previousslow && currentfast>currentslow)
//^buy
{
ticket1=OrderSend(Symbol(),OP_BUY,lotsize,Ask,3,Ask-(stoploss),Ask+(takeprofit),"EA Jim Dandy MA Trade",magicnumber,0,Green);
if(ticket1<0)
Print("Order Failed #",GetLastError());
else
Print("Order success1");
}
otherwise this will be executed every tick
if(ticket1<0)
Print("Order Failed #",GetLastError());
else
Print("Order success1");
ReillyFox:
thanks man, could you suggest code to only check new bar?
thanks man, could you suggest code to only check new bar?
static datetime BarTime=0;
datetime now_bar=Time[0];
if(BarTime!=now_bar)
{
BarTime=now_bar;
//new_bar=true;
//Put code here that only needs to be executed when a new bar opens
}

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Made a simple moving average cross over ea.
2 things;
It only makes sell trades.
I dont know how to add in a maximum open trades code.
Please help.
Here is the code for it only making sells.
can supply full ea if needed
void OnTick()
{
//---
double previousfast = iMA(NULL,0,fastma,fastmashift,fastmamethod,fastmaappliedto,2);
double currentfast = iMA(NULL,0,fastma,fastmashift,fastmamethod,fastmaappliedto,1);
//^(NULL=moving average on the current currency pair. 0=the current timeframe. fastma= the moving average period.
double previousslow = iMA(NULL,0,slowma,slowmashift,slowmamethod,slowmaappliedto,2);
double currentslow = iMA(NULL,0,slowma,slowmashift,slowmamethod,slowmaappliedto,1);
if(previousfast<previousslow && currentfast>currentslow)
//^buy
ticket1 = OrderSend(Symbol(),OP_BUY,lotsize,Ask,3,Ask-(stoploss),Ask+(takeprofit),"EA Jim Dandy MA Trade",magicnumber,0,Green);
if(ticket1<0)
Print("Order Failed #",GetLastError());
else
Print("Order success1");
if (previousfast>previousslow && currentfast<currentslow)
//^sell
ticket2 = OrderSend(Symbol(),OP_SELL,lotsize,Bid,3,Bid+(stoploss),Bid-(takeprofit),"EA Jim Dandy MA Trade",magicnumber,0,Red);
if(ticket2<0)Print("Order Failed #",GetLastError());
else
Print("Order success2");
}