if(iBarHour >= iOpenHour && iBarHour <= iOpenHour + iBarsToTrade && Tradeopen()==false) // Check if time is ok to trade & no trade is open
{
// if(High[2]>High[1] && Low[2]<Low[1]) // see if we have an inside barif(iHigh(hothand(), 60, 2)>iHigh(hothand(), 60, 1) && iLow(hothand(), 60, 2) < iLow(hothand(), 60, 1)) // see if we have an inside bar
{ // on the hothand pair// IB found if(iHigh(hothand(), 60, 1) > dDayOpenPrice) // IB high on hothand pair is greater than day open price bullish signal
{
int buyspread=MarketInfo(hothand(),MODE_SPREAD);
double buyentry = iHigh(hothand(), 60, 1) + 10 + buyspread; //Low of prev bar + 1 pip + spreaddouble buystop = iLow(hothand(), 60, 1) - 10; //Low of prev bar - 1 pipdouble buytpx1 = iHigh(hothand(), 60, 1)+(iHigh(hothand(), 60, 1)-iLow(hothand(), 60, 1)); //1:1 r:rdouble buytpx3 = iHigh(hothand(), 60, 1)+(iHigh(hothand(), 60, 1)-iLow(hothand(), 60, 1))*3; // 1:3 r:rOrderSend(Symbol(),OP_BUY,1 , Ask, 3, buystop, buytpx1, "DIBSBUY", Mnumber1); //Open buy orderOrderSend(Symbol(),OP_BUY,1 , Ask, 3, buystop, buytpx3, "DIBSBUY", Mnumber3);
}
if(iLow(hothand(), 60, 1) < dDayOpenPrice) // IB low on hothand pair is lower than day open price bearish signal
{
int sellspread=MarketInfo(hothand(),MODE_SPREAD);
double sellentry = iLow(hothand(), 60, 1)-10; //Low of prev bar - 1 pip double sellstop = iHigh(hothand(), 60, 1)+ 10 + sellspread; // High of prev bar + 1 pip + Spreaddouble selltpx1 = iLow(hothand(), 60, 1)-(iHigh(hothand(), 60, 1)- iLow(hothand(), 60, 1)); //1:1 r:rdouble selltpx3 = iLow(hothand(), 60, 1)-(iHigh(hothand(), 60, 1)- iLow(hothand(), 60, 1))*3; // 1:3 r:rOrderSend(Symbol(),OP_SELL,1 , Ask, 3, sellstop, selltpx1,"DIBSSELL",Mnumber1); //Open Sell OrderOrderSend(Symbol(),OP_SELL,1 , Ask, 3, sellstop, selltpx3,"DIBSSELL",Mnumber3); //Open Sell Order
}
}
}
//
}
Alright I am back,
This is the part of my code where trades get executed, I am just going to work with 5 digits for the moment. The idea here is I used my hothand function to pick which pair is best to trade for the day. This code should scan for an inside bar on the 1 hour chart. ( The hothand function returns a string of the pair btw) When it finds an inside bar I have just got it to open a flat out buy or sell trade for testing purposes. I am not sure if the backtester can handle trading multiple pairs from 1 chart? I downloaded the 1min history for all the pairs it uses. But it only seems to open trades on the eurusd which is the chart I have attached it to,
WHRoeder thanks for dropping by and helping again also. So is the correct way to open a trade with an ea to open it then go back and fill in the sl and tp after it has opened? I am sure you can spot a million things wrong with that code also.
This is the part of my code where trades get executed, I am just going to work with 5 digits for the moment. The idea here is I used my hothand function to pick which pair is best to trade for the day. This code should scan for an inside bar on the 1 hour chart. ( The hothand function returns a string of the pair btw) When it finds an inside bar I have just got it to open a flat out buy or sell trade for testing purposes. I am not sure if the backtester can handle trading multiple pairs from 1 chart? I downloaded the 1min history for all the pairs it uses. But it only seems to open trades on the eurusd which is the chart I have attached it to,
Some general comments:
you buy at Ask and sell at Bid
if your broker is an ECN type broker you cannot set SL and TP when you place the order (in this case set them to 0), you have to place the order, then modify the order to add the SL & TP
always check the result of placing an order and check for returned errors, you will need to handle these by acting accordingly
if you plan on having this EA on multiple charts, i.e. placing Orders from multiple charts, you will need some kind of Mutex to avoid Order Context Busy (check WHRoeder's posts, he has an excellent Mutex)
Damm WHRoeder, your right "our stops are based on the pair hothand(), but you're opening an order with Symbol()" I did not notice that. How stupid. This stuff just gets so mentally fatiguing whilst your trying to learn it . But yes stupid. Thanks for going over that mess. Ill probably have a break and come back tomorrow with a freash mind. Ill fix them things up you pointed out.
dazamate: Like it doesn't recognize the pair output of the hothand function. The hothand function's output is a string so I dont see what it wont work
OrderSend(hothand(),OP_SELL,1 , Ask, 3, sellstop, selltpx1,"DIBSSELL",Mnumber1); //Open Sell Order
Ask/Bid is the current Symbol() price but you're trying to open another pair. Bogus price.
You can not get bar zero values from the tester for other TF/pairs
You can not open trades of other pairs in the tester, IIRC
unknown symbol name USDCHF for OrderSend function
Where do you get that string? Is the current chart the same pattern, or USD,EUR, or USD/EUR, or USDEURm, or USDEURfxf etc.
I suggest you ONLY trade the current pair. If hothand() isn't the current, no trades. That way it works in the tester, you can always put the EA on other pairs thus controlling which pairs it trades, And you avoid all the pitfalls.
Hey there guys, I am trying to make some code that does the following
externstring sComment4 = "Max Hours allowed before pending orders are deleted";
externint pendinglimit = 4;
// * EVERYTIME A TRADE GETS TRIGGERED
bartraded = TimeHour(TimeCurrent());
// DELETE PENDING ORDERS THAT HAVE NOT BEEN TRIGGERED WITHIN if(TimeHour(TimeCurrent()) > bartraded + pendinglimit && Tradeopen()==true) // Check to see if pending orders have expired
{
for(int tnumber = OrdersTotal()-1; tnumber >= 0 ; tnumber--) //scan through open orders
{
if (OrderSelect(tnumber, SELECT_BY_POS) &&
OrderType()==(OP_BUYSTOP||OP_SELLSTOP) && // The order selected is either a pending buy on stop order or a buy on sell orderOrderMagicNumber()==(Mnumber1||Mnumber3)) // The orders magic number is the same as the magic number used in this ea
{
OrderSelect(tnumber, SELECT_BY_POS); // Select orderOrderDelete(tnumber); // Delete it
}
}
}
If a pending order has been open for x amount of bars delete it if bar number have exceeded x
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Hey Daz & Co,
hothand works on five digit MT4, but not on a four digit platform.
hothand works on five digit MT4, but not on a four digit platform. Any idea what causes this, and any clues on how to fix it?
Alright I am back,
This is the part of my code where trades get executed, I am just going to work with 5 digits for the moment. The idea here is I used my hothand function to pick which pair is best to trade for the day. This code should scan for an inside bar on the 1 hour chart. ( The hothand function returns a string of the pair btw) When it finds an inside bar I have just got it to open a flat out buy or sell trade for testing purposes. I am not sure if the backtester can handle trading multiple pairs from 1 chart? I downloaded the 1min history for all the pairs it uses. But it only seems to open trades on the eurusd which is the chart I have attached it to,
WHRoeder thanks for dropping by and helping again also. So is the correct way to open a trade with an ea to open it then go back and fill in the sl and tp after it has opened? I am sure you can spot a million things wrong with that code also.
Not adjusting slippage for 4/5 digits. Not ECN compatable
Always test return codes so you find out WHY it doesn't work
buystop = iLow(hothand()...Your stops are based on the pair hothand(), but you're opening an order with Symbol(). If they're not the same the stops are completely bogusAlright I am back,
This is the part of my code where trades get executed, I am just going to work with 5 digits for the moment. The idea here is I used my hothand function to pick which pair is best to trade for the day. This code should scan for an inside bar on the 1 hour chart. ( The hothand function returns a string of the pair btw) When it finds an inside bar I have just got it to open a flat out buy or sell trade for testing purposes. I am not sure if the backtester can handle trading multiple pairs from 1 chart? I downloaded the 1min history for all the pairs it uses. But it only seems to open trades on the eurusd which is the chart I have attached it to,
Some general comments:
you buy at Ask and sell at Bid
if your broker is an ECN type broker you cannot set SL and TP when you place the order (in this case set them to 0), you have to place the order, then modify the order to add the SL & TP
always check the result of placing an order and check for returned errors, you will need to handle these by acting accordingly
if you plan on having this EA on multiple charts, i.e. placing Orders from multiple charts, you will need some kind of Mutex to avoid Order Context Busy (check WHRoeder's posts, he has an excellent Mutex)
But it only seems to open trades on the eurusd which is the chart I have attached it to,
Yep, . . .
Symbol() is the pair that the EA/Indicator is attached to, did you mean to do this instead ?
Yes I did mean to do that, but now I get this error
http://clip2net.com/s/144hq
Like it doesn't recognize the pair output of the hothand function. The hothand function's output is a string so I dont see what it wont work
Like it doesn't recognize the pair output of the hothand function. The hothand function's output is a string so I dont see what it wont work
Hey there guys, I am trying to make some code that does the following
If a pending order has been open for x amount of bars delete it if bar number have exceeded x
Something might be wrong with my logic maybe?