Forex
Google
New signals service!

Go Back   Forex Trading > Programming > Metatrader Programming


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 (1) Thread Tools Display Modes
  #681 (permalink)  
Old 02-13-2008, 03:45 AM
Junior Member
 
Join Date: Jan 2008
Location: Canada
Posts: 9
timebandit is on a distinguished road
Help on Programming

Hi,
I've been doing my bes to try programming some things, but I've hit a brick wall. So I tried something real simple. If I uncomment "Print("Five");" and test the program it will only print "Yahooooooo". (Well it prints One" as well). Now with "Print("Five");" commented out, even the "Yahooooooo" doesn't print. What am I missing??
Attached Files
File Type: mq4 Trial.mq4 (1.5 KB, 6 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #682 (permalink)  
Old 02-13-2008, 06:23 AM
Member
 
Join Date: Nov 2006
Posts: 80
k3iroll is on a distinguished road
Close all pending and open order when 1 trade hit TP

Hi,

I'm trying to write a codes in my EA that will close all pending and open orders once there is 1 trade that hit TP. Below is the codes that I used, seems not working. Can somebody take a look and advise what is missing. Thanks.


if( PreviousOpenOrders > OpenOrders )
{
for( cnt = OrdersTotal()-1; cnt >= 0; cnt-- )
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
mode = OrderType();
if( OrderSymbol() == Symbol() &&
OrderMagicNumber()==Magic)

{
if( mode == OP_BUY ) OrderClose(OrderTicket(),OrderLots(),OrderClosePri ce(),slippage,Blue);
if( mode == OP_SELL ) OrderClose(OrderTicket(),OrderLots(),OrderClosePri ce(),slippage,Red);
if (mode == OP_SELLLIMIT) OrderDelete(OrderTicket());
if (mode == OP_BUYLIMIT) OrderDelete(OrderTicket());

}
}
}
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #683 (permalink)  
Old 02-13-2008, 06:46 AM
ralph.ronnquist's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 280
ralph.ronnquist is on a distinguished road
Use Bid and Ask respectively instead of OrderClosePrice()...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #684 (permalink)  
Old 02-13-2008, 07:44 AM
Member
 
Join Date: Nov 2006
Posts: 80
k3iroll is on a distinguished road
Quote:
Originally Posted by ralph.ronnquist View Post
Use Bid and Ask respectively instead of OrderClosePrice()...
Hello ralph,

can you help to give an example. Thanks for the help.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #685 (permalink)  
Old 02-13-2008, 07:48 AM
Senior Member
 
Join Date: Feb 2006
Posts: 525
Michel is on a distinguished road
Quote:
Originally Posted by timebandit View Post
Hi,
I've been doing my bes to try programming some things, but I've hit a brick wall. So I tried something real simple. If I uncomment "Print("Five");" and test the program it will only print "Yahooooooo". (Well it prints One" as well). Now with "Print("Five");" commented out, even the "Yahooooooo" doesn't print. What am I missing??
If you do not use brackets, only one line is executed. It depends of what you want to do, but you should do it like this:
PHP Code:
     if(d>5)
      {
         Print(
"Five");
         Print(
"Yahoooooooooooooooooooooooo");
      } 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #686 (permalink)  
Old 02-13-2008, 08:09 AM
ralph.ronnquist's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 280
ralph.ronnquist is on a distinguished road
PHP Code:
         if( mode ==  OP_BUY )  OrderClose(OrderTicket(),OrderLots(),Bid,slippage,Blue);
         if( 
mode ==  OP_SELL OrderClose(OrderTicket(),OrderLots(),Ask,slippage,Red); 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #687 (permalink)  
Old 02-13-2008, 10:38 AM
Member
 
Join Date: Nov 2006
Posts: 80
k3iroll is on a distinguished road
Need help

................

Last edited by k3iroll; 02-14-2008 at 09:34 AM. Reason: delete post
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #688 (permalink)  
Old 02-13-2008, 08:25 PM
Member
 
Join Date: Sep 2007
Posts: 68
Ronald Raygun is on a distinguished road
Move Stop Once

Here is my bit of code for moving the stoploss to breakeven after a certain profit. Is there anything wrong with it?

Code:
            //MoveOnce
            if(MoveStopOnce && MoveStopWhenPrice > 0) {
               if(Bid - OrderOpenPrice() == Point * MoveStopWhenPrice) {
                  OrderModify(OrderTicket(),OrderOpenPrice(), Bid - Point * MoveStopTo, OrderTakeProfit(), 0, Red);
                     if (!EachTickMode) BarCount = Bars;
                     continue;
                  }
               }
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #689 (permalink)  
Old 02-14-2008, 09:44 AM
Junior Member
 
Join Date: Apr 2007
Posts: 17
la totona is on a distinguished road
People that can help:

The code for the previous bar is below:

//to buy
double indicatorpast = icustom(....................,1);
double indicatornow = icustom(....................,0);


if (close[1]<indicatorpast && close[0]>indicatornow) OpenBUY();
if (close[1]>indicatorpast && close[0]<indicatornow) OpenSELL();

but with this satatement, the expert opens positions not only when the price cross the indicator, it opens position above the indicator too. I want that the expert open position ONLY when it cross the indicator, so i tried that:

//to buy
double indicatorpast = icustom(....................,1);
double indicatornow = icustom(....................,0);

if (close[1]<indicatorpast && close[0]==indicatornow) OpenBUY();
if (close[1]>indicatorpast && close[0]==indicatornow) OpenSELL();

But this statement it is not performing.

Do you know what is happen? Because i think there arent errors in the statement.

The question is why is not opening at the exact point of cross when close[0]==Indicatornow? If the function would be with ==, we will prevent the open of orders above the point of crooss between the indicator and the close of the present bar but is not funtioning with this type of relationship between the variables.

Do you have experimented the same problem? Abyone knows how resolve it?
Thanks, again.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #690 (permalink)  
Old 02-14-2008, 10:07 AM
Senior Member
 
Join Date: Jan 2006
Posts: 1,119
omelette is on a distinguished road
Quote:
Originally Posted by la totona View Post
People that can help:

The code for the previous bar is below:

//to buy
double indicatorpast = icustom(....................,1);
double indicatornow = icustom(....................,0);


if (close[1]<indicatorpast && close[0]>indicatornow) OpenBUY();
if (close[1]>indicatorpast && close[0]<indicatornow) OpenSELL();

but with this satatement, the expert opens positions not only when the price cross the indicator, it opens position above the indicator too. I want that the expert open position ONLY when it cross the indicator, so i tried that:

//to buy
double indicatorpast = icustom(....................,1);
double indicatornow = icustom(....................,0);

if (close[1]<indicatorpast && close[0]==indicatornow) OpenBUY();
if (close[1]>indicatorpast && close[0]==indicatornow) OpenSELL();

But this statement it is not performing.

Do you know what is happen? Because i think there arent errors in the statement.

The question is why is not opening at the exact point of cross when close[0]==Indicatornow? If the function would be with ==, we will prevent the open of orders above the point of crooss between the indicator and the close of the present bar but is not funtioning with this type of relationship between the variables.

Do you have experimented the same problem? Abyone knows how resolve it?
Thanks, again.
Because you are looking for an exact match between a returned 8 digit floating point value and price - they will almost never be equal with resolutions like that. Just check for a greater-than or less-than condition.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Tags
CHinGsMAroonCLK, I_XO_A_H

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

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

LinkBacks (?)
LinkBack to this Thread: http://www.forex-tsd.com/metatrader-programming/554-how-code.html
Posted By For Type Date
Need an experienced programmer? - Page 2 Post #0 Refback 09-24-2008 06:24 AM

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to code this? iscuba11 Metatrader 4 mql 4 - Development course 1 08-03-2007 04:22 PM


All times are GMT. The time now is 07:22 PM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.