placing order when line is touched not working

Jan 31, 2011 at 19:41
935 개의 뷰
3 Replies
ido370
forex_trader_28046
Jan 26, 2011 부터 멤버   게시물7
Jan 31, 2011 at 19:41
im having difficulties with my code, in backtesting it does not place 2 pending orders when it reaches the middle white line on screen.
code for the middle white line:
BarCount = NormalizeDouble((iATR(NULL,1440 ,200,0)/MarketInfo(Symbol(),MODE_POINT))/10,0);
double value = High[iHighest(NULL,0,MODE_HIGH,BarCount,1)] - Low[iLowest(NULL,0,MODE_LOW,BarCount,1)];
double sixth = value/6;
MiddleWhiteLine = NormalizeDouble(Low[iLowest(NULL,0,MODE_LOW,BarCount,1)]+sixth+sixth+sixth, Digits);

the variables for 5 digit broker i use:
//++++ These are adjusted for 5 digit brokers.
double pips2points, // slippage 3 pips 3=points 30=points
        pips2dbl; // Stoploss 15 pips 0.0015 0.00150
int Digits.pips; // DoubleToStr(dbl/pips2dbl, Digits.pips)

in my EA init i have:
if (Digits == 5 || Digits == 3)
   { // Adjust for five (5) digit brokers.
               pips2dbl = Point*10; pips2points = 10; Digits.pips = 1;
   } else { pips2dbl = Point; pips2points = 1; Digits.pips = 0; }

For placing the pending orders i use:
//CENTERLINE ORDER
   if (Ask == MiddleWhiteLine) {
     entryw1 = TopGreenLine;
     TPw1 = TopGoldLine;
     SLw1 = MiddleWhiteLine;
     entryw2 = BottomGreenLine;
     TPw2 = BottomGoldLine;
     SLw2 = MiddleWhiteLine;
     Print('Pending GSPE Orders placed');
     OrderSend(Symbol(),OP_BUYSTOP,lots,entryw1,100,SLw1,TPw1,NULL,MagicNumber,0,Blue);
     Sleep(1000);
     OrderSend(Symbol(),OP_SELLSTOP,lots,entryw2,100,SLw2,TPw2,NULL,MagicNumber,0,Red);
   }
   //END CENTERLINE ORDER

Hopefully someone can tell me why it's not working, and what i should change.

Aug 20, 2009 부터 멤버   게시물266
Jan 31, 2011 at 20:04
It is virtually impossible to compare 2 doubles in MQL4, so your case of Ask==MiddleWhiteLine will just about never be true, even though to you, visually it may 'appear' to be true.

Try giving it a bit of slack, so perhaps check if the MiddleWhiteLine falls between the spread eg :-

if(Ask>=MiddleWhiteLine && Bid<=MiddleWhiteLine)...............etc

Also the sleep command between your orders is superfluous and will cause quote problems. Why is it there? I would just delete it and if you really must leave it there, then do a RefreshRates() before the second order.

Another thing, if you are working with only the currenct chart symbol only then you do not need marketinfo to get the point value......just use Point. It makes the code shorter and easier to read. I have not really examined the code but I think that your BarCount should use Point * 10 and not divided by 10.

Hope it helps
Wealth Creation Through Technology
Aug 20, 2009 부터 멤버   게시물266
Jan 31, 2011 at 20:19
In fact looking at it, the whole BarCount line just does not make any sense at all. You are calculating the daily ATR value and then using that as a number of bars that you need to count back to get the highest and lowest values in a timeseries array?

Your BarCount used in iHighest(iLowest) must be an integer??
Wealth Creation Through Technology
ido370
forex_trader_28046
Jan 26, 2011 부터 멤버   게시물7
Jan 31, 2011 at 21:08 (편집됨 Jan 31, 2011 at 21:21)
hi kenny, i changed it to 'Ask>=MiddleWhiteLine && Bid<=MiddleWhiteLine' like you told (right now it works, it just placed two pendings in backtest!), and removed the Sleep command. i thought it would be necessary because there were 2 orders directly after eacht other, so i thought they would need some time between to process :)
The barcount code is not really mine, its from a topic sixth trading on forexfactory (ea made by stevehopwood and macman), so don't know exactly how it works, but it was 'strangled' in the drawing of the lines, so i left it there..
my topic is also on forexfactory since i could make a post with the complet EA code there: https://www.forexfactory.com/showthread.php?t=275707
 could you also tell me how to delete the opposite pending order, when a pending order is opened?
로그인 / 가입하기 to comment
You must be connected to Myfxbook in order to leave a comment
*상업적 사용 및 스팸은 허용되지 않으며 계정이 해지될 수 있습니다.
팁: 이미지/유튜브 URL을 게시하면 게시물에 자동으로 삽입됩니다!
팁: @기호를 입력하여 이 토론에 참여하는 사용자 이름을 자동으로 완성합니다.