# Need help with EA conditions please

22

Martingle Strategy.

EA places a buy Order, then when price falls below the spicified amount of pips below first order it places another buy order.

I'm having problems printing the second test line, which is where the second buy order would execute from.

e.g. Print(" ----- SECOND TEST LINE ----- ");

I can print the first test line, so I'm guessing it is the condition before the second test line.

Pulling my hair out … any help appriciated .

```extern int    Magic                    = 772177;
extern double TakeProfit               = 50;
extern double LotSize                  = 0.1;
extern double StopLoss                 = 50;
extern int    firstMartinglePosition   = 25;
extern int    slippage                 = 5;

double UsePoint;
int UseSlippage;
int myOrderType;
int cnt;

int init()
{
{
UsePoint = PipPoint(Symbol());
UseSlippage = GetSlippage(Symbol(),slippage);

}

return(0);
}

int deinit()
{
return(0);
}

int start()
{
//----
myOrderType = ConditionsMet();

//+------------------------------------------------------------------+
//+------------------------------------------------------------------+

if(OrdersTotal() < 1 && myOrderType==1)
{
if(StopLoss > 0)
{
double BuyStopLoss = OpenPrice - (StopLoss * UsePoint);
}
if(TakeProfit > 0)
{
double BuyTakeProfit = OpenPrice + (TakeProfit * UsePoint);
}

bool MartingleOne = True;
}

//+------------------------------------------------------------------+
//| First Buy Martingle Position                                     |
//+------------------------------------------------------------------+

while(MartingleOne)
{
for(cnt=OrdersTotal();cnt>=0;cnt--)
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
{
{
Print(" ---- FIRST TEST LINE ----- ");

if (OrderOpenPrice()-Ask >= (firstMartinglePosition * UsePoint))  // NEED HELP Here!
{
Print(" ----- SECOND TEST LINE ----- ");

MartingleOne = false;
}

}
}
}
}

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

//----------- Pip Calculation

//----------- Pip Point Function

double PipPoint(string Currency)
{
int CalcDigits = MarketInfo(Currency,MODE_DIGITS);
if(CalcDigits == 2 || CalcDigits == 3)
{
double CalcPoint = 0.01;
}
else if(CalcDigits == 4 || CalcDigits == 5)
{
CalcPoint = 0.0001;
}
return(CalcPoint);
}

//---------- Get Slippage Function

int GetSlippage(string Currency, int SlippagePips)
{
int CalcDigits = MarketInfo(Currency,MODE_DIGITS);
if(CalcDigits == 2 || CalcDigits == 4)
{
double CalcSlippage = SlippagePips;
}
else if(CalcDigits == 3 || CalcDigits == 5)
{
CalcSlippage = SlippagePips * 10;
}
return(CalcSlippage);
}

int ConditionsMet()
{

// -----------------Custom Indicators here -----------

{
myOrderType=2;
}

// Sell Order
if(((ConditionSell_1 + ConditionSell_2) <= -6))
{
myOrderType=1;
}

return(myOrderType);

}```
Moderator
10615

```         if(OrdersTotal() < 1 && myOrderType==1)
{
bool MartingleOne = True;
}```

Cutting out the other code, you can see that MartingleOne, being a local variable can only be true when the if condition is met.

ie when there are no open orders

The following code will only be executed during the same tick as the order send, so the conditions for the 2nd print are not possible.

```
while(MartingleOne)
{
for(cnt=OrdersTotal();cnt>=0;cnt--)
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
{
{
Print(" ---- FIRST TEST LINE ----- ");

if (OrderOpenPrice()-Ask >= (firstMartinglePosition * UsePoint))  // NEED HELP Here!
{
Print(" ----- SECOND TEST LINE ----- ");

MartingleOne = false;
}

}
}
}```
16096

krystalskull: Martingle Strategy.

1. Guaranteed to wipe your account. Just send the money to me. I'll be happier, you'll still be broke.
2. ```               for(cnt=OrdersTotal();cnt>=0;cnt--)
{
```
There are OrdersTotal() open orders [0 .. OrdersTotal()-1] so the first OrderSelect(OrdersTotal()) will ALWAYS fail, but you continue on as if you do have a selected order.
3. Check What are Function return values ? How do I use them ? - MQL4 forum
22

GumRai:

Cutting out the other code, you can see that MartingleOne, being a local variable can only be true when the if condition is met.

ie when there are no open orders

The following code will only be executed during the same tick as the order send, so the conditions for the 2nd print are not possible.

OK thx GumRai ... I can see now, thanks alot for that!
22

WHRoeder:
1. Guaranteed to wipe your account. Just send the money to me. I'll be happier, you'll still be broke.
2. There are OrdersTotal() open orders [0 .. OrdersTotal()-1] so the first OrderSelect(OrdersTotal()) will ALWAYS fail, but you continue on as if you do have a selected order.
3. Check What are Function return values ? How do I use them ? - MQL4 forum

1. ok thanks for the warning !!!
2. ok I will add -1
4. Great forum by the way!
22

Thanks for previous help.

I removed the bool condition and while loop, and added -1 to the orderselect() for loop.

I am still not able to print the second Test line.

I am able to store the OrderOpenPrice() from the original buy position into the BuyOpenPrice varible ( see first Test Line below).

2014.02.07 13:06:01 2013.12.30 16:00 MBFX EA v1.02 EURUSD,H4: ---- FIRST TEST LINE ----- Buy Open Price = 1.3788
2014.02.07 13:06:01 2013.12.30 16:00 MBFX EA v1.02 EURUSD,H4: open #7 buy 0.10 EURUSD at 1.37882 sl: 1.37382 tp: 1.38382 ok

However, I still can't get the line before the Second Test Line to execute!

```int BuyTicket = OrderSend(Symbol(),OP_BUY,LotSize,OpenPrice,UseSlippage,

}

//+------------------------------------------------------------------+
//+------------------------------------------------------------------+

if(BuyTicket > 0  && MartingleOneTicket == 0)
{
for(cnt=OrdersTotal()-1;cnt>=0;cnt--)
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
{

{
Print(" ---- FIRST TEST LINE ----- Buy Open Price = ", BuyOpenPrice);

{
Print(" ----- SECOND TEST LINE ----- ");

if(StopLoss > 0)
{
}

if(TakeProfit > 0)
{
}