Forex
Google

Go Back   Forex Trading > Metatrader Training > Metatrader 4 mql 4 - Development course > Questions
Forex Forum Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-22-2005, 08:11 PM
trevman2005 trevman2005 is offline
Junior Member
 
Join Date: Dec 2005
Posts: 6
trevman2005 is on a distinguished road
buy order problems

this bit of code doesnt seem to buy, any ideas why?
Code:
   if(Close[2]<ma && Close[1]>ma)
   {
    OrderSend(Symbol(),OP_BUY,lots,Ask,3,stop,Ask+profit,"",2005,0,Green);
   }
it should buy when a new candle closes above the moving average and the previous closed below it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 12-22-2005, 09:38 PM
codersguru's Avatar
codersguru codersguru is offline
Senior Member
 
Join Date: Oct 2005
Posts: 987
codersguru has a spectacular aura aboutcodersguru has a spectacular aura aboutcodersguru has a spectacular aura about
Arrow

Quote:
Originally Posted by trevman2005
this bit of code doesnt seem to buy, any ideas why?
Code:
   if(Close[2]<ma && Close[1]>ma)
   {
    OrderSend(Symbol(),OP_BUY,lots,Ask,3,stop,Ask+profit,"",2005,0,Green);
   }
it should buy when a new candle closes above the moving average and the previous closed below it.
I think it should be:

