Forex



Go Back   Forex Trading > Programming > MetaTrader
Forex Forum Register More recent Blogs Calendar Advertising Others Help






Register
Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.

From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.

Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
  • Elite Section
    Get access to private discussions, specialized support, indicators and trading systems reported every week.
  • Advanced Elite Section
    For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
See more

Reply
 
Thread Tools Display Modes
  #1401 (permalink)  
Old 10-27-2008, 03:47 AM
wolfe's Avatar
Senior Member
 
Join Date: Jan 2006
Posts: 818
wolfe is on a distinguished road
Quote:
Originally Posted by forexarchitect View Post
Hello guys
I have my EA coded with RefreshRates as per following, but I still have requote and my EA stop sending new CloseOrder after 1 or 2 try. How to I write a code that will ask my EA to keep sending CloseOrder until it accepted by the broker server? Thanks

for (int i=0; i < RepeatN; i++)
{
RefreshRates();
bool res = CloseOrder(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID));
if (res) break;
}
Use a while loop.

Ex:

PHP Code:
int CA()//Close All
{
while(
OrdersTotal()>0)
{
OrderSelect(0,SELECT_BY_POS);
if(
OrderType()==OP_BUYOrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),999,Red);
if(
OrderType()==OP_SELLOrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),999,Orange);
if(
OrderType()==OP_BUYSTOP||OrderType()==OP_SELLSTOP||OrderType()==OP_BUYLIMIT||OrderType()==OP_SELLLIMITOrderDelete(OrderTicket());
}
return(
0);

This will Close ALL orders when you call the function.

Place this code after the return(0) at the bottom of your EA, or in an include file. Then all you have to do is type:

PHP Code:
CA(); 
Type this anywhere in your EA you want ALL orders to close.

Hope this helps.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1402 (permalink)  
Old 10-27-2008, 08:03 AM
Member
 
Join Date: Oct 2006
Posts: 80
Big Be is on a distinguished road
To Wolfe

That's Nice!

Big Be
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1403 (permalink)  
Old 10-27-2008, 09:47 AM
Junior Member
 
Join Date: Jan 2008
Posts: 17
forexarchitect is on a distinguished road
Thanks Wolfe, appreciate.. I will try this
__________________
creativity + common sense + a bit of humor = lots of pipp
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1404 (permalink)  
Old 10-27-2008, 10:15 AM
Senior Member
 
Join Date: Nov 2006
Posts: 308
luxinterior is on a distinguished road
A much easier way is to use the include file OrderReliable.

Put it in your experts/include folder then add the following to the top of your EA...

Code:
#include <OrderReliable.mqh>
Lux
Attached Files
File Type: mqh OrderReliable.mqh (25.7 KB, 28 views)
__________________
Build An Expert Advisor. FREE E-course As Seen On TV
ForexArea.com
Users of Gap Trader from 'Forex-Assistant' MUST Read This
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1405 (permalink)  
Old 10-27-2008, 12:51 PM
Beno's Avatar
Senior Member
 
Join Date: Aug 2006
Location: London
Posts: 516
Beno is on a distinguished road
How do you stop an EA from opening new trades if your terminal is restarted and you have already made your days profit.

Cheers


Beno
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1406 (permalink)  
Old 10-28-2008, 12:43 AM
Junior Member
 
Join Date: Aug 2008
Posts: 1
buzzer is on a distinguished road
Restarting the EA after order closes for profit

