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
  #1221 (permalink)  
Old 08-27-2008, 01:58 PM
Senior Member
 
Join Date: Apr 2006
Posts: 131
InTrance is on a distinguished road
Quote:
Originally Posted by ssvl View Post
thx for the information, will try it out

i'm just started learning mql
Don't try it, do it
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1222 (permalink)  
Old 08-27-2008, 02:44 PM
Junior Member
 
Join Date: Mar 2008
Posts: 4
ssvl is on a distinguished road
Quote:
Originally Posted by InTrance View Post
Don't try it, do it
i'm at work... and the metatrader port is blocked at here

Last edited by ssvl; 08-27-2008 at 03:03 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1223 (permalink)  
Old 08-27-2008, 09:02 PM
Member
 
Join Date: May 2008
Posts: 54
fireslayer26 is on a distinguished road
Hey, I'm still new to programming, and I am having trouble adding the following features to this simple EA:

1. Take Profit
2. Stop Loss
3. Trailing Stop
4. Number of pips to activate trailing stop

PHP Code:
//---- input parameters
extern double    Lots=0.1;
extern int       Slippage=5;

int MagicNum 98760;
bool longPosOpenedshortPosOpened;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   
return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   
return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
   
   
double crossup iCustom(NULL 0"18_28Cross"1,18,1,28,1,01);
   
double crossdown iCustom(NULL 0"18_28Cross"1,18,1,28,1,1,1);
   
   if (
crossup != EMPTY_VALUE)
   {
      if (!
PosOpened(OP_BUY))
      {
         
CloseAllOpenAndPendingTrades();
         
OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,Symbol(),MagicNum,0);
      }
   }
   else if(
crossdown != EMPTY_VALUE)
   {
      if (!
PosOpened(OP_SELL))
      {
         
CloseAllOpenAndPendingTrades();
         
OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,Symbol(),MagicNum,0);
      }
   }
   
   return(
0);
  }
//+------------------------------------------------------------------+
bool PosOpened(int orderType)
{
  
int total=OrdersTotal();
  for(
int cnt=0;cnt<total;cnt++)
  {
    
OrderSelect(cntSELECT_BY_POSMODE_TRADES);
    if(
OrderSymbol() == Symbol() && OrderType() == orderType)
    {
      return(
true);
    }
  }
  return(
false);
}

void CloseAllOpenAndPendingTrades()
{
  
int total OrdersTotal();
  for(
int i=total-1;i>=0;i--)
  {
    
OrderSelect(iSELECT_BY_POS);
    if(
Symbol() != OrderSymbol()) continue; // important! only close positions of current currency pair
    
    
int type   OrderType();
    
bool result false;
    
    switch(
type)
    {
      
//Close opened long positions
      
case OP_BUY       result OrderCloseOrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 200);
                          break;
      
      
//Close opened short positions
      
case OP_SELL      result OrderCloseOrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 200);
                          break;

      
//Close pending orders
      
case OP_BUYLIMIT  :
      case 
OP_BUYSTOP   :
      case 
OP_SELLLIMIT :
      case 
OP_SELLSTOP  result OrderDeleteOrderTicket() );
    }
  }
  
  return(
0);

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1224 (permalink)  
Old 08-28-2008, 09:49 AM
Junior Member
 
Join Date: Mar 2008
Posts: 4
ssvl is on a distinguished road
How to detect a jump from parabolic sar?

I'm currently using this code for detecting a jump:

