Following your suggestion no the EA is opening buy and sell orders, and it's closing them normally,
the only problem is that is loosing money :-D
this is the EA, it's missing a good managing, I'me using only the PRICE_OPEN cross with EMA1 at 9 days
//+------------------------------------------------------------------+//| EMA.mq4 |//| Copyright 2013, MetaQuotes Software Corp. |//| http://www.metaquotes.net |//+------------------------------------------------------------------+#property copyright "Copyright 2013, MetaQuotes Software Corp."#property link "http://www.metaquotes.net"externdouble Lots = 0.1;
double EMA1;
double EMA2;
double EMA3;
int i;
int Ticket;
int TicketNumber;
int MagicNo = 12345;
int PositionIndex; // <-- this variable is the index used for the loopint TotalNumberOfOrders; // <-- this variable will hold the number of orders currently in the Trade poolint Slippage= 3;
// int Counted_bars; // Êîëè÷åñòâî ïðîñ÷èòàííûõ áàðîâ //+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+int start()
{
Print(OrdersTotal());
//--------------------------------------------------------------------// Counted_bars=IndicatorCounted(); // Êîëè÷åñòâî ïðîñ÷èòàííûõ áàðîâ // i=Bars-Counted_bars-1; // Èíäåêñ ïåðâîãî íåïîñ÷èòàííîã// while(i>=0) // Öèêë ïî íåïîñ÷èòàííûì áàðà// {
EMA1 = iMA(NULL, 0, 9, 0, MODE_EMA, PRICE_MEDIAN, 0);
EMA2 = iMA(NULL, 0, 27, 0, MODE_EMA, PRICE_MEDIAN, 0);
// EMA3 = iMA(NULL, 0, 50, 0, MODE_EMA, PRICE_MEDIAN, 0); // i--; // Ðàñ÷¸ò èíäåêñà ñëåäóþùåãî áàðà// }//-----section for close the orders -----------------------
TotalNumberOfOrders = OrdersTotal();
if((PRICE_OPEN<EMA1)){
// Print("TotalNumberOfOrders is "+TotalNumberOfOrders);for(PositionIndex = TotalNumberOfOrders - 1; PositionIndex >= 0 ; PositionIndex --) // <-- for loop to loop through all Orders . . COUNT DOWN TO ZERO !
{
if( ! OrderSelect(PositionIndex, SELECT_BY_POS, MODE_TRADES) ) continue; // <-- if the OrderSelect fails advance the loop to the next PositionIndexif( OrderMagicNumber() == MagicNo && OrderSymbol() == Symbol() && ( OrderType() == OP_BUY ) ) // <-- or is it a Sell Order ?if ( ! OrderClose( OrderTicket(), OrderLots(), OrderClosePrice(), Slippage ) ) // <-- try to close the orderPrint("Order Close failed, order number: ", OrderTicket(), " Error: ", GetLastError() ); // <-- if the Order Close failed print some helpful information
} // end of For loop
}
if((PRICE_OPEN>EMA1)){
TotalNumberOfOrders = OrdersTotal(); // <-- we store the number of Orders in the variable// Print("TotalNumberOfOrders is "+TotalNumberOfOrders);for(PositionIndex = TotalNumberOfOrders - 1; PositionIndex >= 0 ; PositionIndex --) // <-- for loop to loop through all Orders . . COUNT DOWN TO ZERO !
{
if( ! OrderSelect(PositionIndex, SELECT_BY_POS, MODE_TRADES) ) continue; // <-- if the OrderSelect fails advance the loop to the next PositionIndexif( OrderMagicNumber() == MagicNo && OrderSymbol() == Symbol() && ( OrderType() == OP_SELL ) ) // <-- or is it a Sell Order ?if ( ! OrderClose( OrderTicket(), OrderLots(), OrderClosePrice(), Slippage ) ) // <-- try to close the orderPrint("Order Close failed, order number: ", OrderTicket(), " Error: ", GetLastError() ); // <-- if the Order Close failed print some helpful information
} // end of For loop
}
//--------------------------------------------------//-----section for open the orders------------------------------------
TotalNumberOfOrders = OrdersTotal();
if(TotalNumberOfOrders==0){
// Print("TotalNumberOfOrders is "+TotalNumberOfOrders);if((PRICE_OPEN>EMA1))
{
TicketNumber=OrderSend(Symbol(), OP_BUY, Lots, Ask, 3,0,0, "EMA_CROSS", MagicNo, 0, Green);
if( TicketNumber > 0 )
{
Print("Order placed # ", TicketNumber + " Bought");
}
else
{
Print("Order Send failed, error # ", GetLastError() );
}
}
}
TotalNumberOfOrders = OrdersTotal();
if(TotalNumberOfOrders==0){
// Print("TotalNumberOfOrders is "+TotalNumberOfOrders);if((PRICE_OPEN<EMA1))
{
TicketNumber=OrderSend(Symbol(), OP_SELL, Lots, Bid, 3,0,0, "EMA_CROSS", MagicNo, 0, Red);
if( TicketNumber > 0 )
{
Print("Order placed # ", TicketNumber + " Sold");
}
else
{
Print("Order Send failed, error # ", GetLastError() );
}
}
}
return(0);
}
// the end.
after this simple EMA cross indicator and EA, I'm trying to translate in MQL4a type of Dorsey indicator,
I've trouble to use the iLow for select the low and lowest value of an array of a variable PB values.
iLow() ? have you read the documentation at all ? so your Symbol is 9 your timeframe is PB and your shift is 0 ??
symbol has to be a string, so 9 won't work, the timeframe has to be an int so PB won't work . . . 0 as the shift is OK
By the way, PB is not an array . . . you do have one array, BU and it's an int which you give double values . . .
BU[0]=BU[1]-BU[2]/3.414+(1/3.414)*PRICE_CLOSE;
. . . do you know what PRICE_CLOSE is ? it's zero . . . click here ---> PRICE_CLOSE
iLow() ? have you read the documentation at all ? so your Symbol is 9 your timeframe is PB and your shift is 0 ??
symbol has to be a string, so 9 won't work, the timeframe has to be an int so PB won't work . . . 0 as the shift is OK
By the way, PB is not an array . . . you do have one array, BU and it's an int which you give double values . . .
. . . do you know what PRICE_CLOSE is ? it's zero . . . click here ---> PRICE_CLOSE
You still haven't read the documentation for iLow() . . . the first parameter is a string and is the Symbol, what symbol is PB[0] ? PB[] is a double not a string . . . do you understand why this is never going to work ?
This is where your missing bracket is . . . all you need to do is count them . . .
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.
orderopening before opening a trade make TicketNumber = 0; otherwise your checking if a new trade opend is senseless
and some other things i can suggest
Following your suggestion no the EA is opening buy and sell orders, and it's closing them normally,
the only problem is that is loosing money :-D
this is the EA, it's missing a good managing, I'me using only the PRICE_OPEN cross with EMA1 at 9 days
You made it now a 2EMA cross
With 3 EMA lines you could follow the instructions of WHRoeder
about changing signal next tick you were using Price_Median
that is (High+Low) / 2 so changing signal on next tick is almost not happening
if your close rule was ok
this is how a chart looks like with 3 ema price_median periods you started
easily to see moments start EMA1 < EMA2 with EMA2 < EMA3 or moment EMA1 > EMA2 with EMA2 > EMA3
if you follow that in coding
then it could be your code is gonna look like .....
Is that necessary? If OrderSend succeeds, TicketNumber will == the ticket number, if it fails, Ticket number will == -1.
Your right about this
Only you get then people gonna do easily
TicketNumberBuy = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage*pips2points,0,0, "EMA_CROSS", MagicNo, 0, Green);
OrderClose( TicketNumberBuy, OrderLots(), OrderClosePrice(), Slippage*pips2points )) // you easily loose that value ( restarting pc )
and you can open only one buy that way...
with loop and orderselect it is not needed to know ticketnumber of your trades
after this simple EMA cross indicator and EA, I'm trying to translate in MQL4a type of Dorsey indicator,
I've trouble to use the iLow for select the low and lowest value of an array of a variable PB values.
after this simple EMA cross indicator and EA, I'm trying to translate in MQL4a type of Dorsey indicator,
I've trouble to use the iLow for select the low and lowest value of an array of a variable PB values.
iLow() ? have you read the documentation at all ? so your Symbol is 9 your timeframe is PB and your shift is 0 ??
symbol has to be a string, so 9 won't work, the timeframe has to be an int so PB won't work . . . 0 as the shift is OK
By the way, PB is not an array . . . you do have one array, BU and it's an int which you give double values . . .
. . . do you know what PRICE_CLOSE is ? it's zero . . . click here ---> PRICE_CLOSE
You need to read the Book . . .
iLow() ? have you read the documentation at all ? so your Symbol is 9 your timeframe is PB and your shift is 0 ??
symbol has to be a string, so 9 won't work, the timeframe has to be an int so PB won't work . . . 0 as the shift is OK
By the way, PB is not an array . . . you do have one array, BU and it's an int which you give double values . . .
. . . do you know what PRICE_CLOSE is ? it's zero . . . click here ---> PRICE_CLOSE
You need to read the Book . . .
instead of PRICE_CLOSE I need the Close price of the actual bar, and about the iLow function I've wrong the order of the fields,
I read bettere the book for modify the iLow, the PB into an array and for sostitute the PRICE_CLOSE with EURUSD Price on the Closed last bar.
I'm reading all the documentation about the arrays and about the array sorting,
the problem is focused into the "finding of the lowest and higher value of the last 9 values of the variable PB"
I understand that MQL give me parenthesis error because can't calulate the line:
this the error of compiler
'\end_of_program' - unbalanced left parenthesis C:\Program Files (x86)\XM MT4\experts\indicators\A.mq4 (59, 1)
You are using the buffers without [ ]
Does this default to [0] or not work?
You are using the buffers without [ ]
Does this default to [0] or not work?
it's giving me the same error also with [0]
it's giving me the same error also with [0]
You still haven't read the documentation for iLow() . . . the first parameter is a string and is the Symbol, what symbol is PB[0] ? PB[] is a double not a string . . . do you understand why this is never going to work ?
This is where your missing bracket is . . . all you need to do is count them . . .