Can anyone help me with this problem? I am using the attached EA and want it to open up one sequence after another if it closes for a profit during a certain time frame. It currently only runs one sequence then quits trading until you restart it. I've tried setting the extern stoptradingaftersequence to false with no avail. I've also tried using "while" and "if,else" functions without success. Keep in mind I'm a noob so any actual "where and what" to put in the code would be very appreciated.
Attached Files
File Type: zip sequencer_v1_2.zip (31.7 KB, 26 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1407 (permalink)  
Old 10-29-2008, 02:19 PM
Senior Member
 
Join Date: Apr 2006
Posts: 158
InTrance is on a distinguished road
Quote:
Originally Posted by buzzer View Post
Can anyone help me with this problem? I am using the attached EA and want it to open up one sequence after another if it closes for a profit during a certain time frame. It currently only runs one sequence then quits trading until you restart it. I've tried setting the extern stoptradingaftersequence to false with no avail. I've also tried using "while" and "if,else" functions without success. Keep in mind I'm a noob so any actual "where and what" to put in the code would be very appreciated.
I'll give you some hints:

First you need to calculate the profit since the start of the sequence. You can use a boolean variable like StartSequence=true; . Then when profit is above a certain level or when you want it to stop a sequence and start another set StartSequence=false. You will also need an initialization loop when StartSequence=false, it should do some calculations you want and then start the sequence all over.

Hope it points you to the right direction.
__________________
Need a Professional Programmer? PM me
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1408 (permalink)  
Old 10-29-2008, 09:47 PM
Junior Member
 
Join Date: Jan 2008
Posts: 7
rami1 is on a distinguished road
new system

hello;

first, thanks for you all and especially the programers for your constant help on this forum !

second, i would like you please to take a look at my strategy, it is really simple and i don't think it will take too much lines of coding :

first we buy and sell 1lot of the same currency at the same time, with a profit target of 20pips for both positions, and a stop loss of 20 pips for both positions too, so if the buy lot hit tp the sell positin will be closed and vice versa.

after the buy position tp is hit and sell positioin hit sl, the system should open 3 lots for buy and 2 lots for sell at the same time, with also profit target of 20pips for all positions, and a stop loss of 20 pips for all positions too. if the 3lots of buy hit tp and 2lot sell hit sl then the system should open another set of 3lots buy and 2lots sell same conditins as previouse set, so we are now going with the trend.

but if the sl of the 3lots buy where hit then all positins should be closed and we start again by 1lot buy+1lot sell, then according to which positin hit tp first it open our 3lots with the trend, and 2lots against the trend...and so on.

thanks on advance for your help and i hope i made it clear for you...

regards...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1409 (permalink)  
Old 10-30-2008, 07:17 AM
Member
 
Join Date: Jul 2008
Posts: 48
chiwing is on a distinguished road
very short program@can't find out where the mistaKe

i write a program, but can't find out what was wrong~ ~
it say:
'SELECT_BY_POS' - variable expected C:\Program Files\Straighthold Trader\experts\scripts\ point tick value defination.mq4 (17, 21)

could anyone tell me what the mistake is?
although u may say that the program don't need to quote "orderselect", but it should be OK even if i add it, what the mistake is?


//+------------------------------------------------------------------+
//| point tick value defination.mq4 |
//| Copyright ?2008, MetaQuotes Software Corp. |
//| Forex Trading Software: Forex Trading Platform MetaTrader 4 |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2008, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"

//+------------------------------------------------------------------+
//| script program start function |
//+------------------------------------------------------------------+

int start()
{ OrderSelect(int i,SELECT_BY_POS, MODE_TRADES);
Print("TEST");
Print("Point = " + Point);
Print ("TICKSIZE = " + MarketInfo(Symbol(),MODE_TICKSIZE));
Print ("TICKVALUE = " +MarketInfo(Symbol(),MODE_TICKVALUE));
Print("SPREAD = " + MarketInfo(Symbol(),MODE_SPREAD));
Print("STOPLEVEL = " + MarketInfo(Symbol(),MODE_STOPLEVEL));
Print ("LOTSIZE = " + MarketInfo(Symbol(),MODE_LOTSIZE));

return(0);
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1410 (permalink)  
Old 10-30-2008, 08:53 AM
Senior Member
 
Join Date: Feb 2006
Posts: 587
Michel is on a distinguished road
Quote:
Originally Posted by chiwing View Post
i write a program, but can't find out what was wrong~ ~
it say:
'SELECT_BY_POS' - variable expected C:\Program Files\Straighthold Trader\experts\scripts\ point tick value defination.mq4 (17, 21)

could anyone tell me what the mistake is?
although u may say that the program don't need to quote "orderselect", but it should be OK even if i add it, what the mistake is?


//+------------------------------------------------------------------+
//| point tick value defination.mq4 |
//| Copyright ?2008, MetaQuotes Software Corp. |
//| Forex Trading Software: Forex Trading Platform MetaTrader 4 |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2008, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"

//+------------------------------------------------------------------+
//| script program start function |
//+------------------------------------------------------------------+

int start()
{ OrderSelect(int i,SELECT_BY_POS, MODE_TRADES);
Print("TEST");
Print("Point = " + Point);
Print ("TICKSIZE = " + MarketInfo(Symbol(),MODE_TICKSIZE));
Print ("TICKVALUE = " +MarketInfo(Symbol(),MODE_TICKVALUE));
Print("SPREAD = " + MarketInfo(Symbol(),MODE_SPREAD));
Print("STOPLEVEL = " + MarketInfo(Symbol(),MODE_STOPLEVEL));
Print ("LOTSIZE = " + MarketInfo(Symbol(),MODE_LOTSIZE));

return(0);
}
I think you should not define the variable i inside the OrderSelect() function; also this has no meaning...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
Reply

Bookmarks

Tags
#include, candle time, CHinGsMAroonCLK, code, coders guru, conditionally, dll, eli hayun, Eur_harvester.ex4, expert adviser, expert advisor, forex, higher high, how to code, indicator, I_XO_A_H, kehedge, mechanical trading, metatrader command line, mt4, MT4-LevelStop-Reverse, OrderReliable.mqh, programming, rectangle tool, trading, volty channel stop


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

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


All times are GMT. The time now is 12:12 PM.



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