Many thanks for your help with this code. My script code now looks like this (I added the changes in red just for this reply, the code in MQ4 looks just like the rest that was there):
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.
this is wrong : if(totalOrders==0 && Magic==OrderMagicNumber() &&
OrderSelect(i-1 , SELECT_BY_POS,MODE_HISTORY)==true)
because you are calling OrderMagicNumber() before OrderSelect(), so it probably refers to the previous call.
Oh,sorry I've wronlgy express my opinion.
I want to code (but I'm not able to do) something that will stop EA trading (or part of ea trading) if the equity is under a value.
Thanks for your help Roger09, but I don't need to display rhe equity on the chartTry this EA
CloseAllBuySell - MQL4 Code Base
Use its idea and make a code with something as
if (AccountEquity()<YourValue) closeallorders();
Could somebody please add the EMA trailing stop to the sample Moving Average EA
EMA trailing set to 1
Then change the entry to
Buy=Open[1]>ma && Close[1]>ma;
Sell=Open[1]<ma && Close[1]<ma;
This should make a very good simple scalper.
Cheers
Beno
Add at the beginning of program
extern int pips=2;//(or your number of pips)
then replace
sl = OrderOpenPrice() ;
if ((OrderType() == OP_SELL) && (OrderStopLoss() > OrderOpenPrice()))
sl = OrderOpenPrice() ;[/CODE]
to
[CODE]if ((OrderType() == OP_BUY) && (OrderStopLoss() < OrderOpenPrice()))
sl = OrderOpenPrice() +pips*Point;
if ((OrderType() == OP_SELL) && (OrderStopLoss() > OrderOpenPrice()))
sl = OrderOpenPrice() -pips*Point;Can someone help me put an alert into this indicator for when it draws a new arrow?
Thanks!
No, fix it
extern int pips=2;
//+------------------------------------------------------------------+
//| script program start function |
//+------------------------------------------------------------------+
int start()
{
//----
string curr = Symbol();
int ot = OrdersTotal();
int ords[200], ordType[200], ordTicket[200]; double ordLots[200];
string ordComments[200];
int ix=0;
for (int i=0; i<ot; i++)
{
int o = OrderSelect(i, SELECT_BY_POS);
if (OrderSymbol() == Symbol())
if ((OrderType() == OP_BUY) || (OrderType() == OP_SELL))
{
double sl = 0;
if ((OrderType() == OP_BUY) && (OrderStopLoss() < OrderOpenPrice()))
sl = OrderOpenPrice() +pips*Point;
if ((OrderType() == OP_SELL) && (OrderStopLoss() > OrderOpenPrice()))
sl = OrderOpenPrice() -pips*Point;
if (sl != 0+10)
OrderModify(OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), 0);
}
}
//----
return(0);
OK, code now looks like this:
extern int pips=10;//
//+------------------------------------------------------------------+
//| script program start function |
//+------------------------------------------------------------------+
int start()
{
//----
string curr = Symbol();
int ot = OrdersTotal();
int ords[200], ordType[200], ordTicket[200]; double ordLots[200];
string ordComments[200];
int ix=0;
for (int i=0; i<ot; i++)
{
int o = OrderSelect(i, SELECT_BY_POS);
if (OrderSymbol() == Symbol())
if ((OrderType() == OP_BUY) || (OrderType() == OP_SELL))
{
double sl = 0;
if ((OrderType() == OP_BUY) && (OrderStopLoss() < OrderOpenPrice()))
sl = OrderOpenPrice() +pips*Point;
if ((OrderType() == OP_SELL) && (OrderStopLoss() > OrderOpenPrice()))
sl = OrderOpenPrice() -pips*Point;
if (sl != 0)
OrderModify(OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), 0);
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
Hi Roger09,
Many thanks for your help with this code. My script code now looks like this (I added the changes in red just for this reply, the code in MQ4 looks just like the rest that was there):
//+------------------------------------------------------------------+
//| script program start function |
//+------------------------------------------------------------------+
int start()
{
//----
extern int pips=2;//
string curr = Symbol();
int ot = OrdersTotal();
int ords[200], ordType[200], ordTicket[200]; double ordLots[200];
string ordComments[200];
int ix=0;
for (int i=0; i<ot; i++)
{
int o = OrderSelect(i, SELECT_BY_POS);
if (OrderSymbol() == Symbol())
if ((OrderType() == OP_BUY) || (OrderType() == OP_SELL))
{
double sl = 0;
if ((OrderType() == OP_BUY) && (OrderStopLoss() < OrderOpenPrice()))
sl = OrderOpenPrice() +pips*Point;
if ((OrderType() == OP_SELL) && (OrderStopLoss() > OrderOpenPrice()))
sl = OrderOpenPrice() -pips*Point;
if (sl != 0)
OrderModify(OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), 0);
}
}
//----
return(0);
Can you let me know if I've got it right? I'm flying blind here so bear with me.
Actually it will be working, but this code isn't good. Unfortunately I don't know your main goals and can't recommend something else.