Help- Can Anyone explain why the Second Trade Doesn't open?

 

Can Anyone explain why the second trade doesn't open. I'm trying to channel prices with a BUYSTOP and A SELLSTOP But it takes one or the other but not both can someone explain??

" //+------------------------------------------------------------------+
//| Signal Begin(Entry) |
//+------------------------------------------------------------------+

if (Sell1_2 < Sell1_4 && Sell1_3 < Sell1_3) Order = SIGNAL_BUY;

if (Buy1_4 > Buy1_3 && Buy1_1 > Buy1_2) Order = SIGNAL_SELL;


//+------------------------------------------------------------------+
//| Signal End |
//+------------------------------------------------------------------+

int expire = TimeCurrent()+(60*60)*4; //- Expire integer for BUY and Sell 2 hour time frame

//Buy
if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
if(!IsTrade) {
//Check free margin
if (AccountFreeMargin() < (1000 * Lots)) {
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}

if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = Low[1]-5*Point;
if (UseTakeProfit) TakeProfitLevel = Ask + TakeProfit * Point; else TakeProfitLevel = 0.0;

Ticket = OrderSend(Symbol(), OP_BUYSTOP, Lots, High[2], Slippage, StopLossLevel, TakeProfitLevel, "Breakout Reversal Buy", MagicNumber, expire, DodgerBlue);
if(Ticket <= 4 ) { //-if(Ticket <= 2 ) {
if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
Print("BUY order opened : ", OrderOpenPrice());
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");
} else {
Print("Error opening BUY order : ", GetLastError());
}
}
if (EachTickMode) TickCheck = True;
if (!EachTickMode) BarCount = Bars;
return(0);
}
}

//Sell
if (Order == SIGNAL_SELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
if(!IsTrade) {
//Check free margin
if (AccountFreeMargin() < (1000 * Lots)) {
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}

if (UseStopLoss) StopLossLevel = Bid + StopLoss * Point; else StopLossLevel = High[1]+5*Point;
if (UseTakeProfit) TakeProfitLevel = Bid - TakeProfit * Point; else TakeProfitLevel = 0.0;

// if(OrdersTotal() == 1) //= allowing second hedge trade

Ticket = OrderSend(Symbol(), OP_SELLSTOP, Lots, Low[2], Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + MagicNumber + ")", MagicNumber, expire, DeepPink);
if(Ticket <= 4) { //-if(Ticket <= 2) {
if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
Print("SELL order opened : ", OrderOpenPrice());
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell");
} else {
Print("Error opening SELL order : ", GetLastError());
}
}
if (EachTickMode) TickCheck = True;
if (!EachTickMode) BarCount = Bars;
return(0);
}
}

if (!EachTickMode) BarCount = Bars;

return(0);""

 

Hello,

1. Ticket is designed to be used to id an order. Is assigned by server. Not going to be <=4 ..., total mistaken usage.

2. You make no attempts at checking OrderSend() status. How do you know was OK? at least check for <=0 ...

3. What about retry loop IF send fails due to a retryable status code ?

...

just a few observations

Regards

.

please consider using the SRC button.

formatted code is actually a good idea.

thanks.

 
fbj wrote >>

Hello,

1. Ticket is designed to be used to id an order. Is assigned by server. Not going to be <=4 ..., total mistaken usage.

2. You make no attempts at checking OrderSend() status. How do you know was OK? at least check for <=0 ...

3. What about retry loop IF send fails due to a retryable status code ?

...

just a few observations

Regards

.

please consider using the SRC button.

formatted code is actually a good idea.

thanks.

I am really having a hard time figuring this stuff out, I'm close with a few little hangups. Are you referring to this piece of code:

if (EachTickMode && Bars != BarCount) TickCheck = False;
Total = OrdersTotal();
Order = SIGNAL_NONE;

bool IsTrade = False;

for (int i = 0; i < Total; i ++) {
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderType() <= OP_BUYSTOP && OrderSymbol() == Symbol()) { //-Sell Stop Makes Sells
IsTrade = True;
if(OrderType() == OP_SELLSTOP) {

Does this Stop the second order from being opened? Thanks for the reply, Jim

 

Now you're just guessing.

Why not take the well trodden route - consult the documentation and appraise yourself of what each line actually does.

Its not that difficult.

AND EVERYONE ***PLEASE*** STOP INCREMENTING UPWARDS IN TRADE/HISTORY LOOPS!!!

Whoever first posted the code snippet with that in it ought to be banned from touching a keyboard.


CB

 
It's not guessing IT's GRASPING!!! I've learned and wrote, the indicator which shows when my Buy and Sell should happen. I started this EA on the EA builder, and added buy_Stop info and variables to make it work for me, and also figured out how to make the stop orders expire after X number of bars. For having no programming experience (except for Basic in 1985) I have learned a freakin boatload over the past few weeks about MQL4, but throw a guy a bone what the heck am I MISSING!! How do you open a Buy stop and Sell stop at the same time. I either get one side of the trade or I get 28 trades opened in 28 ticks!!! I'm goin Nuckin Futs!!
 
cloudbreaker wrote >>

Now you're just guessing.

Why not take the well trodden route - consult the documentation and appraise yourself of what each line actually does.

Its not that difficult.

AND EVERYONE ***PLEASE*** STOP INCREMENTING UPWARDS IN TRADE/HISTORY LOOPS!!!

Whoever first posted the code snippet with that in it ought to be banned from touching a keyboard.

CB

If I had a dime for each...!

You know, seeing ++ just turns my stomach these days. Absolutely NO idea as to the potential catastrophic's to ones a/c. Is sad, but I refuse to comment on that anymore. Why bother? Makes not a hill 'o beans worth of difference once scrolls offa 'da front page!


Again, IF this site was a real forum THEN do's 'n dont's could be sticky etc, etc....


And - not just dry material but the WHY'S too! So many just demonstrate when publish code that not have a clue. I still believe that is down to the greed aspect of trading and how anyone can "get feet wet" [and ultimately burnt]. We all must learn but hey! talkin money here, not just some academic walk in the park...


Yes... on the surface MT appears to be tolerant. But 24/7 fault tolerant? I think not!


Additionally, I sincerely wish that people check in their ego at reception prior engaging in banter on this site. May seem hard but surely is obvious that the world's ills are mostly generated by egocentric pygmies and fruitful dialogue is near on impossible with such traits manifesting every other word...

Man... must be Sun. My soapbox came out this a.m. and has been literally creaking with my ramblings :o)


CB - http://catb.org/esr/faqs/smart-questions.html where in the heck do you come up with these things. Man... I feel so clueless about what's out there and actually, not really know what, how etc. to become more net content savy.

Any pointers? (besides time honoured route of my Colt 45, that is :-)

 
Yentrader2 wrote >>
It's not guessing IT's GRASPING!!! I've learned and wrote, the indicator which shows when my Buy and Sell should happen. I started this EA on the EA builder, and added buy_Stop info and variables to make it work for me, and also figured out how to make the stop orders expire after X number of bars. For having no programming experience (except for Basic in 1985) I have learned a freakin boatload over the past few weeks about MQL4, but throw a guy a bone what the heck am I MISSING!! How do you open a Buy stop and Sell stop at the same time. I either get one side of the trade or I get 28 trades opened in 28 ticks!!! I'm goin Nuckin Futs!!

Hello again Yen,

Frustration is part 'n parcel of this show.

Well done in your "past few weeks" progress. However, in the end. The MQL Book was crafted to enable virtually anyone to get a handle on MT.

Not easy at all. I have been coming up to 10yrs messing around with it and still useless in many areas. The one trait I encourage in myself and others that care to listen is that of self-help.

There are many massive intellects on this site. There are also many less endowed in the MT smarts department. It can happen that the less able are the ones which promote their opinions and help. Fine... maybe, but picking up information from unsound sources just ensures that more unsound information is birthed within those that read and take it on board their own KB.

How does one really know what is 'unsound' information?

Well, tbh, I believe that it is up to each to test information for soundness. Two fold increase in ones KB can happen: 1. by learning HowTo test for correctness, one learns the tools of the trade more intimately and 2. One can, via 1., know that the information is sound or not and amend accordingly to become more sound...

Personally, I have spent more time writing test code over the yrs than I'll ever write as money making production code.

Now, I do not know what your code is. You mention the use of Trade Operations. You also mention "How do you open a Buy stop and Sell stop at the same time." Well Yen..., you cannot.

That is exactely why you must not stress over programming, which is just in the end a way to talk, yes? You need to understand the MT setup so that when you talk [program], the words comming out [code lines] are not only correct but in the correct order, yes? Programming is cool BUT the meat of any system is it's methods of fully utilizing the system with which it works under ie, MT.

Until one appreciates the issues presented to them when using MT, they are just not going to be effective [enough] to cut it.

All of course imho, but I do mean well Yen and trully sympathise with you but the ball really is in your court.

Please practice that self-help some, ok?

Just read, read and read some more. You not only learn about MT, you also see syntax, code lines, ways of thinking/tackling problems. It helps soooo much when crafting 'your final solution'!

Additionally, it does not actually matter that you do not understand it all... just keep reading.

Is well known process of learning. Take in what you can and quietly pass over that you cannot grasp. Eventually, the more that is taken in allows you to re-visit those areas which proved ungraspable... Hey presto! what once seemed gibberish all of a sudden makes sense!

Eventually, one developes ones own style and can 'see' that some styles are actually... not very stylish at all! ie, you have your own opinions now and [hopefully] you'll know they are a-ok cuz you've done the self-help stuff and tested and learned by making those essential to learning... mistakes :)

Enjoy it all Yen.

Regards

 

Wow, I feel like the kid who wants to finish his essay, but can't spell one word. The child asks the parent for help and parent tells the child to look it up, and the child's response is, "if I knew how to look it up I wouldn't have asked the question in the first place!!" I feel these answers are more complex than my little ole question. When I said the last few weeks of working, I mean literally every waking hour and every spare minute at work!! The pieve of code I referenced above is about the only part i an't understand, so i assume that that is where the answer lies. I have searched over and over and over, Do you boys remember reading the documentation way back when? It's not exactly like a recipe that you follow! The documentation alone is pretty overwhelming, but anyway, whatever, and thanks.

And yeah:

"AND EVERYONE ***PLEASE*** STOP INCREMENTING UPWARDS IN TRADE/HISTORY LOOPS!!!"

Nothing pisses me off more than some dweezel who continues to INCREMENT UPWARDS!!

Is that what I'm doing?, i didn't mean to, is that a hint?

Regards

As of Now, Manual - Yentrader2

 
Yentrader2:

I started this EA on the EA builder [...]

I think that's part of the problem; it looks like you started out with code built by something like http://eatbuilder.com/. It's not that bad as automated systems go, but it's producing the sort of code which tends to make experts like CB and fbj scream with horror. Taking the following example from its template:


Ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);
if(Ticket > 0) {
if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
Print("SELL order opened : ", OrderOpenPrice());
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell");
} else {
Print("Error opening SELL order : ", GetLastError());
}
}

This is not very good. It's not logging errors if order placement fails (i.e. OrderSend() < 0). It's only logging errors in the vastly unlikely event that OrderSend() suceeds but OrderSelect() then fails. Basically, the automatically generated code contains bugs.


And I'm a bit mystified by what appears to be your personal amendment of the automated code to do "if(Ticket <= 4 )". I can't see what this is meant to achieve.


Wow, I feel like the kid who wants to finish his essay, but can't spell one word.

Putting it another way, the trouble is that you're a bit like the kid who started his essay by copying from the dunce in the next-door desk.

 

Oh boy... some cool code. auto gened stuff is such the wrong end of the stick to grasp at the start [erm, any time really :]

.

Yen, you start the reading and very soon you'll be playing around with eg, the samples that came with your MT install. Is fun and instructive. Use the Print() and Comment() builtins.

Even there, you'll soon get annoyed that Comment() always zaps the last comment put on the screen. Then... you probably realise [having read around about Comment() and Print() and the string type, that you can embed linefeed,return or newline characters into a string and hey presto! multiline comments magically appear! Again, is fun and loads of sweat as well.

Testing with scripts is massively instructive and very fast too! The editor and terminal environment makes for fast edit, compile, test cycles by just a few function key presses!

.

btw, I'm far from being an expert - not understand tenth of what gets bantered around on this forum. But I know HowTo use that Print() statement - LOL

.

All the best Yen.

Looking forwards to seeing your first bit of coding.

Regards

 
jjc wrote >>

I think that's part of the problem; it looks like you started out with code built by something like http://eatbuilder.com/. It's not that bad as automated systems go, but it's producing the sort of code which tends to make experts like CB and fbj scream with horror. Taking the following example from its template:

This is not very good. It's not logging errors if order placement fails (i.e. OrderSend() < 0). It's only logging errors in the vastly unlikely event that OrderSend() suceeds but OrderSelect() then fails. Basically, the automatically generated code contains bugs.

And I'm a bit mystified by what appears to be your personal amendment of the automated code to do "if(Ticket <= 4 )". I can't see what this is meant to achieve.

Putting it another way, the trouble is that you're a bit like the kid who started his essay by copying from the dunce in the next-door desk.

if(Ticket <= 4 ) { //-if(Ticket <= 2 ) {

Yeah, This is my little brainstorming solution. I copy the existing code, turn it into a comment and make changes to it and see how it falls apart. This is the same method I used to make my indicator. Being a noobie, I didn't really know there were more than one way to accomplish a given task. I just assumed the EA builder coded certain sections how they were supposed to be coded and minor changes to that section could make it perform differently. I was thinking that maybe a loop in the ticket number prevented the opposite side of the trade to be placed. Obiously I havn't made it too far past my loriginal ogic Thanks for the support.

Reason: