interesting EA - need check and possible help

 

Hi guys,

A quick summary what I'd like this EA to do:

At start, it should open a buy position independent from any indicators and anything else. Right at this point, we determine 4 horizontal lines. One is established at the open price(Ubarrier), one is set above the open price by 5 pips (TP1). The other two below the open price by 5 pips (Dbarrier) and 10 pips (TP2).

When price goes in our direction, we'd like to close the open position at TP1. But if not, we'd like to open a sell trade, so hedge the first position at Dbarrier, so 5 pips below with a lot size of previous lot size+0.01. If price goes further down and reaches TP2, we'd like to close the positions. If not and price turns again, we open a position at Ubarrier again with previous lot size+0.01. And so on...

The issue with the code is that it's not really doing what I'd like it to do. Could you please have a look at and tell me your thoughts about it? Many thanks in advance!

(The problem could come from several points in the code and since I'm not an expert in this field, after checking my work it still contains mistakes I guess.)

-------------------------------------------------------------------------------------------------------------------

extern bool SignalMail = False;
extern bool EachTickMode = True;
extern double Lots = 0.01;
extern int Slippage = 3;
extern bool UseStopLoss = False;
extern int StopLoss = 0;
extern bool UseTakeProfit = True;
extern int TakeProfit = 10;
extern bool UseTrailingStop = False;
extern int TrailingStop = 200;


extern int Total = 0;
extern int x=1;
extern double Dbarrier;
extern double Ubarrier;
extern double range = 0.0005;
extern int i = 1; //multiplying the lot size by "i"
extern double val1;
extern double val2;
extern double val3;
extern double val4;

//double Lts = Lots;



int start() {

while(Total==0) {

//if x=1, the previous trade was long, so this one should be long as well

if (x==1) {

OrderSend(Symbol(), OP_BUY, Lots, Ask, 3, 0, 0);

ObjectCreate("Ubarrier", OBJ_HLINE, 0, 0, Ask);
ObjectCreate("TP1", OBJ_HLINE, 0, 0, Ask+range);
ObjectCreate("Dbarrier", OBJ_HLINE, 0, 0, Ask-range);
ObjectCreate("TP2", OBJ_HLINE, 0, 0, Ask-range*2);

x=2;
Total=1;

//if x!=1, previous trade was short, so this one should be short as well

} else {

while (Total=0) {

OrderSend(Symbol(),OP_SELL, Bid, 3, 0, 0);

ObjectCreate("Ubarrier", OBJ_HLINE, 0, 0, Bid+range);
ObjectCreate("TP1", OBJ_HLINE, 0, 0, Bid-range);
ObjectCreate("Dbarrier", OBJ_HLINE, 0, 0, Bid);
ObjectCreate("TP2", OBJ_HLINE, 0, 0, Bid-range*2);

x=1;
Total=1;

}

}

}

//if Total=1, there are open trades. Let's check whether the price hit our stops. If yes
//we should sell or buy accordingly but with previous lot size + 0.01

while (Total !=0) {

double val1=ObjectGet("Ubarrier", OBJPROP_PRICE1);
double val2=ObjectGet("Dbarrier", OBJPROP_PRICE1);
double val3=ObjectGet("TP1", OBJPROP_PRICE1);
double val4=ObjectGet("TP2", OBJPROP_PRICE1);

if(x==2 && Ask<=val2) {

OrderSend(Symbol(), OP_SELL, Lots+i*Lots, Bid, 3, 0, 0);
x=1;
i++;

}

if (x==1 && Bid>=val1) {

OrderSend(Symbol(), OP_BUY, Lots+i*Lots, Ask, 3, 0, Ask+range);
x=2;
i++;

}

}

//if price hit or went trough our TPs, we close all the open positions and delete all the
//horizontal lines we created above

if (Bid >= val3 || Ask <= val4) {
Total=0;
int tot = OrdersTotal();

for(int k=tot-1;k>=0;k--) {

OrderSelect(k, SELECT_BY_POS);
int type = OrderType();

bool result = false;

switch(type) {


//Close opened long positions

case OP_BUY : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5);
break;
Total=0;

//Close opened short positions

case OP_SELL : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5);
Total=0;
}

if(result == false) {

Alert("Order ", OrderTicket(), " failed to close. Error:", GetLastError() );

//if result is false, there are still open trades, so Total=1 to try to close the
//trades again

Total = 1;
}

}



}

return(0);
}

 
thanks for the comment but I'm afraid, I will not be able to read in Russian... thanks anyway!
 

 

Your system looks like a Grid system with random entry. My_2_Cents, don't waste your time. What exactly is it Not doing when you run it in the tester? Any error codes? etc.

 
ubzen:

Your system looks like a Grid system with random entry. My_2_Cents, don't waste your time. What exactly is it Not doing when you run it in the tester? Any error codes? etc.

