MQL4 - automated forex trading   /  

Forum

Login | Register | Language: ru cn en
Buy Latest Technical Indicators in MetaTrader Market

Alternating OP_BUY & OP_SELL Orders

Back to topics list To post a new topic, please log in or register
avatar
322
wackena 2006.09.10 17:01
 
I'm writing an EA to alternate buy and sell orders. I can code to alternate orders when there is a history, but not from first start of EA. This is the base simple code. How do I code to alternate orders?

if(OrderType()==OP_SELL) Buy=true;
 
if(OrderType()==OP_BUY) Sell=true;

Thanks,
Wackena
 
GOLD continues to chop around key Gann levels

GOLD continues to chop around key Gann levels

Our near-term trend bias is positive on the metal while over 1280 A move through 1321 is needed to confirm that a more meaningful move higher is in fact underway A cycle turn window of importance is seen around the start of next month A daily close under 1280 will turn us negative on Gold XAU/USD Strategy: Like the long side while 1280 holds Instrument Support 2 Support 1 Spot Resistance 1 Resistance 2 XAU/USD 1280 1290 1300 1321

avatar
Moderator
5712
stringo 2006.09.11 11:39 #
 
Buy=false;
Sell=false;
 
if(OrderType()==OP_SELL) Buy=true;
 
if(OrderType()==OP_BUY) Sell=true;
avatar
322
wackena 2006.09.11 18:21 #
 
stringo wrote:
Buy=false;
Sell=false;
 
if(OrderType()==OP_SELL) Buy=true;
 
if(OrderType()==OP_BUY) Sell=true;

Stringo,
I've been using your code suggestion, but that is not my problem. The problem is when the EA starts and there are no open orders, OrderType() then would have no data. After first order, then above code works great. It is just how do I get by that first order. Right now, I start EA with a different code just to get first order and then modify code as above. Then EA runs as intended.

Wackena
 
avatar
Moderator
5712
stringo 2006.09.12 13:11 #
 

May be check for last closed order?

avatar
322
wackena 2006.09.12 15:33 #
 
stringo wrote:

May be check for last closed order?


Stringo,

In my EA there are other signals needed to trigger order. Those signals along with code below now works OK.

Thanks for your helpful idea.

Wackena

int hstTotal=HistoryTotal();
Buy=false;
Sell=false;
 
if(hstTotal==0 || OrderType()==OP_SELL) Buy=true;
 
if(hstTotal==0 || OrderType()==OP_BUY) Sell=true;

 
avatar
5
cha 2011.03.22 14:06 #
 

hello plz i need help

How can I change ea If he should buy, he sells and if he should sell he buys. "Buy" to "Sell" and "Sell" to "Buy" in the EA-Editor???


plz
 
avatar
3071
qjol 2011.03.22 14:55 #
 
cha:

hello plz i need help

How can I change ea If he should buy, he sells and if he should sell he buys. "Buy" to "Sell" and "Sell" to "Buy" in the EA-Editor???


plz

replace OP_BUY to OP_SELL & vice versa just for the record reversing the EA doesn't make a losing EA to be profitable

 
avatar
9522
WHRoeder 2011.03.22 16:27 #
 
int hstTotal=HistoryTotal();
Buy=false;
Sell=false;
 
if(hstTotal==0 || OrderType()==OP_SELL) Buy=true;
You can not call OrderType() unless you have an orderSelect before.
    datetime lastClosePrev;
    int      lastCloseType;
    for(int pos=0; pos < HistoryTotal(); pos++) if (
        OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY)   // Only orders w/
    &&  OrderCloseTime()    > lastClosePrev             // not yet processed,
    &&  OrderMagicNumber()  == magic.number             // my magic number
    &&  OrderSymbol()       == Symbol()                 // and my pair.
    &&  OrderType()         <= OP_SELL){    // Avoid cr/bal forum.mql4.com/32363
        lastClose = OrderCloseTime();
        lastCloseType = OrderType();
    }

avatar
5
cha 2011.03.22 16:41 #
 
qjol:

replace OP_BUY to OP_SELL & vice versa just for the record reversing the EA doesn't make a losing EA to be profitable


plz can u make it
Attached files:
  5matf_1.mq4  (10.58 KB)
avatar
9522
WHRoeder 2011.03.23 15:57 #
 

No slaves here, either learn to code or pay someone.

There are several posters here.

There is the mql5 coders section

DelphiScalper.com recommended:

Rentacode.com
Elance.com
ProgrammingForex.com

 
Back to topics list  

To add comments, please log in or register