| / | Forum |
|
devilian1899
2008.01.20 14:20
Hello,
This code's purpose is to check if there's any active order opened by this EA. If none, it will open 2 orders, buy and sell. I haven't test it on real market because it's sunday now, but from backtester, there's no trade appear. What's wrong with these codes? int ordtotal=0; for(int ft=OrdersTotal()-1;ft>=0;ft--) { OrderSelect(ft,SELECT_BY_POS,MODE_TRADES); if(OrderSymbol()==Symbol() && OrderComment()==comment && OrderMagicNumber()==magic) { if(OrderType()<=OP_SELL) ordtotal++; } } int Pips=30; //- first trade if(ordtotal<0) { while(b<0) { buyticket=OrderSend(Symbol(),OP_BUY,Lots(),Ask,Slippage,0,Ask+Pips*Point,0,magic,0,Blue); if(buyticket>0) b=1; } while(s<0) { sellticket=OrderSend(Symbol(),OP_SELL,Lots(),Bid,Slippage,0,Bid-Pips*Point,0,magic,0,Red); if(sellticket>0) s=1; } }Thank you |
|
Simultaneous Displaying of the Signals of Several Indicators from the Four Timeframes While manual trading you have to keep an eye on the values of several indicators. It is a little bit different from mechanical trading. If you have two or three indicators and you have chosen a one timeframe for trading, it is not a complicated task. But what will you do if you have five or six indicators and your trading strategy requires considering the signals on the several timeframes? |
|
Automated
2008.01.20 16:48
One thing you may want to change is if ( ordtotal < 0 ) from the chunk of code you posted you could see that the ordtotal will never get below 0, therefore the lines inside the if block will never get executed... Also take a look at this line please: while ( b < 0 ) it will never get executed unless b<0, however I dont see anywhere in the code you initialize b with a value less then 0, so the lines inside the loop will never get executed i.e. a trade wont be opened...the same is true for the sell order. .. |
|
devilian1899
2008.01.20 18:39
Automated wrote: Damn you're right, how can I be so stupid? Too much love maybe, lolololol..One thing you may want to change is if ( ordtotal < 0 ) from the chunk of code you posted you could see that the ordtotal will never get below 0, therefore the lines inside the if block will never get executed... Also take a look at this line please: while ( b < 0 ) it will never get executed unless b<0, however I dont see anywhere in the code you initialize b with a value less then 0, so the lines inside the loop will never get executed i.e. a trade wont be opened...the same is true for the sell order. .. Thanks a lot |
|
Automated
2008.01.21 03:55
you are welcome :) you could always contact me at automatedfx@gmail.com if you would like to discuss it further... thank you Automated |
|
devilian1899
2008.01.21 15:03
Thanks automated for your offer, but it's already solved now :)
Thank you |
|
bdht
2008.01.22 03:34
I have started coding my EA. I am by no means a decent coder for MQL b/c I've never
seen C++/C. #property copyright "Copyright © 2008 BDHT" #define MAGIC 689 //do not take into consideration //the names of the indicators //they're fabricated extern double lots = 0.1; // Lots extern double TP = 140; // Take Profit extern double SL = 30; // Stop Loss static int prevtime = 0; static int res = 0; double IND2_line1, IND2_line2, IND1, IND1_prev, IND2_line1_prev; int init() { IND2_line1 = iIND2_line1(NULL,0,0,MODE_MAIN,0); IND2_line2 = iIND2_line2(NULL,0,0,MODE_SIGNAL,0); IND1= iCustom(NULL, 0, "IND1", 0, 0, 0); IND1_prev= iCustom(NULL,0, "IND1", 0, 0, 1); IND2_line1_prev = iCustom(NULL, 0, "IND2", 0, 0, 1); return(0); } int deinit() { return(0); } int start() { //Make sure there are no open orders; if yes - stop if (OrdersTotal() > 0) return (0); if (IND1< 0 && IND1 < IND1_prev && IND1_prev > 70 && IND2_line1 < 0 && IND2_line2 < 0) { // 70 may be 10; simply means that the IND1_prev was greater than 0 res=OrderSend(Symbol(),OP_SELL,lots,Bid,3,Bid+SL*Point,Ask+TP*Point,"My EA",MAGIC,0,Blue); return(0); } if (IND2_line1 > IND2_line2 && IND2_line1_prev < IND2_line1) { res=OrderSend(Symbol(),OP_BUY,lots,Ask,3,Ask+SL*Point,Bid+TP*Point,"My EA",MAGIC,0,Blue); return(0); }It doesn't graph anything either... I know there has to be something wrong, but what is it? |
|
phy
2008.01.22 04:56
There are many problems with your code. |
|
bdht
2008.01.22 04:59
Okay. That's understood, what are the problems? Could you point out some?
|
|
phy
2008.01.22 05:12
One problem, code within init() is only executed one time. |
|
bdht
2008.01.22 05:22
Does this mean that there should be a loop? Doesn't the int start() execute every
time there is a new bar? Is this what you meant?
|
|
phy
2008.01.22 05:27
Code withing start() executes every tick Code within init() executes once per intitialization/start/restart of the EA |