MQL4 Learning - page 94

 

problem with my first EA with T3 Tilsons

Hi good day, I'm just learning how to program in mql4, I read the interesting tutorial hosted in this site which gave an EA basics, and I made small modifications to it so I could built my own. Here is the code, as you can see it's a simple T3 Tilson crossover, that gets called with the iCustom function, the T3 indicator I downloaded it from metaquites site.

However when I add the EA into any chart the expert logs starts going crazy. let's say I add the EA to a USDCAD chart, the log says

T3EA USDCAD loaded successfullly

T3EA USDCAD inputs...........

T3EA USDCAD iniitialized

but then it starts going crazy right away , and it says

T3 USDCAD , M1 initialized

T3 USDCAD , M1 loaded successfully

T3 USDCAD , M1 initialized

T3 USDCAD , M1 loaded successfully

T3 USDCAD , M1 initialized

T3 USDCAD , M1 loaded successfully

T3 USDCAD , M1 initialized

T3 USDCAD , M1 loaded successfully

all over again over and over.........

and when I remove the EA the log will say

T3EA USDCAD denitialized

T3 EA USDCAD uninit reason 1

and then right away

T3 USDCAD M1, deinitialized

T3 USDCAD M1, uninit reason 1

T3 USDCAD M1, removed.

T3 USDCAD M1, deinitialized

T3 USDCAD M1, uninit reason 1

T3 USDCAD M1, removed.

all over again........ until I close the chart I was working on.

so far I haven't seen the EA placing any trades...... So I think all of this is related.....

any ideas how can I get it to work??

here is the code, thank in advance.

//---- input parameters

extern double TakeProfit=250.0;

extern double Lots=0.1;

extern double TrailingStop=35.0;

//+------------------------------------------------------------------+

//| expert initialization function |

//+------------------------------------------------------------------+

int init()

{

//----

//----

return(0);

}

//+------------------------------------------------------------------+

//| expert deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

//----

//----

return(0);

}

int Crossed (double line1 , double line2)

{

static int last_direction = 0;

static int current_dirction = 0;

if(line1>line2)current_dirction = 1; //up

if(line1<line2)current_dirction = 2; //down

if(current_dirction != last_direction) //changed

{

last_direction = current_dirction;

return (last_direction);

}

else

{

return (0);

}

}

//+------------------------------------------------------------------+

//| expert start function |

//+------------------------------------------------------------------+

int start()

{

//----

int cnt, ticket, total;

double shortT3, longT3;

if(Bars<100)

{

Print("bars less than 100");

return(0);

}

if(TakeProfit<10)

{

Print("TakeProfit less than 10");

return(0); // check TakeProfit

}

shortT3 = iCustom(NULL,0,"T3",10,0,0);

longT3 = iCustom(NULL,0,"T3",21,0,0);

int isCrossed = Crossed (shortT3,longT3);

total = OrdersTotal();

if(total < 1)

{

if(isCrossed == 1)

{

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,"My EA",12345,0,Green);

if(ticket>0)

{

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());

}

else Print("Error opening BUY order : ",GetLastError());

return(0);

}

if(isCrossed == 2)

{

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,"My EA",12345,0,Red);

if(ticket>0)

{

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());

}

else Print("Error opening SELL order : ",GetLastError());

return(0);

}

return(0);

}

for(cnt=0;cnt<total;cnt++)

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())

{

if(OrderType()==OP_BUY) // long position is opened

{

// should it be closed?

if(isCrossed == 2)

{

OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position

return(0); // exit

}

// check for trailing stop

if(TrailingStop>0)

{

if(Bid-OrderOpenPrice()>Point*TrailingStop)

{

if(OrderStopLoss()<Bid-Point*TrailingStop)

{

OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);

return(0);

}

}

}

}

else // go to short position

{

// should it be closed?

if(isCrossed == 1)

{

OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position

return(0); // exit

}

// check for trailing stop

if(TrailingStop>0)

{

if((OrderOpenPrice()-Ask)>(Point*TrailingStop))

{

if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))

{

OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);

return(0);

}

}

}

}

}

}

return(0);

}

//+------------------------------------------------------------------+

 

Script for hiding comments??

Does this exist?? For example, you have an EA, which you share performance of it with to a trade group. However you do not want to have the comments show up. Is there a script or an add on that can be implemented to hide all comments? Or must this be changed directly in the EA?

