You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
bool order= 0;
int ticket;
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 )
int ticket= OrderSend (NULL,0,0.01,Ask,3, Bid-150*Point, Bid+100*Point);
{
if( ticket!=1)
{
order=1;
}
}
}
}
Your double declaration of ticket .
int ticket;
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 )
int ticket= OrderSend (NULL,0,0.01,Ask,3, Bid-150*Point, Bid+100*Point);
{
if( ticket!=1)
{
order=1;
}
}
}
}
The declaration of ticket hides ... blah blah ? see i'm the human compiler.
Remove the second int .
I put
bool order and
int ticket
on global variables, and the rest of the code on OnTick, but still doesn't make any entry now
Uncompiled, untested
{
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(!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());
}
}
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 removed the duplicated int, but now no trade is made, i need 1 trade, if price> ichimoku cloud, that code first was great, but it continued to create new trades if
the price was above the cloud, i just need help to code in a way that the script will stop after the 1 trade.
Honest Knave: i tried your code, i just defined magic_no that was missing, it works fine, it waits for the new trade the price touch the cloud again, it will really be usefull for next projects, but
i just need it to stop after the 1º trade, what should i do?
Thank you all for you help
int ticket;
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;
}
}
}
}
This is the problem.
int ticket;
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;
}
}
}
}
So try this and i did point out to it a few post back.
Also note that the OrderSend either returns the ticket number , or -1 minus one if it fails.
Honest Knave: i tried your code, i just defined magic_no that was missing, it works fine, it waits to new trade if the price touches the cloud again, it will really be usefull for next projects, but
i just need it to stop after the 1 trade, what should i do?
Thank you all for you help
It shouldn't trade more than 1...? That is what this does:
{
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(!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());
}
}
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);
}
Honest Knave:
Your EA is great, but it creates new trades if the price goes down again to ichimoku cloud and then returns up. It doesnt repeat the orders in the same candle, like the problem i had, and i'll learn a lot by this sample you gave me, to create new
EA's, but i need a way to code that after the first trade, the EA or script will close immediately, so i just need 1 trade ever made.
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:
Your EA is great, but it creates new trades if the price goes down again to ichimoku cloud and then returns up. It doesnt repeat the orders in the same candle, like the problem i had, and i'll learn a lot by this sample you gave me, to create new
EA's, but i need a way to code that after the first trade, the EA or script will close immediately, so i just need 1 trade ever made.
I don't understand what you mean.
That code cannot open more than 1 order at a time.
But if the order closes, and the trigger happens again, it will open another.
Do you mean you want only one trade to be opened EVER?
I don't understand what you mean.
That code cannot open more than 1 order at a time.
But if the order closes, and the trigger happens again, it will open another.
Do you mean you want only one trade to be opened EVER?