2 EAs, 2 same charts 1 account

 

I have a situation where I have found a good EA, but it does not set stop losses. So I built an EA that takes profits off the table and minimizes losses. The first EA enters the trades nicely so I want to keep using it.


The second EA goes through the ticket orders and decides when to cut losses by closing orders.


I put first EA on EURUSD,M1


I put the second EA on a second chart of EURUSD.


I suspect there may be some issue with doing this as there seems to be some lag in the first EA working or second EA working. The dicision as to who gets to run seems to be in play.


the first EA is compiled so I cannot build onto it. I haven't knoticed a magicnumber issue yet.


Because first EA is pkacing the orders and second EA is closing them, I think this is where the problem is coming into play.


Any ideas on how to correct this?

 

LEH


If you're sure the MagicNumber/s are always set & read OK by the two EA's then look at execution delays - which will occur frequently on any live trading server.

You must handle failures of OrderSend & OrderClose, its also highly advisable to handle OrderModify as well!

The general subject can be read about on 'Error 146 ("Trade context busy") and How to Deal with It'


The approach below is one way for OrderSend handling - code mostly done by 4x4ever
NB - iNR should be at least 5, I normally use 10, with iMTS set to 1000 (i.e. one second)
If this doesnt launch an order - have a word with your broker!!!

Good luck

-BB-


int OpenAtMarket (string strPair, int iOrderType, double dLots, double dPrice, int iSlippage, double dSL, double dTP, string strOrderComment, int iMagicNumber, datetime dtExpiry, color cColour, int iNR, int iMTS)
{
int iMaxNumRetries, iNumRetries=iNR;

// is server or context busy - try n times to submit the order
iNumRetries=iNR;

while(iNumRetries>0)
{
int iTicket = OrderSend(strPair, iOrderType, dLots, dPrice, iSlippage, dSL, dTP, strOrderComment, iMagicNumber, dtExpiry, cColour);

iNumRetries--;

if(iTicket == -1 )
{
int iError = GetLastError();

// retry if error is "busy", otherwise give up
if( iError==4 || iError==146 || iError==137 || iError==6 || iError==128) //ERR_SERVER_BUSY, ERR_TRADE_CONTEXT_BUSY, ERR_BROKER_BUSY, ERR_NO_CONNECTION, ERR_TRADE_TIMEOUT
Sleep(iMTS);
else
{
iNumRetries = 0;
Print("OpenAtMarket: OrderSend Error ", GetLastError() );
}
}
else
iNumRetries = 0;
}

return(iTicket);
}

 
BarrowBoy:

LEH


If you're sure the MagicNumber/s are always set & read OK by the two EA's then look at execution delays - which will occur frequently on any live trading server.

You must handle failures of OrderSend & OrderClose, its also highly advisable to handle OrderModify as well!

The general subject can be read about on 'Error 146 ("Trade context busy") and How to Deal with It'


The approach below is one way for OrderSend handling - code mostly done by 4x4ever
NB - iNR should be at least 5, I normally use 10, with iMTS set to 1000 (i.e. one second)
If this doesnt launch an order - have a word with your broker!!!

Good luck

-BB-


int OpenAtMarket (string strPair, int iOrderType, double dLots, double dPrice, int iSlippage, double dSL, double dTP, string strOrderComment, int iMagicNumber, datetime dtExpiry, color cColour, int iNR, int iMTS)
{
int iMaxNumRetries, iNumRetries=iNR;

// is server or context busy - try n times to submit the order
iNumRetries=iNR;

while(iNumRetries>0)
{
int iTicket = OrderSend(strPair, iOrderType, dLots, dPrice, iSlippage, dSL, dTP, strOrderComment, iMagicNumber, dtExpiry, cColour);

iNumRetries--;

if(iTicket == -1 )
{
int iError = GetLastError();

// retry if error is "busy", otherwise give up
if( iError==4 || iError==146 || iError==137 || iError==6 || iError==128) //ERR_SERVER_BUSY, ERR_TRADE_CONTEXT_BUSY, ERR_BROKER_BUSY, ERR_NO_CONNECTION, ERR_TRADE_TIMEOUT
Sleep(iMTS);
else
{
iNumRetries = 0;
Print("OpenAtMarket: OrderSend Error ", GetLastError() );
}
}
else
iNumRetries = 0;
}

return(iTicket);
}