Any information would be greatly appreciated.

SUAP

 

For the main reason that we wish to keep the system's names private for a period of time. We have one EA developer who says this is not a problem to change, but the other has it hard coded into his EA and doesnt want to change it. The script or tool could either change, or just mask the comments.

 
lightman:
Hi good day, I'm just learning how to program in mql4, I read the interesting tutorial hosted in this site which gave an EA basics, and I made small modifications to it so I could built my own. Here is the code, as you can see it's a simple T3 Tilson crossover, that gets called with the iCustom function, the T3 indicator I downloaded it from metaquites site.

However when I add the EA into any chart the expert logs starts going crazy. let's say I add the EA to a USDCAD chart, the log says

T3EA USDCAD loaded successfully

T3EA USDCAD inputs..........

T3EA USDCAD iniitialized

but then it starts going crazy right away , and it says

T3 USDCAD , M1 initialized

T3 USDCAD , M1 loaded successfully

..

..

so far I haven't seen the EA placing any trades...... So I think all of this is related.....

any ideas how can I get it to work??

Hi Lightman,

I was able to compile and test your T3 EA...and it worked fine. I tried it on UsdCad M15 and H1 and it ran without any log errors. As you can see from the screen shot...it is working correctly making the trades at the crossings. I used a smaller TP and TS in this example.

Without knowing all the steps you are trying, I'm not sure why you are getting those 'deinit and removed' messages and no trades? I only got them at the end of the test run, and it was just normal closing out the indicators after testing - in any case they did not affect the EA making trades. It would be interesting to see your entire log to see what's happening.

I have attached my compiled test version for you to try. I named it "T3 EA - Test1" to make sure no one assumes it's a finished EA.

The crossing code and TP works fine. The SL for this EA is limited to the crossbacks, which makes it unprofitable and may need modification with more SL options. This EA is ok for learning and testing, but I did not find any quick winning settings.

There are a number of good/great MA EA's here on TSD - I would suggest that you look at them and compare the codes...great way to learn...and you can always add your T3 iCustom to those codes if you find the features you want in your EA (like SL or other options).

Hope this helps,

Robert

 
 
 

Timeframe change

Hi!

Which is the code as to make the EA to understand if there is or not a timeframe change? For example if we use H1 frames, which is the key point to denote the creation of the new timeframe?

Thank you

 

Are you talking about timeframes or candles? To detect new candle read Time[ 0 ], store it, and compare the stored value with Time[ 0 ] on next tick.

 

Ammending and EA

Hi CodersGuru,

I have an EA that essentially opens a trade when an indicator threshold is reached and then closes it when another threshold is reached. It immediately opens new opposite direction trade upon closing the current trade. This way there is always a trade going on.

Now, I have found that the closing of a current trade and the opening of an opposite new trade works perfectly on a demo account. When I run it on a live account I notice, in the EA journal, that the EA does send a signal to the platform at the appropriate time to open a new opposite trade, upon the closing of the current trade, but the new opposite trade does not ever get executed on the live platform. The only thing I can put it down to is that on demo the orders are executed instantly, but on live it can take several seconds. And because the EA sends the closing of an order and the opening of the new opposite order so close together that the platform misses the opening of the new opposite trade because it has taken several seconds (20 in some instances) to close the current trade.

The code does have a "sleep(1000)" line in it, between closing of a current trade and opening of a new opposite one. I suspect I need to pump up the "sleep" to say (20000). Do you think this would most likely resolve the problem??

Also, The EA is currently running on the live account. If I open the MT4 editor and just change the program line to "sleep (20000)" instead of "sleep(1000)" will this take affect immediately even though the EA is currently loaded and running? Or do I need to close the platform, edit the EA, re-load the EA in the experts folder and then finally re-load the EA on the chart again??

Also, do I need to compile it to get an exe file, or will the current exe file in the experts folder simply be adjusted automatically if I change the mq4 file?

thank you so much in advance for your valuable advise.

 

Please help guys!

Hey guys,

Really quick question and i would really appreciate some help on this... simple question... but too hard for me...

How do I modify an EA so that it will only take a trade if the previous bars Volume was greater that the baar before that...

So

1) Bar closes

2) Confirmed entry bar

3) Check if volume was increasing on that bar

4) Then enter trade.

Thanks alot!!!

Reason: