Results 1 to 5 of 5
 0 Attachment(s)    

Thread: How to send an order without SL and TP, then 1 second later send a ordermodify with ?

  1. #1
    Junior Member
    Join Date
    Oct 2009
    Posts
    11

    Default How to send an order without SL and TP, then 1 second later send a ordermodify with ?

    Code:
      
    if(RK_sig(1)==1&&UseFilterRK&&(GetOrders(Symbol(),OP_BUY,MagicRK)==0)&&(GetOrders(Symbol(),OP_SELL,MagicRK)==0))
       {
       t=0;
       if(TP!=0) t=Ask+TP*point;
       s=0;
       if(SL!=0) s=Ask-SL*point;
       if(!FixedLot) l=GetLot(SL);
       
       OpenOrders(OP_BUY,t,s,Ask,l,MagicRK,"RK buy");
       }
      if(RK_sig(1)==-1&&UseFilterRK&&(GetOrders(Symbol(),OP_BUY,MagicRK)==0)&&(GetOrders(Symbol(),OP_SELL,MagicRK)==0))
       {
      t=0;
       if(TP!=0) t=Bid-TP*point;
       s=0;
       if(SL!=0) s=Bid+SL*point;
       
       if(!FixedLot) l=GetLot(SL);
       OpenOrders(OP_SELL,t,s,Bid,l,MagicRK,"RK sell");
       } 
       }
    Can some body do the work for me,please?I am not a coder.
    Thanks in advance.

  2. #2
    Junior Member
    Join Date
    Oct 2009
    Posts
    11

    Default

    Funyoo,I need your help.

  3. #3
    Administrator funyoo's Avatar
    Join Date
    Sep 2008
    Posts
    7,003

    Default

    Quote Originally Posted by sunyc1982 View Post
    Funyoo,I need your help.
    Hi sunyc1982,

    You ordersend functions are not correct, it should be something like that :

    Code:
    OrderSend(Symbol(),OP_BUY,lots,Ask,slippage,longsl,longtp,comment,magic,expire,Blue);
    OrderSend(Symbol(),OP_SELL,lots,Bid,slippage,shortsl,shorttp,comment,magic,expire,Blue);
    You just need to replace long/shortsl and long/shorttp by 0.

    Then you add this :

    Code:
    createlstoploss(stoploss);
    createltakeprofit(takeprofit);
    createsstoploss(stoploss);
    createstakeprofit(takeprofit);
    And At the end of the code :

    Code:
    void createlstoploss(int stoploss){
       RefreshRates();
       double ask=MarketInfo(Symbol(),MODE_ASK);
       double bid=MarketInfo(Symbol(),MODE_BID);
       for(int i=0;i<OrdersTotal();i++){
          OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
          if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==magic){
             if(OrderType()==OP_BUY){
                if(OrderStopLoss()==0){                 
                   OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(ask-stoploss*pt,dg),OrderTakeProfit(),0,Red);
                   return(0);
                }
             }
          }
       }
    }
    
    void createsstoploss(int stoploss){
       RefreshRates();
       double ask=MarketInfo(Symbol(),MODE_ASK);
       double bid=MarketInfo(Symbol(),MODE_BID);
       for(int i=0;i<OrdersTotal();i++){
          OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
          if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==magic){
             if(OrderType()==OP_SELL){
                if(OrderStopLoss()==0){                 
                   OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(bid+stoploss*pt,dg),OrderTakeProfit(),0,Red);
                   return(0);
                }
             }
          }
       }
    }
    
    void createltakeprofit(int takeprofit){
       RefreshRates();
       double ask=MarketInfo(Symbol(),MODE_ASK);
       double bid=MarketInfo(Symbol(),MODE_BID);
       for(int i=0;i<OrdersTotal();i++){
          OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
          if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==magic){
             if(OrderType()==OP_BUY){
                if(OrderTakeProfit()==0){                 
                   OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NormalizeDouble(ask+takeprofit*pt,dg),0,Red);
                   return(0);
                }
             }
          }
       }
    }
    
    void createstakeprofit(int takeprofit){
       RefreshRates();
       double ask=MarketInfo(Symbol(),MODE_ASK);
       double bid=MarketInfo(Symbol(),MODE_BID);
       int total=OrdersTotal();
       for(int i=0;i<OrdersTotal();i++){
          OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
          if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==magic){
             if(OrderType()==OP_SELL){
                if(OrderTakeProfit()==0){                 
                   OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NormalizeDouble(bid-takeprofit*pt,dg),0,Red);
                   return(0);
                }
             }
          }
       }
    }

  4. #4
    Junior Member
    Join Date
    Dec 2009
    Posts
    4

    Default How to send all order without SL ,TP then add it after one second for ECN broker

    //---- input parameters
    extern double Lots=0.01;
    extern int LotDigits=2;
    extern double StopDistance =;
    extern double TakeProfit =; //0 Means auto calculate profit from StopLoss
    extern double StopLoss=;
    //extern bool FirstOrderIsLong = true;
    bool FirstOrderIsLong = true;
    extern int Period_MA = 20;
    extern int MagicNumber=999;
    extern bool UseHourTrade = false;
    extern int StartHourTrade = 6; // start trading on this hour
    extern int EndHourTrade = 18; // end trading on this hour
    extern bool FiveDigitBroker = true;
    extern int TimeFrame = 0;
    extern double InitialRisk=4;

    //extern int StartHour=0;
    //extern int EndHour=24;

    int Slippage = 3;

    double OpenBuy=0;
    double OpenSell=0;
    double OpenBuyLimit=0;
    double OpenSellLimit=0;
    double OpenBuyStop=0;
    double OpenSellStop=0;
    double EntryPrice=0;

    double LastBuyStopPrice=0;
    double LastSellStopPrice=0;
    double BuyStopPrice=0;
    double SellStopPrice=0;
    //double aLots[]={1,3,6,12,24,48,96,192,384,768};
    //double aLots[]=(0.1, 0.3, 0.9, 2.7, 8.1, 24.3, 72.9, 218.7, 656.1, 1968.3);
    double MaxLots=0;

    double MA; // MA value on 0 bar
    bool Fact_Up = true; // Fact of report that price..
    bool Fact_Dn = true; //..is above or below MA

    //Trade Signal
    #define _NONE 0
    #define _BUY 1
    #define _SELL 2
    #define _CLOSEBUY 4
    #define _CLOSESELL 8
    #define _OPENBUYSTOP 16
    #define _OPENSELLSTOP 32
    #define _DELETEBUYSTOP 64
    #define _DELETESELLSTOP 128

    int cur_signal=_NONE;

    static double point;
    //+------------------------------------------------------------------+
    //| expert initialization function |
    //+------------------------------------------------------------------+
    int init()
    {
    //---- TODO: add your code here
    point = Point;
    if (FiveDigitBroker)
    point = Point * 10;
    CheckOpenPositions();
    return(0);
    }

    //+------------------------------------------------------------------+
    //| expert deinitialization function |
    //+------------------------------------------------------------------+
    int deinit()
    {
    //---- TODO: add your code here
    return(0);
    }


    //+------------------------------------------------------------------+
    //| expert start function |
    //+------------------------------------------------------------------+
    int start()
    {
    double llots;
    double lSL;

    if (TakeProfit==0) TakeProfit=StopLoss/2;

    if (StopDistance!=TakeProfit)
    if (StopDistance!=(TakeProfit/2))
    return (-1);
    if (TimeFrame!=0)
    if ((TimeFrame!=PERIOD_M1) && (TimeFrame!=PERIOD_M5) && (TimeFrame!=PERIOD_M15) && (TimeFrame!=PERIOD_M30) && (TimeFrame!=PERIOD_H1) && (TimeFrame!=PERIOD_H4) && (TimeFrame!=PERIOD_D1) && (TimeFrame!=PERIOD_W1) && (TimeFrame!=PERIOD_MN1))
    return (-1);

    if(MaxLots==0) llots=LotSize(); else
    if(MaxLots==LotSize()) llots=3*LotSize(); else
    llots=MaxLots*2;

    lSL=StopLoss;

    CheckSignal();


    if(cur_signal & _BUY !=0)
    OpenOrder(OP_BUY, llots, Ask, Slippage, lSL, TakeProfit, WindowExpertName(), MagicNumber, 0, Blue);

    if(cur_signal & _SELL !=0)
    OpenOrder(OP_SELL, llots, Bid, Slippage, lSL, TakeProfit, WindowExpertName(), MagicNumber, 0, Red);

    if(cur_signal & _CLOSEBUY !=0)
    {
    CloseLongs(MagicNumber);
    }

    if(cur_signal & _CLOSESELL !=0)
    {
    CloseShorts(MagicNumber);
    }

    if(cur_signal & _DELETEBUYSTOP !=0)
    DeleteOpenOrder(OP_BUYSTOP);

    if(cur_signal & _DELETESELLSTOP !=0)
    DeleteOpenOrder(OP_SELLSTOP);

    if(cur_signal & _OPENBUYSTOP !=0)
    {
    DeleteOpenOrder(OP_BUYSTOP);
    if(FirstOrderIsLong) BuyStopPrice=EntryPrice; else BuyStopPrice=EntryPrice+StopDistance*point;
    Print ("First Order Is Long = " + FirstOrderIsLong);
    OpenOrder(OP_BUYSTOP, llots, BuyStopPrice, Slippage, lSL, TakeProfit, WindowExpertName(), MagicNumber, 0, Blue);
    }

    if(cur_signal & _OPENSELLSTOP !=0)
    {
    DeleteOpenOrder(OP_SELLSTOP);
    Print ("Entry Price = " + NormalizeDouble(EntryPrice,Digits));
    if(FirstOrderIsLong) SellStopPrice=EntryPrice-StopDistance*point; else SellStopPrice=EntryPrice;
    Print ("First Order Is Long = " + FirstOrderIsLong);
    OpenOrder(OP_SELLSTOP, llots, SellStopPrice, Slippage, lSL, TakeProfit, WindowExpertName(), MagicNumber, 0, Red);
    }

    CheckOpenPositions();
    HandleOpenPositions();
    return(0);
    }
    //+------------------------------------------------------------------+


    void CheckSignal()
    {
    cur_signal=_NONE;

    if(OpenBuy==0 && OpenSell==0)
    {
    if(OpenBuyStop>0) cur_signal |= _DELETEBUYSTOP;
    if(OpenSellStop>0) cur_signal |= _DELETESELLSTOP;

    if(cur_signal==_NONE)
    {
    // to see if it's possible to made a trade
    if(BlockTradingFilter1())
    return(0);

    MA=iMA(NULL,TimeFrame,Period_MA,0,MODE_SMA,PRICE_C LOSE,0);

    if (Bid > MA && Fact_Up == true) // Checking if price above
    {
    Fact_Dn = true; // Report about price above MA
    Fact_Up = false; // Don't report about price below MA
    //Alert("Price is above MA(",Period_MA,")."); // Alert
    FirstOrderIsLong = true;
    }
    //--------------------------------------------------------------------
    if (Bid < MA && Fact_Dn == true) // Checking if price below
    {
    Fact_Up = true; // Report about price below MA
    Fact_Dn = false; // Don't report about price above MA
    //Alert("Price is below MA(",Period_MA,").");// Alert
    FirstOrderIsLong = false;
    }


    if(FirstOrderIsLong) cur_signal |= _BUY; else cur_signal |= _SELL;
    EntryPrice=0;
    }
    }

    if(OpenBuy!=0 || OpenSell!=0)
    {
    if(OpenBuy>OpenSell && OpenSellStop==0)
    {
    cur_signal |= _OPENSELLSTOP;
    }
    if(OpenBuy<OpenSell && OpenBuyStop==0)
    {
    cur_signal |= _OPENBUYSTOP;
    }
    }
    }

  5. #5
    Junior Member
    Join Date
    Dec 2009
    Posts
    4

    Default

    hi Funyo could you please help me make this EA send order and bending order with out SL;TP then add it after one second.and if possible hedg all position with the same x SL TP.thank you you make this forum very usefull and attractfull.

Similar Threads

  1. Melomind, send good vibrations to your brain
    By fxtester in forum General discussion
    Replies: 0
    Last Post: 02-05-2015, 14:49
  2. Return value of 'OrderModify' should be checked
    By fxtester in forum MQL programming
    Replies: 0
    Last Post: 08-11-2014, 09:32
  3. Order Send Erorrs
    By Doodman in forum MQL programming
    Replies: 10
    Last Post: 03-26-2012, 12:01
  4. Replies: 1
    Last Post: 12-27-2009, 17:48
  5. Is there way to send orders from mt4 to another platform ?
    By nabelion in forum MQL programming
    Replies: 2
    Last Post: 12-02-2009, 17:49

Tags for this Thread

broker, ecn, expert, how to, magic, sells, slippage, sma, thank you, trading

Posting Permissions

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