ops, sorry, I'm new to this forum, will do it in the future surely...

second point: thanks for pointing out that my EA is a kind of grid system! I didn't know about it.

Anyways, my problem is that yesterday evening when I started test my EA, it did not open any new positions after the first one. After that I have modified it a bit in this morning but since I'm at my workplace, I could not test it if it's working in the tester... I was just interested that if anybody is doing such a system, how he/she codes it. Other words, is my coding logical and should be working at all? Any mistakes, etc?

Thanks!

 

brekeke: ..I was just interested that if anybody is doing such a system, how he/she codes it. Other words, is my coding logical and should be working at all? Any mistakes, etc?...

Yes, this system have been presented on this forum allot of times.

The Coding is obviously different from individual to individual.

Yes, your code appears logical (To Me).

If it's not working, then tell us what's not working.

 

Personally, I'll have to Test your program in the back-tester to figure out if it's doing what your description wants it to do. If it's not doing that, then (I personally) would have to re-write it from top-down. But (I personally) believe the what's wrong part is your responsibility. If you can test it and tell us what it's not doing then there's allot of people here to assist you. 

 
ubzen:

brekeke: ..I was just interested that if anybody is doing such a system, how he/she codes it. Other words, is my coding logical and should be working at all? Any mistakes, etc?...

Yes, this system have been presented on this forum allot of times.

The Coding is obviously different from individual to individual.

Yes, your code appears logical (To Me).

If it's not working, then tell us what's not working.

Personally, I'll have to Test your program in the back-tester to figure out if it's doing what your description wants it to do. If it's not doing that, then (I personally) would have to re-write it from top-down. But (I personally) believe the what's wrong part is your responsibility. If you can test it and tell us what it's not doing then there's allot of people here to assist you.


okay, great. thanks, I will do so and let you know the findings.

By the way, do you think these systems could be profitable? Because in theory it's working but in real life, a lot of conditions can impact your trading... (spread size, news, etc.)

 

Your Sim is moving into an apartment building full of interesting neighbors and a wide variety of pets

Student Loan health care Y8 Games Fun Games

 
brekeke:

okay, great. thanks, I will do so and let you know the findings.

By the way, do you think these systems could be profitable? Because in theory it's working but in real life, a lot of conditions can impact your trading... (spread size, news, etc.)


Yeah, IMO they could work but not in the long run. The primary reason and you said it yourself is the Spread. See, we have to pay to play the game. Most people who use such a system use tp of about 50-100 pips instead of 5-pips. Most spreads are 2-4 pips that about at least average 50% of your movement. Wanna know what the house edge is at the game of blackjack? 1.5% if you're a basic strategy player. The house edge with your system is about 33% given the fact that you're placing random makes it that much worse. You would have a better chance if your entry had an Edge. Try to get an Edge.
 
ubzen:

Yeah, IMO they could work but not in the long run. The primary reason and you said it yourself is the Spread. See, we have to pay to play the game. Most people who use such a system use tp of about 50-100 pips instead of 5-pips. Most spreads are 2-4 pips that about at least average 50% of your movement. Wanna know what the house edge is at the game of blackjack? 1.5% if you're a basic strategy player. The house edge with your system is about 33% given the fact that you're placing random makes it that much worse. You would have a better chance if your entry had an Edge. Try to get an Edge.

ok, so first of all what I think and expect: Of course, the spread is a critical point here because if it goes up to 5 pips then I could not break even. At Alpari UK - allows hedging as well - the spreads are as low as 1.6 pips which is not as good as Oanda's spreads but fear enough to take profits. As I see the biggest problem is that when news come spreads could be even higher than 5 pips. This can cause a serious system breakdown but I'd like to build in a news indicator as well for the long run. In the short run, I would only like to test the system as it is, so the poor frame of the system. Your other point was the position-hedge distance in which this system will work. You mentioned 50-100 pips which can be as high as 150-300 pips as a trading range. IMO, this cannot work in the long run, only if you have such a capital. When you hedge a 50 pip loss, it is not good for your margin. But this point can be overtaken by huge capital. The reason why I'd like to choose a 5-7 pip range is that EURUSD moves approximately 150 pips a day. This means, you can have 20-30 trades a day not couting the ranging periods. So smaller profits to salvage. So imagine that EURUSD cannot break through a 15-21 pip range in either direction... It's absolutely not possible due to the nature of the pair. But fight my thoughts if you have a different point of view after reading my reasoning:) You're welcome!:)

So, to the point: I have tested the code in the evening and it does not work. After opening the first position, the code does not open any new one and even close any of the open ones... Again, I'm not a programmer. You mentioned you would have written it other way. Could you please help me out? Absolutely fine if you might find the mistakes in the current code. Looking forward to read your ideas! Cheers!

Reason: