Results 1 to 3 of 3
 0 Attachment(s)    

Thread: Need some help here with limit orders

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    3

    Default Need some help here with limit orders

    //Buy
    if (Order == SIGNAL_BUY1) {// && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
    if(!IsTrade) {
    //Check free margin
    if (AccountFreeMargin() < (1000 * LotSize)) {
    Print("We have no money. Free Margin = ", AccountFreeMargin());
    return(0);
    }

    if (UseStopLoss) StopLossLevel = Ask - StopLoss1 * Point; else StopLossLevel = 0.0;
    if (UseTakeProfit) TakeProfitLevel = Ask + TakeProfit1 * Point; else TakeProfitLevel = 0.0;

    Ticket = OrderSend(Symbol(), OP_BUYLIMIT, LotsOptimized(), Ask-100*Point, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + MagicNumber + ")", MagicNumber, TimeCurrent()+10800, DodgerBlue);
    if(Ticket > 0) {
    if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
    Print("BUY order opened : ", OrderOpenPrice());
    if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");
    } else {
    Print("Error opening BUY order : ", GetLastError());
    }
    }
    if (EachTickMode) TickCheck = True;
    if (!EachTickMode) BarCount = Bars;
    return(0);
    }
    }

    //Sell
    if (Order == SIGNAL_SELL1) {// && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
    if(!IsTrade) {
    //Check free margin
    if (AccountFreeMargin() < (1000 * LotSize)) {
    Print("We have no money. Free Margin = ", AccountFreeMargin());
    return(0);
    }

    if (UseStopLoss) StopLossLevel = Bid + StopLoss1 * Point; else StopLossLevel = 0.0;
    if (UseTakeProfit) TakeProfitLevel = Bid - TakeProfit1 * Point; else TakeProfitLevel = 0.0;

    Ticket = OrderSend(Symbol(), OP_SELLLIMIT, LotsOptimized(), Bid+100*Point, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + MagicNumber + ")", MagicNumber, TimeCurrent()+10800, DeepPink);
    if(Ticket > 0) {
    if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
    Print("SELL order opened : ", OrderOpenPrice());
    if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell");
    } else {
    Print("Error opening SELL order : ", GetLastError());
    }
    }
    if (EachTickMode) TickCheck = True;
    if (!EachTickMode) BarCount = Bars;
    return(0);
    }
    }

    }


    Could someone check what's going wrong here? It was a normal direct buy/sell script, and i want to use limit buy and limit sell orders. I'm beginning with coding, please keep it simple I'm getting error 130 now, so i guess that there is something wrong with the tp/sl.

    Ideal: would like to send a limit order with fixed TP and SL.
    Last edited by Gnom; 02-27-2010 at 22:15.

  2. #2
    Junior Member
    Join Date
    Feb 2010
    Posts
    3

    Default

    Now i brought it down to this, should be better.

    //Buy
    if (Order == SIGNAL_BUY1) {// && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
    if(!IsTrade) {
    //Check free margin
    if (AccountFreeMargin() < (1000 * LotSize)) {
    Print("We have no money. Free Margin = ", AccountFreeMargin());
    return(0);
    }

    if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0;
    if (UseTakeProfit) TakeProfitLevel = Ask + TakeProfit * Point; else TakeProfitLevel = 0.0;
    int BuyLimit = Bid-difference * Point;
    Ticket = OrderSend(Symbol(), OP_BUYLIMIT, LotsOptimized(), BuyLimit, Slippage, BuyLimit-StopLoss*Point, BuyLimit+TakeProfit*Point, "Buy(#" + MagicNumber + ")", MagicNumber, TimeCurrent()+10800, DodgerBlue);
    if(Ticket > 0) {
    if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
    Print("BUY order opened : ", OrderOpenPrice());
    if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");
    } else {
    Print("Error opening BUY order : ", GetLastError());
    }
    }
    if (EachTickMode) TickCheck = True;
    if (!EachTickMode) BarCount = Bars;
    return(0);
    }
    }

    //Sell
    if (Order == SIGNAL_SELL1) {// && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
    if(!IsTrade) {
    //Check free margin
    if (AccountFreeMargin() < (1000 * LotSize)) {
    Print("We have no money. Free Margin = ", AccountFreeMargin());
    return(0);
    }

    if (UseStopLoss) StopLossLevel = Bid + StopLoss * Point; else StopLossLevel = 0.0;
    if (UseTakeProfit) TakeProfitLevel = Bid - TakeProfit * Point; else TakeProfitLevel = 0.0;
    int SellLimit = Ask+difference*Point;
    Ticket = OrderSend(Symbol(), OP_SELLLIMIT, LotsOptimized(), SellLimit, Slippage, SellLimit+StopLoss*Point, SellLimit-TakeProfit*Point, "Sell(#" + MagicNumber + ")", MagicNumber, TimeCurrent()+10800, DeepPink);
    if(Ticket > 0) {
    if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
    Print("SELL order opened : ", OrderOpenPrice());
    if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell");
    } else {
    Print("Error opening SELL order : ", GetLastError());
    }
    }
    if (EachTickMode) TickCheck = True;
    if (!EachTickMode) BarCount = Bars;
    return(0);
    }
    }
    Last edited by Gnom; 02-27-2010 at 22:54.

  3. #3
    Junior Member
    Join Date
    Feb 2010
    Posts
    3

    Default

    Problems are solved, just by looking in the codebase. It had quite some mistakes thought

Similar Threads

  1. EA Request Trailing Buy Stop/Sell Stop or Buy Limit/Sell Limit
    By bseth in forum Ideas for expert advisors
    Replies: 3
    Last Post: 02-25-2016, 04:04
  2. Limit Orders Manager
    By madscalp in forum Scripts and other tools
    Replies: 7
    Last Post: 04-25-2013, 06:39
  3. Script help needed buy limit / sell limit
    By mr.influence in forum Scripts and other tools
    Replies: 0
    Last Post: 02-03-2011, 22:08
  4. Replies: 2
    Last Post: 07-01-2010, 01:14
  5. Before x profit then buy limit or sell limit
    By gaspar in forum MQL programming
    Replies: 0
    Last Post: 10-14-2009, 17:13

Tags for this Thread

100, coding, free, limit, magic, money, signal, simple, slippage

Posting Permissions

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