if(iSAR(NULL,0,0.02,0.2,0)-iSAR(NULL,0,0.02,0.2,1)>1.0){ // if there is a jump up

But this doesn't seem to work right.

How can i detect if the psar is above or below my bars?

TIA
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1225 (permalink)  
Old 08-28-2008, 10:03 AM
IN10TION's Avatar
Senior Member
 
Join Date: Mar 2007
Posts: 569
Blog Entries: 1
IN10TION is on a distinguished road
:: use your proxy in metatrader...

IN10TION
Quote:
Originally Posted by ssvl View Post
i'm at work... and the metatrader port is blocked at here
__________________
..4.Nov.08.. IN10TION newsReader v09.85 Lite - the best news reader on your chart
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1226 (permalink)  
Old 08-28-2008, 10:05 AM
IN10TION's Avatar
Senior Member
 
Join Date: Mar 2007
Posts: 569
Blog Entries: 1
IN10TION is on a distinguished road
:: compare your sar result with a current close[0]

Quote:
Originally Posted by ssvl View Post
I'm currently using this code for detecting a jump:

if(iSAR(NULL,0,0.02,0.2,0)-iSAR(NULL,0,0.02,0.2,1)>1.0){ // if there is a jump up

But this doesn't seem to work right.

How can i detect if the psar is above or below my bars?

TIA
__________________
..4.Nov.08.. IN10TION newsReader v09.85 Lite - the best news reader on your chart
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1227 (permalink)  
Old 08-28-2008, 12:03 PM
matrixebiz's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 1,174
matrixebiz is on a distinguished road
Hey IN10TION, do you know of a good way to check if a trade just closed so that the EA won't place another trade (re-entry) until next signal comes? My EA checks trade condition upto lets say 10 bars but if a Sell trade condition was already met in the first few bars and closed I want the EA to stop checking upto the 10 bar Offset and wait until the next actual signal?
Thansk

Last edited by matrixebiz; 08-28-2008 at 12:08 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1228 (permalink)  
Old 08-28-2008, 05:13 PM
Senior Member
 
Join Date: Nov 2006
Posts: 215
luxinterior is on a distinguished road
Use the OrderHistory() function.

Lux
__________________
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!
Reply With Quote
  #1229 (permalink)  
Old 08-28-2008, 07:08 PM
matrixebiz's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 1,174
matrixebiz is on a distinguished road
Quote:
Originally Posted by luxinterior View Post
Use the OrderHistory() function.

Lux
Thanks but not sure how that works. I don't really want to know if an order was just closed but rather if an order was just Opened and Closed within so many bars. Then only place another trade on next main signal entry. I'm still trying to eliminate quick trade re-entries when an order was just opened and closed but trade conditions are still met. I want it to somehow only do One trade per main signal, so even though trade conditions are still valid don't trade again if already traded on that signal (including offset).

Let me see if I can explain with an example. It might be something that can't be helped.

EG: Let's say I'm using QQE and VQI as a signal trade entry point (QQE cross and VQI changes from buy to Sell or visa-versa)
Now I'm adding a SignalOffset option of lets say 6 bars because the QQE cross and VQI signal might not happen exactly on the same bar.

Now lets say there is a valid trade within 2 bars of each other when QQE and VQI agree, so now a trade is placed but I have a TP of 10 pips and the bar moves 15 pips my TP is hit and the trade is closed. Trade conditions are still met because of my 6 bar Offset now another trade is placed (re-entry) bad if that one or two bars moves 100 pips and my TP is 10, I've just had 10 trades, bad I only want One trade per Signal (Offset included)

Does that make sense? i would still want it to trade within the 6 bars though if and opposite signal happens and the other trade was closed still.

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1230 (permalink)  
Old 08-28-2008, 08:08 PM
IN10TION's Avatar
Senior Member
 
Join Date: Mar 2007
Posts: 569
Blog Entries: 1
IN10TION is on a distinguished road
:: make a [switch] variable, if there is already 1 sell order made it stops doing other sells (switch value is -1) & will only readjust when there is a buy signal & buy order made (switch value is 1)... something extra (surplus) you can think about is a timer reset, in case if there is a big trend up or down, you can have 2 or 3 sells with a kind of interval in between same orders (timing).


IN10TION

Quote:
Originally Posted by matrixebiz View Post
Thanks but not sure how that works. I don't really want to know if an order was just closed but rather if an order was just Opened and Closed within so many bars. Then only place another trade on next main signal entry. I'm still trying to eliminate quick trade re-entries when an order was just opened and closed but trade conditions are still met. I want it to somehow only do One trade per main signal, so even though trade conditions are still valid don't trade again if already traded on that signal (including offset).

Let me see if I can explain with an example. It might be something that can't be helped.

EG: Let's say I'm using QQE and VQI as a signal trade entry point (QQE cross and VQI changes from buy to Sell or visa-versa)
Now I'm adding a SignalOffset option of lets say 6 bars because the QQE cross and VQI signal might not happen exactly on the same bar.

Now lets say there is a valid trade within 2 bars of each other when QQE and VQI agree, so now a trade is placed but I have a TP of 10 pips and the bar moves 15 pips my TP is hit and the trade is closed. Trade conditions are still met because of my 6 bar Offset now another trade is placed (re-entry) bad if that one or two bars moves 100 pips and my TP is 10, I've just had 10 trades, bad I only want One trade per Signal (Offset included)

Does that make sense? i would still want it to trade within the 6 bars though if and opposite signal happens and the other trade was closed still.

Thanks
__________________
..4.Nov.08.. IN10TION newsReader v09.85 Lite - the best news reader on your chart
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Tags
candle time, CHinGsMAroonCLK, coders guru, expert advisor, forex, how to code, I_XO_A_H, mechanical trading, trading

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 07: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 05:22 PM


All times are GMT. The time now is 09:42 AM.



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