int open_orders() { int count = 0; for(int i=OrdersTotal()-1; i>=0; i--) // good habit to count down { if(!OrderSelect(i,SELECT_BY_POS)) continue; // select the order if(OrderSymbol() != _Symbol) continue; // optional check for same symbol if(OrderMagicNumber()!= magic_no) continue; // optional check for magic number if(OrderType() < 2) count++; // 0 == OP_BUY and 1 == OP_SELL } return(count); }
Marco: I tried your new update, but it doesnt make any trade, i put just the way you posted last, just removed the second int, in the ticket. But the first trade is never made on strategy tester, what to do now?
honest_knave: You are welcome. But do you agree the answer is rarely as simple as it seems? Which may explain some of the comments here CODE Help( Urgent).
i already removed that comment, a simple EA is a problem for me, i know nothing really to say something
Yes Mr Marco vd Heijden it works just like that from honest_knave, i tried again based on last code you dispose, worked great, i'll take both answers, and use your to this script as it is more similar to the original idea.
I believe, from the code you post, the EA wont open anymore order again. Unless u remove the EA from the chart, and reattached again (to initialize). I guess that was the purpose?
Hairi Baba: I believe, from the code you post, the EA wont open anymore order again. Unless u remove the EA from the chart, and reattached again (to initialize). I guess that was the purpose?
Now let's hope he picks the right direction :)
I read somewhere about a guy that forgot he still had an open position and guess what happened... $$$$$
Hairi Baba: I believe, from the code you post, the EA wont open anymore order again. Unless u remove the EA from the chart, and reattached again (to initialize). I guess that was the purpose?
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.
Yes sir, just 1 trade ever made, but your example was great, it will be very useful as base to create new eas
void OnTick()
{
double up = iIchimoku(NULL,5,9,26,52,3,0),
down = iIchimoku(NULL,5,9,26,52,4,0);
static bool was_above = true;
bool is_above = (MathMax(up,down)< Bid);
if(!trade_made && !was_above && is_above && open_orders()<1)
{
if(OrderSend(NULL,0,0.01,Ask,3, Bid-150*Point, Bid+100*Point)<0)
{
printf("OrderSend() failed. Error code: %i",GetLastError());
}
else trade_made=true;
}
was_above = is_above;
}
int open_orders()
{
int count = 0;
for(int i=OrdersTotal()-1; i>=0; i--) // good habit to count down
{
if(!OrderSelect(i,SELECT_BY_POS)) continue; // select the order
if(OrderSymbol() != _Symbol) continue; // optional check for same symbol
if(OrderMagicNumber()!= magic_no) continue; // optional check for magic number
if(OrderType() < 2) count++; // 0 == OP_BUY and 1 == OP_SELL
}
return(count);
}
Marco: I tried your new update, but it doesnt make any trade, i put just the way you posted last, just removed the second int, in the ticket. But the first trade is never made on strategy tester, what to do now?
It should place a trade because:
if (MathMax (up,down) < Bid )
ticket= OrderSend (NULL,0,0.01,Ask,3, Bid-150*Point, Bid+100*Point);
//| One Order.mq4 |
//| Copyright 2017, Marco vd Heijden, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, Marco vd Heijden, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
bool order=0;int ticket;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
if(order==0)
{
double up=iIchimoku(NULL,5,9,26,52,3,0);
double down=iIchimoku(NULL,5,9,26,52,4,0);
{
if(MathMax(up,down)<Bid)
{
ticket=OrderSend(NULL,0,0.01,Ask,3,Bid-150*Point,Bid+100*Point);
{
if(ticket>-1)
{
order=1;
}
}
}
}
}
}
//+------------------------------------------------------------------+
I just tried it and it placed ONE order...
Thanks a lot honest_knave that's exaclety what i needed, i'll be forever in debt,
thank you too Mr Marco for your help.
Thanks a lot honest_knave that's exaclety what i needed, i'll be forever in debt,
You are welcome. But do you agree the answer is rarely as simple as it seems? Which may explain some of the comments here CODE Help( Urgent).
i already removed that comment, a simple EA is a problem for me, i know nothing really to say something
Hey, we're all still learning. And your heart was in the right place.
I'm glad you fixed your problem.
There are many ways to do the same thing... Marco and I tackled the problem from different directions, and both are equally correct.
Good luck
Yes Mr Marco vd Heijden it works just like that from honest_knave, i tried again based on last code you dispose, worked great, i'll take both answers, and use your to this script as it is more similar to the original idea.
Thank you for your help
I believe, from the code you post, the EA wont open anymore order again. Unless u remove the EA from the chart, and reattached again (to initialize). I guess that was the purpose?
Now let's hope he picks the right direction :)
I read somewhere about a guy that forgot he still had an open position and guess what happened... $$$$$
I believe, from the code you post, the EA wont open anymore order again. Unless u remove the EA from the chart, and reattached again (to initialize). I guess that was the purpose?