PHP Code:
 if(Close[1]<ma && Close[0]>ma)
  {
   
ticket=OrderSend(Symbol(),OP_BUY,lots,Ask,3,stop*Point,Ask+profit*Point,"",2005,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);

__________________
Hope it helps !
Coders' Guru
Senior MQL programmer:
www.xpworx.com/custom.htm
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 12-22-2005, 09:46 PM
trevman2005 trevman2005 is offline
Junior Member
 
Join Date: Dec 2005
Posts: 6
trevman2005 is on a distinguished road
that worked, very much appreciated, but why the "ticket", "orderselect" and "Point" x ask+profit?, i'm reading through your tutorials atm, i apologise if i missed this info. thanks again.

Last edited by trevman2005 : 12-22-2005 at 09:50 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 12-22-2005, 10:00 PM
codersguru's Avatar
codersguru codersguru is offline
Senior Member
 
Join Date: Oct 2005
Posts: 987
codersguru has a spectacular aura aboutcodersguru has a spectacular aura aboutcodersguru has a spectacular aura about
Arrow You're welcome!

Quote:
Originally Posted by trevman2005
that worked, very much appreciated, but why the "ticket" and "orderselect" i'm reading through your tutorials atm, i apologise if i missed this info. thanks again.
You're welcome!


If you noticed the code:


1- I've changed

if(Close[2]<ma && Close[1]>ma)

To:

if(Close[1]<ma && Close[0]>ma)

Because the index of the new bar is 0 and the index of the previous one is 1.


2- I used ticket and OrderSelect only to check what the wrong (if any) is.
(Please prefer to
Appendix 2 - Trading functions)


3- I've changed stop to stop*Point and profit to profit*Point.
__________________
Hope it helps !
Coders' Guru
Senior MQL programmer:
www.xpworx.com/custom.htm
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 12-23-2005, 08:06 AM
trevman2005 trevman2005 is offline
Junior Member
 
Join Date: Dec 2005
Posts: 6
trevman2005 is on a distinguished road
Quote:
Originally Posted by codersguru
3- I've changed stop to stop*Point and profit to profit*Point.[/color][/size][/font][/left]
why does point need to be a part of the code?

i've also noticed that my stoploss is set to 30 and my take profit is 80, yet my backtest results give me around 17 loss and 45 profit, why does it do this? thanks again.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 12-23-2005, 02:05 PM
codersguru's Avatar
codersguru codersguru is offline
Senior Member
 
Join Date: Oct 2005
Posts: 987
codersguru has a spectacular aura aboutcodersguru has a spectacular aura aboutcodersguru has a spectacular aura about
Arrow Point

Quote:
Originally Posted by trevman2005
why does point need to be a part of the code?
Point function returns the point size of the current symbol.
(EX: if you trade EURUSD the point value = .0001 and if you trade EURJPY the point value should be .01)
So, if your stoploss must be converted to points in order to use OrderSend or OrderModify functions.

Quote:
i've also noticed that my stoploss is set to 30 and my take profit is 80, yet my backtest results give me around 17 loss and 45 profit, why does it do this? thanks again.
Could you explain more? Do you mean that the strategy tester automatically set your stoploss and takeprofit values?
__________________
Hope it helps !
Coders' Guru
Senior MQL programmer:
www.xpworx.com/custom.htm
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 12-23-2005, 02:20 PM
trevman2005 trevman2005 is offline
Junior Member
 
Join Date: Dec 2005
Posts: 6
trevman2005 is on a distinguished road
Quote:
Originally Posted by codersguru
Point function returns the point size of the current symbol.
(EX: if you trade EURUSD the point value = .0001 and if you trade EURJPY the point value should be .01)
So, if your stoploss must be converted to points in order to use OrderSend or OrderModify functions.
"Ask+profit*Point" should be equal to whatever i set my profit level at right?, but if "ask" is 1.1825 and "profit" is 50 then "1.1825+80*1.1825" but that equals 95

Quote:
Originally Posted by codersguru
Could you explain more? Do you mean that the strategy tester automatically set your stoploss and takeprofit values?
my expert has the below settings as default
extern double profit = 80;
extern double stop = 30;

but backtesting produced t/p stops of 45-46 and stoploss losses of 17

Last edited by trevman2005 : 12-23-2005 at 02:24 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 12-23-2005, 02:37 PM
codersguru's Avatar
codersguru codersguru is offline
Senior Member
 
Join Date: Oct 2005
Posts: 987
codersguru has a spectacular aura aboutcodersguru has a spectacular aura aboutcodersguru has a spectacular aura about
Arrow

Quote:
Originally Posted by trevman2005
"Ask+profit*Point" should be equal to whatever i set my profit level at right?, but if "ask" is 1.1825 and "profit" is 50 then "1.1825+80*1.1825" but that equals 95
No, the Point will be .0001 not 1.1825 (1.1825 is the ask price).
So,
If "ask" is 1.1825 and "profit" is 50then:

1.1825 + (50 * .0001) = 1.1825 + 0.005 = 1.1875 (50 Pips)



Quote:
my expert has the below settings as default
extern double profit = 80;
extern double stop = 30;

but backtesting produced t/p stops of 45-46 and stoploss losses of 17
Still don't understand this point .
Did you use Optimization testing mode?
__________________
Hope it helps !
Coders' Guru
Senior MQL programmer:
www.xpworx.com/custom.htm
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 12-23-2005, 03:39 PM
trevman2005 trevman2005 is offline
Junior Member
 
Join Date: Dec 2005
Posts: 6
trevman2005 is on a distinguished road
maybe this will help,

Parameters profit=80; stop=30;

yet niether the t/p or s/l are the same as the specified
Attached Files
File Type: htm StrategyTester.htm (10.4 KB, 24 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 12-27-2005, 06:26 PM
trevman2005 trevman2005 is offline
Junior Member
 
Join Date: Dec 2005
Posts: 6
trevman2005 is on a distinguished road
does no one have any ideas why the results are as shown in the test run?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


Similar Threads
Thread Thread Starter Forum Replies Last Post
Order Execution Problems with my EA mrebersv Metatrader 4 6 04-01-2007 09:08 AM
Problems with EA's. rodrigojmz General Discussion 3 02-22-2007 01:15 AM
Help, anyone having problems with MT4? increase General Discussion 10 12-08-2006 01:06 PM
ea problems Eaglehawk Metatrader 4 3 06-13-2006 05:32 PM


All times are GMT. The time now is 03:27 AM.