Ok, I guess I should elaborate. I found a good EA from http://www.powertradelive.com it allows for multiple trades. In particular, I am using the Trend trade tool the most. I set my charts to M1, on Interbank I set settings to: grid=3, TakeProfit=10, Lots=2

Now at this point and time, I like the earnings side of things, but the run away losses are killing me. By modifying the settings to a very small level, I can conservatively generate small earnings without a problem, but still, there are sizable chunks of run away losses I am enduring. This program does not use stop losses as it assumes such a small size on the lot's that it won't margin out before the market returns to pick up the stragglers. If they do margin out, then the earnings of other good trades will compensate for the losses.

I just want to trim the run away losses before they get out of control. I also don't care to have my account exposed to a high risk of margin, so a stop loss process needs to be implemented. I cannot access the code provided by the designer, so I have to build an outside EA to handle the stop loss process for me.

When I attempt to do so, I find that my attempts to close the orders is not working very well.

Currently, I am attempting to use their multi-currency ring strategy, this means that I have to do this against various symbols in the orders list. I really don't want any of these trades to stay on the table if loss exceeds 10% of the trade on any oder ticket.

I am still learning the language and terminologies so I am having a very frustrating time making this work.

IF ANYONE IS WILLING TO MAKE THE SOLUTION, I AM WILLING TO ENTERTAIN A PRICE FOR IT. I will want to set the percentage of the stop though. I would even like to set the stop loss as a trailing one at the designated stop percentage that I want to apply. The second piece of this would be to set a leading TakeProfit percentage as well. For example, if the price is within a 5% of current TakeProfit, I would like to move the TakeProfit up higher at a percentage of the OrderOpenPrice. This keeps the potential earnings growing, but minimizes the losses.

In fact, I am prepared to pay anyone $5000 if they can get this working by 05/16/08. Here is the actual requirements:

1. Must operate against open orders in order list (buy or sells only), includes various currency pairs.

2. Trailing stop loss based on a percentage (provided by user), initially sets at stop percentage below OrderOpenPrice(), then increments trailing stop loss by the same percentage; example if price = 1, then initial stop loss is at 1-(1*.05). When current price exceeds break even point, stop loss becomes:

BreakEven + OrderOpenPrice() * StopLossPercentage. example, OrderOpenPrice = 1, breakeven = 2.5, StopLossPercentage = .05, NewStopLoss = 2.5 + (1 * .05)

3. GrowthTakeProfit initiates at user TakeProfit entry on the order. Value of TakeProfit grows by user provided GrowthTakeProfitPercentage Each time the current price (ask or bid depending on order direction) is within ReachPercentage (percentage less than TakeProfit set by user), the take profit grows to next take profit level.

The end result should be a trailing stop loss that will be set at user specified loss percentage and will follow the earnings securing them at the specified percentage as the order increases in earnings. The take profit will continue to climb to a higher take profit level set by user specified percentage as the earnings get within the Reachpercentage range.

Final requirement is that I want the source code when done. I want all copyrights on the code.

 
LEHayes:
BarrowBoy:

LEH


If you're sure the MagicNumber/s are always set & read OK by the two EA's then look at execution delays - which will occur frequently on any live trading server.

You must handle failures of OrderSend & OrderClose, its also highly advisable to handle OrderModify as well!

The general subject can be read about on 'Error 146 ("Trade context busy") and How to Deal with It'


The approach below is one way for OrderSend handling - code mostly done by 4x4ever
NB - iNR should be at least 5, I normally use 10, with iMTS set to 1000 (i.e. one second)
If this doesnt launch an order - have a word with your broker!!!

Good luck

-BB-


