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
  #2061 (permalink)  
Old 09-24-2009, 08:57 PM
Junior Member
 
Join Date: Sep 2009
Posts: 2
smsfm is on a distinguished road
Minimum bars before/after trade

Hi,

Hi, i'm new to MT4.. Could someone please let me know how i can place a restriction in an EA that requires a minimum of "x" bars to either open a new position or close a previous one?

(without using the sleep command)

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
  #2062 (permalink)  
Old 09-25-2009, 01:30 PM
Member
 
Join Date: Feb 2009
Posts: 49
happyfx is on a distinguished road
mql coding help

if (iMA(NULL, 0, 24, 0, MODE_LWMA, PRICE_WEIGHTED, 1) > iMA(NULL, 0, 120, 1, MODE_LWMA, PRICE_WEIGHTED, 1)) gi_268 = 2;

---------------------------------------------------------------

what does it mean ??

2 LWMA used ?

LWMA period =24 shift =0 on price weighted (hcll4) cross over LWMA period 120 shift =1 on price weighted (hcll4) then buy or sell ??
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
  #2063 (permalink)  
Old 09-26-2009, 01:29 PM
Junior Member
 
Join Date: Sep 2009
Location: Malta
Posts: 24
ljuba973 is on a distinguished road
Problem with closing position

Hi,

I just started with my new EA and opening positions is OK, I setup tp and sl. EA open and close 1 by 1 position and never there are more than 1 order. But I would like to close position if some of indicators alert me before sl or tp limit.

If I try something like this:

Code:
for (int i=1; i<=OrdersTotal(); i++) {    
      if (OrderSelect(i, SELECT_BY_POS, 2)) { 
         if (OrderSymbol()==Symbol()) { 
           Ans=OrderClose(OrderTicket(),alLots,Bid,2);// Order closing 
         } 
      } 
   }
Nothing happened. Doesn't find any opened positions and I know there is 1.

If I try something like this:

Code:
 for (int i=1; i<=OrdersTotal(); i++) {    
     CloseOrder(OrderValue(i,VAL_TICKET),OrderValue(i,VAL_LOTS),Bid,3); 
   }
Compiler report error message that VAL_TICKER and VAL_LOTS are not defined and in examples I found they are nowhere declared.

If I try direcly by number to close:

Code:
Ans=OrderClose(0,alLots,Bid,2);// Order closing
I get error message 4107 or 4105 that ticker is invalid

Can somebody check this and my ea in attachment and help please?

