English

## Execution of series of positions on ticks - please someone help me

 10 JoaTrader 2014.02.26 17:41 #   angevoyageur: What you asked for is a trivial task for an experimented programmer, if you post all the code. If you can't do it here publicly, I suggest you to use the Jobs section. You don't have to replace start() by OnTick(). I am not looking for an experimenting programmer. I thought here one would find support by experienced programmers for whom this is routine. The whole code? Now that's one helluva file and more than half of it refers to CLOSING of positions. What good would THAT do? It is ONLY the OPENING of positions that bothers me............ but let me try it anyway .. and as you said yourself, it's an easy task apparently and nobody tells me what and where to change. Litgerally dozens tell me the exact same... easy as pie... but not ONE tells me hey.... take off this line and replace by this one........
 10 JoaTrader 2014.02.26 17:45 #   ```//------------------------------------------- double curLot, LotSize; bool global; //+------------------------------------------------------------------+   double GetLots() {       double a;       a = NormalizeDouble((PercentMM * AccountFreeMargin() / 100000), 1);             if(a > 499.9) return(499.9);       else if(a < 0.1)        {          Comment("Lots < 0.1");          return(0);        }       else return(a);     } //+------------------------------------------------------------------+ double CoefLots() {    int n;    double a, b;    if(Coefficient == false) a = GetLots();    //---    else if(Coefficient == true)     {       int Hist = OrdersHistoryTotal();       for(n = Hist; n >= 0; n--)        {          OrderSelect(n, SELECT_BY_POS, MODE_HISTORY);          if(OrderType() <= OP_SELL && OrderSymbol() == Symbol() && (OrderMagicNumber() == MagicNumberLong || OrderMagicNumber() == MagicNumberShort))           {             if(OrderProfit() < 0)              {                a = NormalizeDouble(OrderLots() * LotCoefficient, 1);                b = NormalizeDouble((maxPercentMM * AccountFreeMargin() / 100000), 1);                if(a > b) a = b;                break;              }             else if(OrderProfit() >= 0)              {                a = GetLots();                b = NormalizeDouble((maxPercentMM * AccountFreeMargin() / 100000), 1);                if(a > b) a = b;                break;              }           }        }       if(a == 0) a = GetLots();               }    //---    return(a);       } //+------------------------------------------------------------------+ int GetDigits() {    if(Digits == 5 || Digits == 3)     {       return(10);     }    else     {       return(1);     } } //+------------------------------------------------------------------+ int CalculatePositionBuy() {    int Pos;    int orderT = OrdersTotal();    if(orderT > 0)     {       for(int i = orderT - 1; i >= 0; i--)        {          if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == false) break;          if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumberLong)           {             if(OrderType() == OP_BUY)  Pos++;           }        }       return(Pos);     }        else if(orderT == 0) return(0); } //+------------------------------------------------------------------+ int CalculatePositionSel() {    int Pos;    int orderT = OrdersTotal();    if(orderT > 0)     {       for(int i = orderT - 1; i >= 0; i--)        {          if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == false) break;          if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumberShort)           {             if(OrderType() == OP_SELL)  Pos++;           }        }       return(Pos);     }        else if(orderT == 0) return(0); } //+------------------------------------------------------------------+ int init() {    return(0); }           //+------------------------------------------------------------------+ double indicator 1 //+------------------------------------------------------------------+ double indicator 2 //+------------------------------------------------------------------+ double indicator 3 //+------------------------------------------------------------------+                      START     START     START int start() {    int n, k;    int d = GetDigits();    int tot = OrdersTotal();    double profBest, profWorst, orderLots;    double SumProfBuy = 0;    double SumProfSel = 0;    int cB = CalculatePositionBuy();    bool oB, oS;    //---    if(cB > 0 && TrailingStop == true)     {             for(n = 0; n < tot ; n++)        {          OrderSelect(n, SELECT_BY_POS, MODE_TRADES);          if(OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumberLong)           {                     if(Ask - OrderOpenPrice() > 0)              {                if(OrderStopLoss() < Bid - Point * TrailingStopShort * d)                 {                   OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStopShort * d, OrderTakeProfit(), 0, Green);                 }              }             }          }     }    //============================    curLot = 0;        if(MoneyTP == true  && cB > 0)     {       for(n = tot - 1; n >= 0; n--)        {          OrderSelect(n, SELECT_BY_POS, MODE_TRADES);          if(OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumberLong)           {             SumProfBuy = SumProfBuy + OrderProfit() + OrderSwap() + OrderCommission();             if(curLot == 0) curLot = OrderLots();           }        }         if(SumProfBuy >= ProfitAmountBuy * curLot)        {          for(k = tot - 1; k >= 0; k--)           {             OrderSelect(k, SELECT_BY_POS, MODE_TRADES);             if(OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumberLong)              {                OrderClose(OrderTicket(), OrderLots(), Bid, 3 * d, Yellow);              }           }            }     }      //################################################################################################ //___________________________________________________________________________________________________   BUY   ________    if(OpenBuy == true)//_________________________________________________________________________________________________     {             int ticketB = 0;       bool ticCloseS;       int orderID;           cB = CalculatePositionBuy();       cS = CalculatePositionSel();       if(MaxAllowPos == true && cB >= 0 && cB < MaxAllowPosNum)```
13125
WHRoeder 2014.02.26 17:59 #

1. JoaTrader: Do I have to replace int start() with OnTick()????????
You don't HAVE to, but just seeing int start() means everyone is thinking your problem is dealing with old code/new language.
2. JoaTrader: I wouldn't know WHERE in the EA there would be a filter....... You commented that they are written to execute on every tick....... just what I wanted all along...
OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStopShort * d, OrderTakeProfit(), 0, Green);
What are Function return values ? How do I use them ? - MQL4 forum

4. Print your variable values so you find out WHY.
5. ```   if(OpenBuy == true)//___Undefined OpenBuy do you ever set it?
```
6.  Simplified ```// int Pos;    int Pos=0; // int orderT = OrdersTotal(); // if(orderT > 0) //  {       for(int i = OrdersTotal() - 1; i >= 0; i--)        {          if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == false) break;          if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumberShort)           {             if(OrderType() == OP_SELL)  Pos++;           }        }       return(Pos);  // }     // else if(orderT == 0) return(0); ```