int OpenAtMarket (string strPair, int iOrderType, double dLots, double dPrice, int iSlippage, double dSL, double dTP, string strOrderComment, int iMagicNumber, datetime dtExpiry, color cColour, int iNR, int iMTS)
{
int iMaxNumRetries, iNumRetries=iNR;

// is server or context busy - try n times to submit the order
iNumRetries=iNR;

while(iNumRetries>0)
{
int iTicket = OrderSend(strPair, iOrderType, dLots, dPrice, iSlippage, dSL, dTP, strOrderComment, iMagicNumber, dtExpiry, cColour);

iNumRetries--;

if(iTicket == -1 )
{
int iError = GetLastError();

// retry if error is "busy", otherwise give up
if( iError==4 || iError==146 || iError==137 || iError==6 || iError==128) //ERR_SERVER_BUSY, ERR_TRADE_CONTEXT_BUSY, ERR_BROKER_BUSY, ERR_NO_CONNECTION, ERR_TRADE_TIMEOUT
Sleep(iMTS);
else
{
iNumRetries = 0;
Print("OpenAtMarket: OrderSend Error ", GetLastError() );
}
}
else
iNumRetries = 0;
}

return(iTicket);
}

Ok, I guess I should elaborate. I found a good EA from http://www.powertradelive.com it allows for multiple trades. In particular, I am using the Trend trade tool the most. I set my charts to M1, on Interbank I set settings to: grid=3, TakeProfit=10, Lots=2

Now at this point and time, I like the earnings side of things, but the run away losses are killing me. By modifying the settings to a very small level, I can conservatively generate small earnings without a problem, but still, there are sizable chunks of run away losses I am enduring. This program does not use stop losses as it assumes such a small size on the lot's that it won't margin out before the market returns to pick up the stragglers. If they do margin out, then the earnings of other good trades will compensate for the losses.

I just want to trim the run away losses before they get out of control. I also don't care to have my account exposed to a high risk of margin, so a stop loss process needs to be implemented. I cannot access the code provided by the designer, so I have to build an outside EA to handle the stop loss process for me.

When I attempt to do so, I find that my attempts to close the orders is not working very well.

Currently, I am attempting to use their multi-currency ring strategy, this means that I have to do this against various symbols in the orders list. I really don't want any of these trades to stay on the table if loss exceeds 10% of the trade on any oder ticket.

I am still learning the language and terminologies so I am having a very frustrating time making this work.

IF ANYONE IS WILLING TO MAKE THE SOLUTION, I AM WILLING TO ENTERTAIN A PRICE FOR IT. I will want to set the percentage of the stop though. I would even like to set the stop loss as a trailing one at the designated stop percentage that I want to apply. The second piece of this would be to set a leading TakeProfit percentage as well. For example, if the price is within a 5% of current TakeProfit, I would like to move the TakeProfit up higher at a percentage of the OrderOpenPrice. This keeps the potential earnings growing, but minimizes the losses.

In fact, I am prepared to pay anyone $5000 if they can get this working by 05/16/08. Here is the actual requirements:

1. Must operate against open orders in order list (buy or sells only), includes various currency pairs.

2. Trailing stop loss based on a percentage (provided by user), initially sets at stop percentage below OrderOpenPrice(), then increments trailing stop loss by the same percentage; example if price = 1, then initial stop loss is at 1-(1*.05). When current price exceeds break even point, stop loss becomes:

BreakEven + OrderOpenPrice() * StopLossPercentage. example, OrderOpenPrice = 1, breakeven = 2.5, StopLossPercentage = .05, NewStopLoss = 2.5 + (1 * .05)

3. GrowthTakeProfit initiates at user TakeProfit entry on the order. Value of TakeProfit grows by user provided GrowthTakeProfitPercentage Each time the current price (ask or bid depending on order direction) is within ReachPercentage (percentage less than TakeProfit set by user), the take profit grows to next take profit level.

The end result should be a trailing stop loss that will be set at user specified loss percentage and will follow the earnings securing them at the specified percentage as the order increases in earnings. The take profit will continue to climb to a higher take profit level set by user specified percentage as the earnings get within the Reachpercentage range.

Final requirement is that I want the source code when done. I want all copyrights on the code.

Also. I forgot to mention that orders to close trades at stop loss must be within market reqcuirements to ensure the closure on the trades take place if a stop loss is hit or take profit should be hit. In other words, take into consideration freezelevels and such to make sure the order will close.

 
Never mind. I found the key that I was looking for to make this work. I can finish the code myself.