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

Having a great idea? Share it on the traders' Forum!
29
2014.02.26 16: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........

29
2014.02.26 16: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 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)
{
}
}
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 SumProfSel = 0;
bool oB, oS;
//---
if(cB > 0 && TrailingStop == true)
{
for(n = 0; n < tot ; n++)
{
if(OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumberLong)
{
{
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--)
{
if(OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumberLong)
{
if(curLot == 0) curLot = OrderLots();
}
}
{
for(k = tot - 1; k >= 0; k--)
{
if(OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumberLong)
{
OrderClose(OrderTicket(), OrderLots(), Bid, 3 * d, Yellow);
}
}
}
}
//################################################################################################
{
int ticketB = 0;
bool ticCloseS;
int orderID;
cS = CalculatePositionSel();
if(MaxAllowPos == true && cB >= 0 && cB < MaxAllowPosNum)```
13956
2014.02.26 16: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); ```

29
2014.02.26 17:34

Well...

AGain, I have not the slightest idea what you're talking about and I could not simplify ANYTHING. I am simply too old to get into programming, not lazy but I am about to retire (the age issue.....)

So you say the instructions are too complicated and when simplified, they be executing on every tick?

Why was my comment misleading? You said that by nature any EA is written to execute serial positions and mine does not. I only said it is what I wanted, the serial positions, on every tick that is available to me....

Sooooo I still don't know why my EAs are executing ONE per bar instead of tick... I do KNOW I might get hundreds of positions - but the way they are NOW I only get ONE and I would want this changed....

By the way: I do Never get such messages, NEVER, referring to your "undefined OpenBuy"...

The whole EAs are working with exactly this setting, no change ever and meanwhile it makes me crazy. All I am changing is indicators and the instructions based on them

Some guy sent me a copy of HIS EA... that one executes on every bloody tick - but he does not know why either..... he's not a programmer and had this done by another guy with some EA creator

Again... this code in my EAs was written by a pro...... I trust he knew what he was doing and when I run them on standard, they work all perfectly well. Someone help me with this.... .

The issue is the execution. How am I going to tell you what I want when my comments are apparently misleading.... :(

Again.... I run this on a set of indicators, say on a 5M. Now I get a signal to buy. At that moment the EA should be BUYING... and BUYING... and BUYING.... all the time, all of the 5 minutes for as long as the indicators stick to the value and keep the signal for long alive during the whole 5 M...... I do run the indicators on actual candle, at least one of them. So what is it that I am not getting`? There are hours with thousands and thousands of ticks.... I want all of them, I keep buying and buying and buying again on every tick, until my indicator tells me to do otherwise or they do not agree on buying anymore. The way this is set is that I get ONE signal at the end of the candle and I get ONE position at the opening of the new candle.... BUT BUT on that new candle I want each and every tick I can trade because my indicators said BUY...

Pldease do not question my ideas or my reasoning or the purpose behind it. I know WHY I want instant execution on every tick of this particular candle and I might be selling on the next ..... thousands of positions again if need be.....

29
2014.02.26 17:41

Sorry.....

I stand corrected

The open buy (true) is a feature for another purpose.

I can disable long or short by simply clicking on that

by standard they are both (long and short) set to true.

If I am testing something, I often do it separately... One setting for long, another for short..... THAT is what this refers to.... Has nothing to do with entering on tick ......

Moderator
8835
2014.02.26 22:17

You still have not shown any code that opens an order.

I suggest that you contact the person who coded your EA and request the modification.

/ /12