Results 1 to 1 of 1
 0 Attachment(s)    

Thread: Alternate Buys and Sells Please HELP!!

  1. #1

    Default Alternate Buys and Sells Please HELP!!

    Hi All,

    I'm trying to get it to alternate between Buys and Sells.

    I'm using "j" as the qualifier. "j" starts as "1", then after the "Buys" run we add "1" to "j" ("j" is two at this point) The Sells are passed by until orders close and adds another "1" to "j" and it the becomes a "3".... so the Buys don't execute but the sells which wants to have a "3" does....after the sells runs "j" is reset to zero... after the sells close orders close "j" gets 1 added to it and the Buys execute and the process starts again. The only problem is it doesn't work !! It appears that the problem is somewhere in the close trade area...because when I put in Print() the results are it keeps adding and adding and adding ...it doesn't stop at 3. What have I done wrong?? Please help Thanks in advance


    int i = 1;
    int j = 1;

    //+------------------------------------------------------------------+
    //| expert initialization function |
    //+------------------------------------------------------------------+
    int init()
    {
    //----

    //----
    return(0);
    }
    //+------------------------------------------------------------------+
    //| expert deinitialization function |
    //+------------------------------------------------------------------+
    int deinit()
    {
    //----

    //----
    return(0);
    }
    //+------------------------------------------------------------------+
    //| expert start function |
    //+------------------------------------------------------------------+
    int start()
    {
    //----




    if(TradeLong)
    if (j == 1)

    if(ActionsPerBarLong == True)
    {

    //----
    OrderSend(Symbol(),OP_BUY,LE1, Ask,5,Ask-sl1*Point,0,"",255,0,CLR_NONE);
    Sleep(2);
    OrderSend(Symbol(),OP_BUYLIMIT, LE2, Ask-sh2*Point,5,Ask-sl2*Point,0,"",255,0,CLR_NONE);
    Sleep(20);
    OrderSend(Symbol(),OP_BUYLIMIT, LE3, Ask-sh3*Point,5,Ask-sl3*Point,0,"",255,0,CLR_NONE);
    Sleep(20);
    OrderSend(Symbol(),OP_BUYLIMIT, LE4, Ask-sh4*Point,5,Ask-sl4*Point,0,"",255,0,CLR_NONE);
    Sleep(20);
    OrderSend(Symbol(),OP_BUYLIMIT, LE5, Ask-sh5*Point,5,Ask-sl5*Point,0,"",255,0,CLR_NONE);
    Sleep(20);
    OrderSend(Symbol(),OP_BUYLIMIT, LE6, Ask-sh6*Point,5,Ask-sl6*Point,0,"",255,0,CLR_NONE);
    Sleep(20);
    OrderSend(Symbol(),OP_BUYLIMIT, LE7, Ask-sh7*Point,5,Ask-sl7*Point,0,"",255,0,CLR_NONE);
    Sleep(20);
    OrderSend(Symbol(),OP_BUYLIMIT, LE8, Ask-sh8*Point,5,Ask-sl8*Point,0,"",255,0,CLR_NONE);
    Sleep(20);
    OrderSend(Symbol(),OP_BUYLIMIT, LE9, Ask-sh9*Point,5,0,0,"",255,0,CLR_NONE);
    ActionsPerBarLong =False;


    j++;

    }



    //----

    //----

    //+------------------------------------------------------------------+


    if(TradeShort)

    if (j == 3)

    if(ActionsPerBarShort==True)
    {
    OrderSend(Symbol(),OP_SELL,LE1, Bid,5,Bid+sl1*Point,0,"",255,0,CLR_NONE);
    Sleep(2);
    OrderSend(Symbol(),OP_SELLLIMIT, LE2, Bid+sh2*Point,5,Bid+sl2*Point,0,"",255,0,CLR_NONE) ;
    Sleep(20);
    OrderSend(Symbol(),OP_SELLLIMIT, LE3, Bid+sh3*Point,5,Bid+sl3*Point,0,"",255,0,CLR_NONE) ;
    Sleep(20);
    OrderSend(Symbol(),OP_SELLLIMIT, LE4, Bid+sh4*Point,5,Bid+sl4*Point,0,"",255,0,CLR_NONE) ;
    Sleep(20);
    OrderSend(Symbol(),OP_SELLLIMIT, LE5, Bid+sh5*Point,5,Bid+sl5*Point,0,"",255,0,CLR_NONE) ;
    Sleep(20);
    OrderSend(Symbol(),OP_SELLLIMIT, LE6, Bid+sh6*Point,5,Bid+sl6*Point,0,"",255,0,CLR_NONE) ;
    Sleep(20);
    OrderSend(Symbol(),OP_SELLLIMIT, LE7, Bid+sh7*Point,5,Bid+sl7*Point,0,"",255,0,CLR_NONE) ;
    Sleep(20);
    OrderSend(Symbol(),OP_SELLLIMIT, LE8, Bid+sh8*Point,5,Bid+sl8*Point,0,"",255,0,CLR_NONE) ;
    Sleep(20);
    OrderSend(Symbol(),OP_SELLLIMIT, LE9, Bid+sh9*Point,5,0,0,"",255,0,CLR_NONE);
    ActionsPerBarShort=False;
    j--;
    j--;
    j--;

    }

    //----



    if(AccountEquity()-AccountBalance()>=AcctPrftClseAllRestart*OrdersTot al()*1.5)

    {
    for(i=OrdersTotal()-1;i>=0;i--)
    {
    OrderSelect(i, SELECT_BY_POS);
    int type = OrderType();

    bool result = false;

    switch(type)
    {
    //Close opened long positions
    case OP_BUY : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(Or derSymbol(),MODE_BID),Slippage,Pink);
    break;

    //Close opened short positions
    case OP_SELL : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(Or derSymbol(),MODE_ASK),Slippage,Pink);
    case OP_BUYLIMIT : result = OrderDelete( OrderTicket() );
    Sleep(10);
    case OP_BUYSTOP : result = OrderDelete( OrderTicket() );
    Sleep(10);
    case OP_SELLLIMIT : result = OrderDelete( OrderTicket() );
    Sleep(10);
    case OP_SELLSTOP : result = OrderDelete( OrderTicket() );
    Sleep(600);


    j++;

    }


    }


    }



    if (OrdersTotal()==0)
    {
    ActionsPerBarLong =True;

    ActionsPerBarShort =True;
    }


    return(0);
    }
    Last edited by BillR; 06-01-2009 at 01:00.

Similar Threads

  1. Pfizer buys Hospira for 15 billion of dollars
    By fxtester in forum Stock market
    Replies: 0
    Last Post: 02-06-2015, 10:55
  2. Microsoft buys Minecraft for 2.5 billion USD
    By fxtester in forum Stock market
    Replies: 0
    Last Post: 09-15-2014, 22:56
  3. Facebook buys WhatsApp for $ 19 billion
    By fxtester in forum Stock market
    Replies: 0
    Last Post: 02-20-2014, 21:23
  4. Big jump in US home sells
    By james_smart in forum Economy
    Replies: 7
    Last Post: 10-16-2011, 21:01

Tags for this Thread

add, expert, sells, slippage, stop

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •