Here you go. Hope this is helpful.. I know what it's like trying to learn this stuff. I was lost for a while too. I just started recording some videos and posting them on youtube to try and help someone. if you search for Mql4 lessons .. you will find them.... keep learning....
.......Trade Safely....
JimDandy.
//+------------------------------------------------------------------+//| Simple EA.mq4 |//| Copyright 2013, MetaQuotes Software Corp. |//| http://www.metaquotes.net |//+------------------------------------------------------------------+#property copyright "Copyright 2013, MetaQuotes Software Corp."#property link "http://www.metaquotes.net"//Literally copying Ferrus Format to a teeexternstring Label1="===General Trade Settings===";
externint TakeProfit=25;
externint StopLoss=10;
externint TrailingStop=0;
externint Slippage=2;
externdouble Lot=0.1;
//---------Time Filter--------//externstring Label5="===Moving Average Settings===";
externint MA_Period=200;
externint MA_Shift=0;
externint MA_Type=1;
externint MA_Price=0;
//-------Initialize EA Orders Accounting-----//int start()
{
//--------------Bar CHeck------//double EMA=iMA(NULL,PERIOD_M1,MA_Period,MA_Shift,MA_Type,MA_Price,0);
double BarClose;
BarClose=iClose(Symbol(),PERIOD_M1,0);
//---------Adjusting for every digit broker-------------//int mypoint;
if (Digits==3||Digits==5){ mypoint=10;}
else {mypoint=1;}
//------------Taking Trades----------//int total = OrdersTotal();
if(total<1)// You only want to check to open orders. If you have none open.
{ //Otherwise it will open an order on every tick...if(BarClose>EMA)
{
double SLB=Bid-StopLoss*Point*mypoint;
double TPB=Bid+TakeProfit*Point*mypoint;
int buy = OrderSend(Symbol(),0,Lot,Ask,Slippage,SLB,TPB);
//if order succeeds, int buy will be ticket number of order just placed.//if this was an ecn broker you can not send tp and sl along with order, you use zeros.//but if order succeeds .. you use the 'buy' (ticketnumber) of order just placed to select it then modify it.//if(buy>0)OrderSelect(buy,SELECT_BY_TICKET,MODE_TRADES) //select the order you just placed //OrderModify(OrderTicket(),OrderOpenPrice(),SLB,TPB,0,Green);//put in your SLB and TPBif(buy>0) Print("BUY order opened : ",OrderOpenPrice());//if ticket number exists. Print.elsePrint("Error opening BUY order : ",GetLastError());//otherwise get the error.
}
if(BarClose<EMA)
{
double SLS=Ask+StopLoss*Point*mypoint;
double TPS=Ask-TakeProfit*Point*mypoint;
int sell = OrderSend(Symbol(),1,Lot,Bid,Slippage,SLS,TPS);
if(sell>0) Print("SELL order opened : ",OrderOpenPrice());
elsePrint("Error opening BUY order : ",GetLastError());
}
}
//int err=GetLastError();You don't want this here it will run every tick.//Alert(err); Even if there is no error.return(0);
}
//+------------------------------------------------------------------+
I am currently viewing your webpages. So far, error 130 is still happening, so I will try to figure it out. Oanda is not an ECN, so I should be able to adjust the stops in the OrderSend().
If your Broker is not an ECN you caan send the TP & SL with the OrderSend() so you don't need to do the OrderModify(), you do need to make sure your SL isn't too close . . .
Yes it is larger than 10. Do you think it has something to do with my trade criteria? I just wanted to make an EA to get the hang of putting in stops but its proved to be a great learning opportunity.
Yes it is larger than 10. Do you think it has something to do with my trade criteria? I just wanted to make an EA to get the hang of putting in stops but its proved to be a great learning opportunity.
See Also
https://www.mql5.com/en/forum/143607 for how you can make ordersend / orderclose work as well for 4 as for 5 digit broker
If Bid is moving around EMA you will have open a lot of trades in a short period with each crossing
Here you go. Hope this is helpful.. I know what it's like trying to learn this stuff. I was lost for a while too. I just started recording some videos and posting them on youtube to try and help someone. if you search for Mql4 lessons .. you will find them.... keep learning....
.......Trade Safely....
JimDandy.
Also you might want to move that digit check into the init() function so that it does not run every tick.
int mypoint;Also you might want to move that digit check into the init() function so that it does not run every
Thank you for the input Jimdandy.
I am currently viewing your webpages. So far, error 130 is still happening, so I will try to figure it out. Oanda is not an ECN, so I should be able to adjust the stops in the OrderSend().
See Also
https://www.mql5.com/en/forum/143607 for how you can make ordersend / orderclose work as well for 4 as for 5 digit broker
If Bid is moving around EMA you will have open a lot of trades in a short period with each crossing
Thank you deVries, making those changes today.
If your Broker is not an ECN you caan send the TP & SL with the OrderSend() so you don't need to do the OrderModify(), you do need to make sure your SL isn't too close . . .
Read this: Requirements and Limitations in Making Trades what is your Stoplevel ? is it greater than 10 ?
what is your Stoplevel ? is it greater than 10 ?
what is your Stoplevel ? is it greater than 10 ?
Hey RaptorUK:
Yes it is larger than 10. Do you think it has something to do with my trade criteria? I just wanted to make an EA to get the hang of putting in stops but its proved to be a great learning opportunity.
Hey RaptorUK:
Yes it is larger than 10. Do you think it has something to do with my trade criteria? I just wanted to make an EA to get the hang of putting in stops but its proved to be a great learning opportunity.
As I said before . . .
Read this: Requirements and Limitations in Making Trades
Your SL and TP have to be further away from the entry price than the Stoplevel.
With a Stoplevel of greater than 10 your SL is bad, with a Stoplevel greater than 25 your TP is also bad.