- Sākumlapa
- Kopiena
- Programmēšana
- placing order when line is touched not working
Edit Your Comment
placing order when line is touched not working
forex_trader_28046
Biedrs kopš
7 ieraksti
Jan 31, 2011 at 19:41
Biedrs kopš
7 ieraksti
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.
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.
Biedrs kopš
266 ieraksti
Jan 31, 2011 at 20:04
Biedrs kopš
266 ieraksti
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
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
Biedrs kopš
266 ieraksti
Jan 31, 2011 at 20:19
Biedrs kopš
266 ieraksti
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??
Your BarCount used in iHighest(iLowest) must be an integer??
Wealth Creation Through Technology
forex_trader_28046
Biedrs kopš
7 ieraksti
Jan 31, 2011 at 21:08
(labots Jan 31, 2011 at 21:21)
Biedrs kopš
7 ieraksti
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?
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?
*Spams netiks pieļauts, un tā rezultātā var slēgt kontu.
Tip: Posting an image/youtube url will automatically embed it in your post!
Tip: Type the @ sign to auto complete a username participating in this discussion.