How to code? - page 144 1...137138139140141142143144145146147148149150151...346 New comment Michel 2008.11.12 16:40 #1431 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. Roger09 2008.11.12 17:54 #1432 EBK: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 chart Try this EA CloseAllBuySell - MQL4 Code Base Use its idea and make a code with something as if (AccountEquity()<YourValue) closeallorders(); Beno 2008.11.15 15:25 #1433 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 Files: ematrailingstop_v1.mq4 5 kb Ask! Moving Average MA entry MA close [Deleted] 2008.11.16 00:58 #1434 Roger09 2008.11.16 18:29 #1435 Add at the beginning of program extern int pips=2;//(or your number of pips) then replace if ((OrderType() == OP_BUY) && (OrderStopLoss() < OrderOpenPrice())) 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; [Deleted] 2008.11.17 18:28 #1436 Can someone help me put an alert into this indicator for when it draws a new arrow? Thanks! Files: hilow3.mq4 2 kb Roger09 2008.11.18 00:44 #1437 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); Coding help need some help with Exit Strategy: Stepping Stops [Deleted] 2008.11.18 02:36 #1438 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); } //+------------------------------------------------------------------+ Coding help need some help with Exit Strategy: Stepping Stops [Deleted] 2008.11.18 02:37 #1439 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. Coding help trailingstop Moving Stop to Breakeven Roger09 2008.11.18 05:31 #1440 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. 1...137138139140141142143144145146147148149150151...346 New comment
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.