Thanks a lot
Attached Files
File Type: mq4 rsiproba.mq4 (5.7 KB, 4 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
  #2064 (permalink)  
Old 09-26-2009, 09:30 PM
Junior Member
 
Join Date: Jun 2009
Posts: 19
username1 is on a distinguished road
Question iHighest iLowest Clarification

Assume 3 bars: Bar [2], Bar [1] and Bar [0] (Current).

Is the following "stop_low()" function correct to find the lowest low of bar [2] and [3] ?

double stop_low = iLowest(Symbol(),0,1,2,1);

------------------------------------------------------------

Reference:

int iLowest( string symbol, int timeframe, int type, int count=WHOLE_ARRAY, int start=0)
Returns the shift of the least value over a specific number of periods depending on type.
Parameters:
symbol - Symbol the data of which should be used to calculate indicator. NULL means the current symbol.
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.
type - Series array identifier. It can be any of Series array identifier enumeration values.
count - Number of periods (in direction from the start bar to the back one) on which the calculation is carried out.
start - Shift showing the bar, relative to the current bar, that the data should be taken from.
Sample:

// calculating the lowest value on the 10 consequtive bars in the range
// from the 10th to the 19th index inclusive on the current chart
double val=Low[iLowest(NULL,0,MODE_LOW,10,10)];
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
  #2065 (permalink)  
Old 09-27-2009, 12:06 AM
Junior Member
 
Join Date: Jun 2009
Posts: 19
username1 is on a distinguished road
Question Reduce Open Position

Does anyone know how to close / reduce half a position. What function do we call ?

Example: Reduce an open position from 10 Lots to 5 Lots without opening another trade in the opposite direction ?
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
  #2066 (permalink)  
Old 09-27-2009, 12:27 AM
Senior Member
 
Join Date: Dec 2007
Posts: 492
Enforcer is on a distinguished road
Is called 'partial close';

PHP Code:
bool OrderCloseint ticketdouble lotsdouble priceint slippagecolor Color=CLR_NONE
Just specify how many lots to close.
__________________
www.signalcopy.com - Most advanced tools for copy Metatrader signals.
Free MT4 account statistics - advanced stats and graphs for MT4 accounts
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
  #2067 (permalink)  
Old 09-27-2009, 06:58 AM
Senior Member
 
Join Date: Oct 2008
Location: Vancouver, BC
Posts: 158
Roger09 is on a distinguished road
Quote:
Originally Posted by ljuba973 View Post
Hi,
Try this way
Code:
for (int i=OrdersTotal()-1;i>=0 i--) {    
      if (OrderSelect(i, SELECT_BY_POS)) { 
         if (OrderSymbol()==Symbol()&&OrderType()==0) { 
           Ans=OrderClose(OrderTicket(),alLots,Bid,2);// Order closing 
         } 
         if (OrderSymbol()==Symbol()&&OrderType()==1) { 
           Ans=OrderClose(OrderTicket(),alLots,Ask,2);// Order closing 
         } 
      
}
__________________
www.rogersignals.com - Share your strategy with all
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
  #2068 (permalink)  
Old 09-27-2009, 07:01 AM
Senior Member
 
Join Date: Oct 2008
Location: Vancouver, BC
Posts: 158
Roger09 is on a distinguished road
Quote:
Originally Posted by username1 View Post
Does anyone know how to close / reduce half a position. What function do we call ?

Example: Reduce an open position from 10 Lots to 5 Lots without opening another trade in the opposite direction ?
Just close order for 5 lots, like this:
OrderClose(OrderTicket(),5.0,.......
__________________
www.rogersignals.com - Share your strategy with all
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
  #2069 (permalink)  
Old 09-27-2009, 10:29 AM
Junior Member
 
Join Date: Sep 2009
Location: Malta
Posts: 24
ljuba973 is on a distinguished road
Hi Roger,

Thanks a lot for help. In meantime I managed to fix it to work:

Code:
   OrderSend(Symbol(),OP_BUY,alLots,Ask,3,0,0,EA_Tester,Magic);
     if(OrderSelect(OrdersTotal()-1, SELECT_BY_POS)==true) {
       alTicker = OrderTicket();
       Alert("Bought! ", alTicker);
     } else Print("OrderSelect failed error code is ",GetLastError());
Like that I found alTicker (after opening position) which I close later on.

But your code I will use to optimize my Closing function. Sorry for maybe "beginner's code", I am into mq4 just 2 days ... will improve - I promise

Thanks again

Quote:
Originally Posted by Roger09 View Post
Try this way
Code:
for (int i=OrdersTotal()-1;i>=0 i--) {    
      if (OrderSelect(i, SELECT_BY_POS)) { 
         if (OrderSymbol()==Symbol()&&OrderType()==0) { 
           Ans=OrderClose(OrderTicket(),alLots,Bid,2);// Order closing 
         } 
         if (OrderSymbol()==Symbol()&&OrderType()==1) { 
           Ans=OrderClose(OrderTicket(),alLots,Ask,2);// Order closing 
         } 
      
}
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
  #2070 (permalink)  
Old 09-27-2009, 09:13 PM
Junior Member
 
Join Date: Nov 2006
Posts: 2
fxbg is on a distinguished road
How I can place a fixed StopLoss ?

Hi,
Could someone please let me know how I can place a fixed StopLoss in ths code?
PHP Code:
//+------------------------------------------------------------------+
//|                                              Daydream by Cothool |
//|                                          Recommended: USD/JPY 1H |
//+------------------------------------------------------------------+
#define MAGIC_NUM  48213657
//+------------------------------------------------------------------+
extern double Lots       0.1;
extern int ChannelPeriod 25;
extern int Slippage      3;
extern int TakeProfit    15;
//+------------------------------------------------------------------+
double LastOrderTime 0;
double CurrentDirection 0;
double CurrentTakeProfitPrice 0;
//+------------------------------------------------------------------+
void OpenLong()
{
   if (
Time[0] == LastOrderTime)
      return;
   if (
CurrentDirection != 0)
      return;

   
OrderSend(Symbol(), OP_BUYLotsAskSlippage00,
             
"Daydream"MAGIC_NUM0Blue);
   
LastOrderTime Time[0];
   
CurrentDirection 1;
}
//+------------------------------------------------------------------+
void OpenShort()
{
   if (
Time[0] == LastOrderTime)
      return;
   if (
CurrentDirection != 0)
      return;

   
OrderSend(Symbol(), OP_SELLLotsBidSlippage00,
             
"Daydream"MAGIC_NUM0Red);
   
LastOrderTime Time[0];
   
CurrentDirection = -1;
}
//+------------------------------------------------------------------+
void CloseLong()
{
   
int i;

   if (
Time[0] == LastOrderTime)
      return;
   if (
CurrentDirection != 1)
      return;

   for (
0OrdersTotal(); i++)
   {
      if (
OrderSelect(iSELECT_BY_POS) && OrderSymbol() == Symbol() &&
          
OrderMagicNumber() == MAGIC_NUM && OrderType() == OP_BUY)
      {
         
OrderClose(OrderTicket(), OrderLots(), Bid3White);
         
LastOrderTime Time[0];
         
CurrentDirection 0;
      }
   }
}
//+------------------------------------------------------------------+
void CloseShort()
{
   
int i;

   if (
Time[0] == LastOrderTime)
      return;
   if (
CurrentDirection != -1)
      return;

   for (
0OrdersTotal(); i++)
   {
      if (
OrderSelect(iSELECT_BY_POS) && OrderSymbol() == Symbol() &&
          
OrderMagicNumber() == MAGIC_NUM && OrderType() == OP_SELL)
      {
         
OrderClose(OrderTicket(), OrderLots(), Ask3White);
         
LastOrderTime Time[0];
         
CurrentDirection 0;
      }
   }
}
//+------------------------------------------------------------------+
void start()
{
   
double HighestValue;
   
double LowestValue;

   
HighestValue High[Highest(NULL0MODE_HIGHChannelPeriod1)];
   
LowestValue Low[Lowest(NULL0MODE_LOWChannelPeriod1)];

   
// BUY
   
if (Close[0] < LowestValue)
   {
      
CloseShort();
      
OpenLong();
      
CurrentTakeProfitPrice Bid TakeProfit Point;
   }

   
// SELL
   
if (Close[0] > HighestValue)
   {
      
CloseLong();
      
OpenShort();
      
CurrentTakeProfitPrice Ask TakeProfit Point;
   }

   
// Trailing Profit Taking for Long Position
   
if (CurrentDirection == 1)
   {
      if (
CurrentTakeProfitPrice Bid TakeProfit Point)
         
CurrentTakeProfitPrice Bid TakeProfit Point;
      if (
Bid >= CurrentTakeProfitPrice)
         
CloseLong();
   }

   
// Trailing Profit Taking for Short Position
   
if (CurrentDirection == -1)
   {
      if (
CurrentTakeProfitPrice Ask TakeProfit Point)
         
CurrentTakeProfitPrice Ask TakeProfit Point;
      if (
Ask <= CurrentTakeProfitPrice)
         
CloseShort();
   }
}
//+------------------------------------------------------------------+ 
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
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 09:29 AM.



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