Just construct a loop which reads through all the open orders, checks the OrderType() of each, and sets a string variable sCurrentOrderType to "none", "buy", "sell" or "both" accordingly.
To be efficient, you could execute this loop once in your init() and then have your logic check and set the value of the sCurrentOrderType variable as you open and close orders.
CB
CB is right...
What you are asking about was one of my early programming challenges also.... What I did early on was just have some very simple logic...
int sell =0;
int buy =0;
if (OrdersTotal() ==0)
{
sell=1;
buy=0;
}
if (sell==1)
if(whatever other stuff you need to be true to trade){
your sell order here........;
sell =0;
buy=1;
}
if(buy==1)
if(whatever other stuff you need to be true to trade)
{
your buy order here..............;
sell =1;
buy=0;
}
I think you have to have the buy and sell variables declared as static:
static int sell =0;
static int buy =0;
I think you have to have the buy and sell variables declared as static:
static int sell =0;
static int buy =0;
No, you don't.
CB
int lastType; int init() { lastType=-1; // Open either type initially. } int start() { if (lastType != OP_SELL) { //... code to possibly open a sell lastType = OP_SELL; // opened a sell } else if ( lastType != OP_Buy) { // ... code to possibly open a buy lastType = OP_BUY; // opened a sell } }
Yes you do if you want it to remember what the last order type was between ticks.
Using just the basic "if" logic and setting sell to 1 or 0 only needs int sell =0; The "sell" is just being set to an integer. Maybe this is a better visual
int a=0;
int b=0;
if (OrdersTotal() ==0)
{
a=1;
b=0;
}
if (a==1)
if(whatever other stuff you need to be true to trade){
your sell order here........;
a=0;
b=1;
}
if(b==1)
if(whatever other stuff you need to be true to trade)
{
your buy order here..............;
a=1;
b=0;
}
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
HI all,
I started making EA a month ago and i was creating EAs just for training, now i'm trying to code my live EA. I need something that makes the EA only buy after a sell or sell after a buy, so it can't buy twice in a row nor sell twice in a row but i need it to be able to make the first trade ignoring this rules, then it will trade by the rules. How can i do this?
Thanks
Cheers