Hi I´m new to the stuff

 
I want to programme some automatic trading strategies, but its really difficult to get an overview in the whole programming stuff ( Im quite a beginner although I have some programming JAVA experience)
So to start with I´m asking for some help with the basics...

How can I programme the following?:
1) if close1=close2 do nothing
2) it should enter position "long" if close1>close2 and enter "short" if opposite;
3) if position is "long" and close1>close2 do nothing, respective for position "short"
4) if position is "long" and close1<close2 then close position "long" and enter "short"
5) opposite for position"short"

I am thankfull for any hints given...
 
1. if (Close[1]==Close[2]) return; // it is wrong compare of two double
2. if (Close[1]>Close[2]) OrdersSend()....  OrdersClose()...
3. if (Close[1]>Close[2] && OrdersTotal()>0)
{
for (i=OrdersTotal()-1;i>=0;i--)
{
if (OrderSelect(i,SELECT_BY_POS))
{
if (OrderType()==OP_BUY) contunue;
....
}
}
}
4.
if (Close[1]<Close[2] && OrdersTotal()>0)
{
for (i=OrdersTotal()-1;i>=0;i--)
{
if (OrderSelect(i,SELECT_BY_POS))
{
if (OrderType()==OP_BUY) OrderClose(OrderTicket(),..);
....
}
}
OrderSend(Symbol(),OP_SELL...);
...
}

Enough?
 
wow ! thx

I´ll try it out immediatly - we´ll see if I have understood..
 
Goaranga:

Ok I have programmed the following - it should just  open and close orders, but it doesnt -why?
how can I get the variable order_id?
any other hints?

int start()

{
int y;

Print(OrdersTotal());
if (OrdersTotal()== 0)
{
OrderSend (Symbol(),OP_BUY,1,Ask,NULL,NULL,NULL,NULL,0,0,Green);
}
else
{
y++;
OrderSelect(OrdersTotal(),SELECT_BY_TICKET);
OrderClose(y,1,Ask,3,Red);
}

}

 
Is it an expert advisor (EA)? Remember, that

Trading functions of OrderSend(), OrderClose, OrderCloseBy, OrderDelete, and OrderModify cannot be called from custom indicators.



And check your settings (Ctrl+O) to allow EA to trade (EA is smiling)
 

Hi Dear Friends,

I just want to share my idea. I'm quiet new in this matter, could you please let me know the most simple way in making EA based on alligator indicator. My idea is, for example: lips 5 (blue), teeth 34 (yellow), and jaws 89 (red), all 0 shift, linear weighted method, and based on close.

1. When blue going down and crossing yellow, then OrderSell and it will be closed when blue crossing up red. But simultanously,
2. When blue going up and crossing yellow, it will OrderBuy and be closed when blue crossing down red.

It should be able to be adjusted according to chart time frame, all currency pair, there must be to have StopLoss and/or TakeProfit setting, but it could be ignored especially for some currency pair.

I really hope that this idea can accomodate your ideas as well.

Thanks for your help and attention to my idea.

 
Rosh:
Is it an expert advisor (EA)?  Remember, that

Trading functions of OrderSend(), OrderClose, OrderCloseBy, OrderDelete, and OrderModify cannot be called from custom indicators.



And check your settings (Ctrl+O) to allow EA to trade (EA is smiling)

It is an EA: it opens the first trade, closes it again, opens anotherone, but doesnt close it like intended.
Im experimenting: conditions like enter position when sthg. happenes will follow after im capable of opening and closing orders. ...

heres the journal:
1,0 are OrdersTotal() printed.

2007.05.15 14:21:55 2006.01.05 00:00 Ka EURUSD,Daily: unknown ticket 1 for OrderClose function
2007.05.15 14:21:55 2006.01.05 00:00 Ka EURUSD,Daily: 1
2007.05.15 14:21:55 2006.01.04 00:00 Ka EURUSD,Daily: open #2 buy 1.00 EURUSD at 1.2034 ok
2007.05.15 14:21:55 2006.01.04 00:00 Ka EURUSD,Daily: 0
2007.05.15 14:21:55 2006.01.03 00:00 Ka EURUSD,Daily: close #1 buy 1.00 EURUSD at 1.1822 at price 1.1812
2007.05.15 14:21:55 2006.01.03 00:00 Ka EURUSD,Daily: 1
2007.05.15 14:21:55 2006.01.02 00:00 Ka EURUSD,Daily: open #1 buy 1.00 EURUSD at 1.1822 ok
2007.05.15 14:21:55 2006.01.02 00:00 Ka EURUSD,Daily: 0
 

Rosh:
Is it an expert advisor (EA)?  Remember, that

Trading functions of OrderSend(), OrderClose, OrderCloseBy, OrderDelete, and OrderModify cannot be called from custom indicators.



And check your settings (Ctrl+O) to allow EA to trade (EA is smiling)


int y;
 
 
int start()
 
{
 
 
Print(OrdersTotal());
if (OrdersTotal()== 0)
 {
 OrderSend (Symbol(),OP_BUY,1,Ask,NULL,NULL,NULL,NULL,0,0,Green);
 }
else
 {
 y++;
 OrderSelect(y,SELECT_BY_TICKET);
 OrderClose(y,1,Ask,3,Red);
 }
 
}
ok it works now for opening and closing orders, more to come... Thx for ur help ;)




 
No, your code is wrong. Use
OrderSelect(y,SELECT_BY_POS);
 
Rosh:
No, your code is wrong. Use
OrderSelect(y,SELECT_BY_POS);

thx.. Where is the difference? (the Help file explains it ...strangely)
 
You need to use loop , for example

int i,y;
 
 
int start()
 
{
 
 
Print(OrdersTotal());
if (OrdersTotal()== 0)
 {
 OrderSend (Symbol(),OP_BUY,1,Ask,NULL,NULL,NULL,NULL,0,0,Green);
 }
else
 {
 for (i=OrdersTotal();i>=0;i--)
 if (OrderSelect(i,SELECT_BY_POS))
 if (OrderType()==OP_BUY) OrderClose(OrderTicket(),OrderLots(),Ask,3,Red);
 }
 
}

It is more safely code.
Reason: