if(Volume[0]>1) return;is not reliable use Time or iTime() (the same by close)
for(i=0;ma - ma2 < 0;)cycle operator for as to be 3 expression (the same by buy)
if(OrderProfit() > 0 && i == 1)
to use OrderProfit() The order must be previously selected by the OrderSelect() function. (the same by buy)
ma - ma2
use NormalizeDouble() for that
An empty expression is valid in a for loop. You can even do it like this:
for(;;) { }
PipfX, you should loop down when closing orders and I suggest you ask specific questions about specific problems.
Thank you both for the insight!
@Mr. Gordon - I was concerned about lacking the ability to even phrase the question, the issue was baffling me. I need to get my signals to turn on and off trading before I do anything it seems like.
@Mr. Gordon - I was concerned about lacking the ability to even phrase the question, the issue was baffling me. I need to get my signals to turn on and off trading before I do anything it seems like.
The problem is that your question is too broad. Generally, to solve a problem you divide into many small subproblems. For example, your loop to close all orders under specific criteria is a subproblem in your design. It is not done properly, but of course you can't see that because you are concentrating on your overall design which is too broad... You should focus on each and every subproblem in your design, isolate it and verify that it works properly. Only after you are sure all the different sections work properly, focus on your overall design.
That's what I mean about asking specific questions about specific problems...
I understand. Here is is a specific question then. A portion of my trading programs system relies on closing a test trade if it is losing, it's just a bait trade, but using SL isn't very elegant, it's wasted money. I want to close the trade when the value is lower then the opening price. Here is my code so far, and it is not working:
//Can you see anything I am doing wrong with this loop? -- I realized that's not a very specific question.
How can I effectively use OrderProfit() to close a trade?
EDIT: Fixed this part. Thanks for your time :)
for(int i=0;i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break; if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue; //---- check order type if(OrderType()==OP_BUY && ma3 < ma4) { OrderClose(OrderTicket(),OrderLots(),Bid,3,White); break; } if(OrderType()==OP_SELL && ma3 > ma4) { OrderClose(OrderTicket(),OrderLots(),Ask,3,White); break; } if(OrderType()==OP_BUY && OrderProfit() < 0) //Was using 0 to test, doesn't work either. { OrderClose(OrderTicket(),OrderLots(),Bid,3,White); break; } if(OrderType()==OP_SELL && OrderProfit() < 0) //Was using 0 to test, doesn't work either. { OrderClose(OrderTicket(),OrderLots(),Ask,3,White); break; } //----if a trade is losing, close it. }
I hope you realize that when u 'break' you exit the loop so at most you will only be able to close one order in this loop. If this isn't what u are trying yo achieve, then pay close attention to what I mentioned before - you should loop down. See here for explanation -> https://www.mql5.com/en/forum/120128. You should also use an if-else structure, both to speed things up and to avoid a bug where multiple criteria are valid for the same order (maybe not possible in this case, but it's still a better design).
Thanks for the help Mr. Gordon, I had forseen the issue of how I would close multiple orders, but wasn't sure how to tackle the problem. I read the other post, and understand the premise for decrementing it. How would I make that loop decrementing? Yes it's that bad. Thanks for your patience <3.
This code fails, if I make the loop incrementing it works.
for(int i=1;i>OrdersTotal();i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break; if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue; //---- check order type if(OrderType()==OP_BUY && ma3 < ma4 || OrderProfit() < OrderOpenPrice() - 10000) { OrderClose(OrderTicket(),OrderLots(),Bid,3,White); } if(OrderType()==OP_SELL && ma3 > ma4 || OrderProfit() < OrderOpenPrice() - 10000) { OrderClose(OrderTicket(),OrderLots(),Ask,3,White); } if(OrdersTotal()==0)break; //----if a trade is losing, close it. }
See example here -> https://www.mql5.com/en/forum/123968.
Note that you are comparing profit with price... Obviously that won't work.
PipFx
Why not 'simply' track price movement since the time of the initial signal...?
If the movement confirms, you can put the real order on...?
Or is that too simple?
-BB-
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Can someone please take a look at my program and tell me what I am doing wrong? (It's probably a lot!) I am very lost, my head really hurts, I have been working on this for two weeks straight! Help please!!
I have two problems I have repeatedly failed to solve:
+ When the trade signal is present, fire one test trade. If that trade is profitable, fire the real trade. Stop trading until the next signal.
+ When either the test or real trade is less then the trade open, close the trade. Stop trading until the next signal.
That's all I want this EA to do, and I can't seem to get it right!! I have learned a TON about programming in the last two weeks, but I simply lack the technique to solve this problem it feels like. Thank you for your time!