Coding help - page 423

 

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:

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)
Files:
 
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:

Please read my previous post

That opening does not have anything to do with a lack of symbol checking - you must have additional checking to disable opening orders on the same symbol and on the same bar. If you have the same EA on same symbols and different time frames, then not even that checking would help you (since the bars will be different in some cases for different time frames of the same symbol)

 

Thanks so much mladen,

I tried to add a code you thought me some years ago....but it seems not working.....the code if you remember go this way...

static datetime lastAlerted=0;

if(lastalerted!=Time[0];

open().......

kindly help me add the right code at the appropriate place!

mladen:
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
 
Mastercash:
Thanks so much mladen,

I tried to add a code you thought me some years ago....but it seems not working.....the code if you remember go this way...

static datetime lastAlerted=0;

if(lastalerted!=Time[0];

open().......

kindly help me add the right code at the appropriate place!

Mastercash

As I told in the previous post : if you attach that EA to same symbol and different time frames there is no way how you can prevent a lower time frame EA to open an order on the higher time frame current bar (that already has opened order).

You would have to scan all the time frames current bars, which translated comes to the highest time frame current bar - but even then you have no idea whict tyim frame opened the bar

You could use the comment field of the order to mark that, but the comment field can be changed by the broker so there is no reliable way to do that

 

ok sir..

but I never make my ea multi time frames.Anyway I ve attached the code below..kindly help me out with an adjustment for this repeated trading on the same currency to stop: and if I need to make any axtra commitment to get it done, you may lrt me know by inbox me.tnks

mladen:
Mastercash

As I told in the previous post : if you attach that EA to same symbol and different time frames there is no way how you can prevent a lower time frame EA to open an order on the higher time frame current bar (that already has opened order).

You would have to scan all the time frames current bars, which translated comes to the highest time frame current bar - but even then you have no idea whict tyim frame opened the bar

You could use the comment field of the order to mark that, but the comment field can be changed by the broker so there is no reliable way to do that
Files:
 
Mastercash:
ok sir.. but I never make my ea multi time frames.Anyway I ve attached the code below..kindly help me out with an adjustment for this repeated trading on the same currency to stop: and if I need to make any axtra commitment to get it done, you may lrt me know by inbox me.tnks

Actually that EA is a multi time frame EA (it uses indicators on a 5 minute data) but never mind : here you have a version that does not allow opening more than one order per bar nicetrader_1.021.mq4

Files:
 

Hi everyone,

can someone help me coding a simple ea based on xcode indicator, as I'm noob in coding.

just need buy and sell orders after signal bar close, indicator's signal period change option, trading hours and trading days change option.

buy and sell entry's are simple as described in screenshot. any timeframe any pair, take profit option, trailing stop option.

I know it's not the holy grail and is far from it (as holy grail doesn't exist ), but we can try to get something from this.

Also if it possible to add lot size increasing option (to change manually). for example: 0.01,0.01,0.02,0.02,0.04,0.04,0.08,0.08 and so on...

Files:
xcode.jpg  346 kb
xcode.mq4  11 kb
 
mladen:
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

}

Hi Mladen,

thank you so much for your help! I have implemented your code as suggested.

Now it is working

May I probably ask you another short question?

What do you think about the CCI Filter, is this the right approach to filter sideways marktes in this case?

Should I give it a range like (CCIFilter>80 && CCIFilter<100)

Maybe you could advice?

if(openedOrders<=0)

{

double CCIFilter=iCCI(NULL,0,CCIPeriod,CCIMethod,0);

double trendc = iCustom(Symbol(),0,"Hull moving average 2 strict nmc", "", HMA_Period, HMA_Price, HMA_Speed,0,3,1); //buffer, signal candle, up

double trendp = iCustom(Symbol(),0,"Hull moving average 2 strict nmc", "", HMA_Period, HMA_Price, HMA_Speed,0,3,2); //buffer, signal candle, down

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 80)) OpenBuy(); // (CCIFilter>80 && CCIFilter<100) maybe better?

if(cshorts < maxshorttrades && trendc==-1 && (CCIFilter<-80)) OpenSell(); //(CCIFilter-100)

// Check the CCI condition

// it is not symetrical to buy condition

}

}

P.S, I hope you are not affected by the Alpari bankruptcy, there is quite some turbulence.

Thank you in advance and have a nice weekend!

With kind regards,

TFI

Files:
backtest2.jpg  160 kb
 
tfi_markets:
Hi Mladen,

thank you so much for your help! I have implemented your code as suggested.

Now it is working

May I probably ask you another short question?

What do you think about the CCI Filter, is this the right approach to filter sideways marktes in this case?

Should I give it a range like (CCIFilter>80 && CCIFilter<100)

Maybe you could advice?

if(openedOrders<=0)

{

double CCIFilter=iCCI(NULL,0,CCIPeriod,CCIMethod,0);

double trendc = iCustom(Symbol(),0,"Hull moving average 2 strict nmc", "", HMA_Period, HMA_Price, HMA_Speed,0,3,1); //buffer, signal candle, up

double trendp = iCustom(Symbol(),0,"Hull moving average 2 strict nmc", "", HMA_Period, HMA_Price, HMA_Speed,0,3,2); //buffer, signal candle, down

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 80)) OpenBuy(); // (CCIFilter>80 && CCIFilter<100) maybe better?

if(cshorts < maxshorttrades && trendc==-1 && (CCIFilter<-80)) OpenSell(); //(CCIFilter-100)

// Check the CCI condition

// it is not symetrical to buy condition

}

}

P.S, I hope you are not affected by the Alpari bankruptcy, there is quite some turbulence.

Thank you in advance and have a nice weekend!

With kind regards,

TFI

TFI

Of Alpari : I have been their client for a long time. But I close my accounts from time to time (when what I consider a critical mass is reached) and this time I closed my account with them about a month ago, and did not open a new one (having a still opened account with another broker too). Frankly, even though I was lucky and I was not affected at all with what happened, I must say that I am sad for what happened to them : I never ever had any problem (not even a smallest problem) with them, and in cases when some things needed clarification or correction they always did it in a timely manner

_______________________

Of CCI filter : usually values between -100 and +100 are considered a "normal zone" for CCI (which would mean ranging) but a lot of traders are trading CCI exclusively on a zero cross with default (14) length parameter set. It increases the possibility of being hit by a whipsaw, but those that are using zero crosses usually use it on short time frame. To avoid that time of usage, set the period to longer period (try 50 for example) which is quite a good setting for zer cross signals on a lot of symbols and time frames

 
mladen:
TFI

Of Alpari : I have been their client for a long time. But I close my accounts from time to time (when what I consider a critical mass is reached) and this time I closed my account with them about a month ago, and did not open a new one (having a still opened account with another broker too). Frankly, even though I was lucky and I was not affected at all with what happened, I must say that I am sad for what happened to them : I never ever had any problem (not even a smallest problem) with them, and in cases when some things needed clarification or correction they always did it in a timely manner

_______________________

Of CCI filter : usually values between -100 and +100 are considered a "normal zone" for CCI (which would mean ranging) but a lot of traders are trading CCI exclusively on a zero cross with default (14) length parameter set. It increases the possibility of being hit by a whipsaw, but those that are using zero crosses usually use it on short time frame. To avoid that time of usage, set the period to longer period (try 50 for example) which is quite a good setting for zer cross signals on a lot of symbols and time frames

Hello Mladen,

I would like to thank you for your help once more. You are very knowledgable. I really apprechiate it, helping and knowledge sharing people are quite rare nowadays. I will also implement and test your suggestions about the CCI.

I was thankfully not affected by the Alpari case because I am still developing my EA (it should trade while I am in the office and generate some extra income for me and my family). I used Alpari as testing platform, because they left the demo account open for unlimited timespan. I have opend an account with IG markets a few days ago, but I have no money transferred yet. I need to have the EA running reliable and bugfree first.

All the best for you and keep up your great work!

With kind regards,

TFI

Reason: