Coding help - page 422

 
Mastercash:
I set the use moneymanagement to false.... but about Lots parameters, it is not about the Lots but the number of open orders.I dont want the ea to open more than 5 orders......at a given time, that is why I set NumberofTrades parameter to 5, on the input parameters but it will still dare me, and take more than 5 orders, thereby threaten my moneymanagements!

Mastercash

This is a result of testing it :

As you can see it never opened more than 5 orders for the same symbol and same magic number at the same time

Files:
5_test.gif  87 kb
 

ok, I can see...I just dont want it to take more than 5 order for different symbols....e.g, lets say there are trading signal from 10 symbols within the last 20 minutes....the ea should take only first 5 trading signals, then when any of those five order close, he can take one more, making sure the current runing orders across various symbol does not exceed 5.But it keep on exceeding 5, no matter.....Sometimes it takes 5 same orders from the same symbol which is also wrong.

mladen:
Mastercash

This is a result of testing it :

As you can see it never opened more than 5 orders for the same symbol and same magic number at the same time
 
Mastercash:
ok, I can see...I just dont want it to take more than 5 order for different symbols....e.g, lets say there are trading signal from 10 symbols within the last 20 minutes....the ea should take only first 5 trading signals, then when any of those five order close, he can take one more, making sure the current runing orders across various symbol does not exceed 5.But it keep on exceeding 5, no matter.....Sometimes it takes 5 same orders from the same symbol which is also wrong.

If you want it to have maximum 5 orders over all symbols, go to line 144 (if( OrderSymbol() != Symbol() ) continue;) and delete it. And keep the magic number for all the instances on all the symbols same (so it can count orders opened only by that EA on all symbols)

 

Hi Mladen

I have a nice indi which is not refreshing when set at a higher TF.

As you can see on the chart when I do not edit, it remains stuck. Could you help to solve that problem?

I add the indicator and a screenshot

 
wolfsch:
Hi Mladen

I have a nice indi which is not refreshing when set at a higher TF.

As you can see on the chart when I do not edit, it remains stuck. Could you help to solve that problem?

I add the indicator and a screenshot

wolfsch

That can happen only in visual back test (that is an error that metatrader did not correct for at lest 7-8 months, and is an error of metatrader not of the indicator) and it happens to all multi time frame indicators when visually backtested

In normal usage it works OK (tested it right now just in case, and all works as it is supposed to work on regular charts)

 

Thank you, I will work on this I get back to you......

mladen:
If you want it to have maximum 5 orders over all symbols, go to line 144 (if( OrderSymbol() != Symbol() ) continue;) and delete it. And keep the magic number for all the instances on all the symbols same (so it can count orders opened only by that EA on all symbols)
 
mladen:
TFI

Buffer 3 is the correct one (that is the "trend" buffer that has values 1 for up slope and -1 for down slope). You are using shifts 1 and 2, hence it is testing the 1st closed bar.

Buy part of the code is OK.

You left out the

if(trendc!=trendp)

from the sell part ant that might be causing you a problem

Hello Mladen,

thank you very much for being helpful. I changed the code according

to your suggestion, it is trading smooth, the pip calculation is also fine.

But now it is not opening short trades anymore (could be also a strategy ;-)).

It is just closing long positions.

Could you please advice once more?

extern double maxshorttrades = 2;

extern double maxlongtrades = 2;

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

//| BUY |

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

for (i=OrdersTotal()-1;i>=0; i--)

if(OrderType()==OP_BUY && OP_BUY<maxlongtrades) break; // Check Traded Positions.

{

if(trendc!=trendp)

{

if(trendc==1 && (CCIFilter<80)) // code for buy

OpenBuy();

return(0);

}

openedOrders++;

}

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

//| SELL |

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

for (i=OrdersTotal()-1;i>=0; i--)

if(OrderType()==OP_SELL && OP_SELL<maxshorttrades) break; // Check Traded Positions.

{

if(trendc!=trendp)

{

if(trendc==-1 && (CCIFilter>80)) // code for sell

OpenSell();

return(0);

}

openedOrders++;

}

}

Please see attached screenshot for details.

Thank you in advance!

With kind regards,

TFI

Files:
backtest.jpg  163 kb
 
tfi_markets:
Hello Mladen,

thank you very much for being helpful. I changed the code according

to your suggestion, it is trading smooth, the pip calculation is also fine.

But now it is not opening short trades anymore (could be also a strategy ;-)).

It is just closing long positions.

Could you please advice once more?

extern double maxshorttrades = 2;

extern double maxlongtrades = 2;

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

//| BUY |

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

for (i=OrdersTotal()-1;i>=0; i--)

if(OrderType()==OP_BUY && OP_BUY<maxlongtrades) break; // Check Traded Positions.

{

if(trendc!=trendp)

{

if(trendc==1 && (CCIFilter<80)) // code for buy

OpenBuy();

return(0);

}

openedOrders++;

}

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

//| SELL |

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

for (i=OrdersTotal()-1;i>=0; i--)

if(OrderType()==OP_SELL && OP_SELL<maxshorttrades) break; // Check Traded Positions.

{

if(trendc!=trendp)

{

if(trendc==-1 && (CCIFilter>80)) // code for sell

OpenSell();

return(0);

}

openedOrders++;

}

}

Please see attached screenshot for details.

Thank you in advance!

With kind regards,

TFI

TFI

Try something like this :

extern double maxshorttrades = 2;

extern double maxlongtrades = 2;

//-----------------------------------------------------

//

//-----------------------------------------------------

int clongs = 0;

int cshorts = 0;

for (i=OrdersTotal()-1;i>=0; i--)

{

if(OrderType()==OP_BUY) clongs++; // Check Long Traded Positions.

if(OrderType()==OP_SELL) cshorts++; // Check Short Traded Positions.

}

if(trendc!=trendp)

{

if(clongs < maxlongtrades && trendc== 1 && (CCIFilter<80)) OpenBuy();

if(cshorts 80)) OpenSell();

// Check the CCI condition

// it is not symetrical to buy condition

}

 

mladen,

I have done the change in number 144 and I have unified the magic number, "MagicNumber" across the symbols instances....It is now take maximum of 5 trades at a go but it now repeat trades on the same symbol at the same time, e.g, if receive a SELL trading signal on EURUSD , it will place that EURUSD sell order 5 times. See the image of the live order it took like that:

Mastercash:
Thank you, I will work on this I get back to you......
Files:
apcorrimage.png  39 kb
 
Mastercash:
mladen, I have done the change in number 144 and I have unified the magic number, "MagicNumber" across the symbols instances....It is now take maximum of 5 trades at a go but it now repeat trades on the same symbol at the same time, e.g, if receive a SELL trading signal on EURUSD , it will place that EURUSD sell order 5 times. See the image of the live order it took like that:

That does not depend on that code part

You have to add a check in the rest of the code not to open an order at the same bar and same symbol

Reason: