English

## I am stuck. What am I missing?

 106 4x_Gypsy 2015.09.11 01:27   I have the following function that is supposed to create 5 pending orders. The distance of the the pending orders are to be 20pips apart. I can open the inital market order and place the first pending order at the proper distance but the following 4 pending orders are placed at the same price as the first.How can i place each of the following 4 pending orders 20 pips apart?```//+------------------------------------------------------------------+ //|                                                                  | //+------------------------------------------------------------------+ void PendingOrders()   { //-------------------------------------------------------------------------------------------------    double PendingDistance=NormalizeDouble(PendingOrderDistance*pips,Digits);    double PendingPrice=NormalizeDouble(OrderOpenPrice()+PendingDistance,Digits); //-------------------------------------------------------------------------------------------------    int i;    int NewPendingLong;    int NewPendingShort;    if(OrdersTotal()
 Moderator3528 GumRai 2015.09.11 02:24 #   ```void PendingOrders()   { //-------------------------------------------------------------------------------------------------    double PendingDistance=NormalizeDouble(PendingOrderDistance*pips,Digits);    double PendingPrice=OrderOpenPrice(); //-------------------------------------------------------------------------------------------------    int i;    int NewPendingLong;    int NewPendingShort;    if(OrdersTotal()
 Moderator3528 GumRai 2015.09.11 23:35 #   4x_Gypsy: Nope didn't work.I was puzzled why this didn't work, but must admit that I didn't actually look at the code for your OrderSend(). I was just focused on your code placing the trades the correct distance apart.I quickly wrote a test EA and found that the reason it doesn't work is that your OrderSend() is wrong. It is missing the Expiration parameter and there is no calculations for the SL and TP.Adapt this to your needs.```#property strict //--- input parameters input int         EA_MagicNumber=999; input double      EA_LotSize=1; input int         EA_Slippage=5; input double      InpPendingLongSL=50; input double      InpPendingLongTP=50; input int         InpPendingOrderDistance=20; input int         NumberofOrders=5; input string      EA_Comment="Pending"; input color       EA_ArrowColor=clrBlue; bool              FirstTick=true; double            SLDecimal; double            TPDecimal; double            PendingDistance; #include //+------------------------------------------------------------------+ //| Expert initialization function                                   | //+------------------------------------------------------------------+ int OnInit()   {    if(Digits==3 || Digits==5)      {       SLDecimal=InpPendingLongSL*Point*10;       TPDecimal=InpPendingLongTP*Point*10;       PendingDistance=InpPendingOrderDistance*Point*10;      }    else      {       SLDecimal=InpPendingLongSL*Point;       TPDecimal=InpPendingLongTP*Point;       PendingDistance=InpPendingOrderDistance*Point;      } //---    return(INIT_SUCCEEDED);   } //+------------------------------------------------------------------+ //| Expert deinitialization function                                 | //+------------------------------------------------------------------+ void OnDeinit(const int reason)   { //---   } //+------------------------------------------------------------------+ //| Expert tick function                                             | //+------------------------------------------------------------------+ void OnTick()   {    if(FirstTick)      {       double PendingLongSL=Ask-SLDecimal;       double PendingLongTP=Ask+SLDecimal;       int ticket=OrderSend(Symbol(),OP_BUY,EA_LotSize,Ask,EA_Slippage,PendingLongSL,PendingLongTP,EA_Comment,                            EA_MagicNumber,EA_ArrowColor);       if(ticket>0)         {          PendingOrders(ticket);          FirstTick=false;         }      } //---   } //+------------------------------------------------------------------+ void PendingOrders(int ticket)   {    if(OrderSelect(ticket,SELECT_BY_TICKET))      {       double PendingPrice=OrderOpenPrice();       int i;       int NewPendingLong;       int NewPendingShort;       if(OrdersTotal()
 106 4x_Gypsy 2015.09.14 09:40 #   ```//+------------------------------------------------------------------+ //|                                                                  | //+------------------------------------------------------------------+ void PlacePendingOrders(int OpenTicket)   { //places pending orders at a pre-determined distance from the market order and each other   /* //------------------------------------------------------------------------------------------------- //Global Order SetUp //------------------------------------------------------------------------------------------------- extern string GlobalEAInputs="Inputs for all Trades";//Alert extern double EA_LotSize=0.01;//LotSize extern int    EA_Slippage=0;//Slippage extern string EA_Comment="Place Comment Here";//Comment extern int    EA_MagicNumber=0001;//Magic Number extern color  EA_ArrowColor=clrNONE;//Arrow Color extern string EA_break="";//======================================= //------------------------------------------------------------------------------------------------- //Static Stops for StopLoss and TakeProfit //------------------------------------------------------------------------------------------------- extern string staticstop="Use Static Stops for SL and TP"; extern int    Static_StopLoss=50;//StopLoss extern int    Static_TakeProfit=100;//TakeProfit extern string StaticStopsbreak="";//======================================= //------------------------------------------------------------------------------------------------- //Pending Orders extern string Pending_Orders="Pending Orders"; extern int    PendingOrderDistance=5;//Pending Order Distance extern int    NumberofOrders=5;//Number of Orders //-------------------------------------------------------------------------------------------------   */ //-------------------------------------------------------------------------------------------------    double PendingDistance=NormalizeDouble(PendingOrderDistance*pips,Digits);    double PendingPrice=OrderOpenPrice(); //-------------------------------------------------------------------------------------------------    int NewPendingOrder=0; //-------------------------------------------------------------------------------------------------    if(OrderSelect(OpenTicket,SELECT_BY_TICKET))       if(OrdersTotal()=0;i--)       if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))          if(OrderType()==OP_BUYSTOP || OrderType()==OP_SELLSTOP)            {             DeleteOrders=OrderDelete(OrderTicket());             Print("Delete Pending..Error  : "+ErrorDescription(GetLastError()));            } //-------------------------------------------------------------------------------------------------   } //+------------------------------------------------------------------+ //|                                                                  | //+------------------------------------------------------------------+ void DeleteAllOrders()   { //only deletes pending orders if any of the market orders close at the stoploss //-------------------------------------------------------------------------------------------------    int CloseTicket=0;    int DeleteOrders=0; //-------------------------------------------------------------------------------------------------    if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))      {       if(OrderStopLoss()==OrderClosePrice())         {          for(i=OrdersTotal()-1;i>=0;i--)             if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))               {                DeleteOrders=OrderDelete(OrderTicket());                Print("Delete Pending..Error  : "+ErrorDescription(GetLastError()));                CloseTicket=OrderClose(OrderTicket(),OrderLots(),Bid,EA_Slippage,EA_ArrowColor);                Print("Close Long Order..Error  : "+ErrorDescription(GetLastError()));                CloseTicket=OrderClose(OrderTicket(),OrderLots(),Ask,EA_Slippage,EA_ArrowColor);                Print("Close Short Order..Error  : "+ErrorDescription(GetLastError()));               }         }      }   }```GumRaiWorks perfectly. Thank You again.I added 2 functions to delete the pending orders when the market order(s) close. I am now working on a way to combine them into 1 function. Happy Trading to you/