Go Back   Forex-TSD > Programming > MetaTrader Programming
Forex Forum Register More recent 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
  #1251 (permalink)  
Old 08-29-2008, 03:02 PM
Junior Member
 
Join Date: Aug 2008
Posts: 3
mellda is on a distinguished road
What value returns the function iTime? Is it start date of a bar? There is written only "Returns Time value for the bar of indicated symbol with timeframe and shift." in the manual.

Thanks for reply in advance.
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
  #1252 (permalink)  
Old 08-29-2008, 03:26 PM
IN10TION's Avatar
Senior Member
 
Join Date: Mar 2007
Posts: 701
Blog Entries: 1
IN10TION is on a distinguished road
:: yes, start of the bar
Quote:
Originally Posted by mellda View Post
What value returns the function iTime? Is it start date of a bar? There is written only "Returns Time value for the bar of indicated symbol with timeframe and shift." in the manual.

Thanks for reply in advance.
__________________
QUICK FIX!! 2 March 2010 IN10TION newsReader v09.99a Lite - the best forex news reader on your chart
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
  #1253 (permalink)  
Old 08-29-2008, 07:12 PM
Member
 
Join Date: May 2008
Posts: 60
fireslayer26 is on a distinguished road
Help a beginner?

Been trying to add the following parameters to this EA, but am having problems getting it to work. Can someone help code it, or atleast show me how to code it. Any help would be appreciated.

Take Profit
Stop Loss
Trailing Stop
Max Concurrent trades

Thanks!

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);


Last edited by fireslayer26; 09-02-2008 at 11:58 PM.
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
  #1254 (permalink)  
Old 08-30-2008, 12:23 PM
matrixebiz's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 1,225
matrixebiz is on a distinguished road
Need EA to close ALL orders once profit is hit

Hello, just wondering if one of you great coders can just add in the code to close ALL orders once g_MinProfit and f_MinProfit is hit. What I find is when profit is hit there are left over Buy/Sell Stop/Limit order stragglers and would just like them ALL deleted once profit min is triggered.

Thank you

Code:
extern bool    g_CLOSE_ALL=false;
extern bool    g_RESTART=true;

extern int     g_Step=120;
extern double  g_FirstLot=0.1;
extern double  g_IncLot=0;
extern double  g_MinProfit=450;
extern int     g_Magic = 2008;
extern string  g_comment="Win";

extern bool    f_CLOSE_ALL=false;
extern bool    f_RESTART=true;

extern int     f_Step=120;
extern double  f_FirstLot=0.1;
extern double  f_IncLot=0;
extern double  f_MinProfit=450;
extern int     f_Magic = 2009;
extern string  f_comment="REV";


int    GOrder_Buy=0;
int    GOrder_Sell=0;
double GLotSell=0;
double GLotBuy=0;
double gLotSell=0;
double gLotBuy=0;
double gLSP,gLBP;
double gCurrentProfit;

int    FOrder_Buy=0;
int    FOrder_Sell=0;
double FLotSell=0;
double FLotBuy=0;
double fLotSell=0;
double fLotBuy=0;
double fLSP,fLBP;
double fCurrentProfit;

double max_dd;



//--------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------

int init()
{
  Comment("Waddah Attar Win TradeBalancer 1");
  if(!GlobalVariableCheck("max_DD")) GlobalVariableSet("max_DD",0);
  return(0);
}

int deinit()
{
  Comment("");
  return(0);
}

//--------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------

int start()
{
  gCurrentProfit=GetOrdersProfit(g_Magic);

  if (gCurrentProfit>=g_MinProfit || g_CLOSE_ALL)
  {
    DeletePendingOrders(g_Magic);
    CloseOrders(g_Magic);
  }

  if (MyOrdersTotal(g_Magic)==0 && g_RESTART)
  {
    OrderSend(Symbol(),OP_BUYLIMIT,g_FirstLot,Ask-g_Step*Point,3,0,0,g_comment,g_Magic,0,Blue);
    OrderSend(Symbol(),OP_SELLLIMIT,g_FirstLot,Bid+g_Step*Point,3,0,0,g_comment,g_Magic,0,Red);
  }

  gLSP=GetLastSellPrice(g_Magic);
  gLBP=GetLastBuyPrice(g_Magic);
  
  if((gLSP-Bid)<=5*Point)
  {
    OrderSend(Symbol(),OP_SELLLIMIT,gLotSell+g_IncLot,gLSP+g_Step*Point,3,0,0,g_comment,g_Magic,0,Red);
  }

  if((Ask-gLBP)<=5*Point)
  {
    OrderSend(Symbol(),OP_BUYLIMIT,gLotBuy+g_IncLot,gLBP-g_Step*Point,3,0,0,g_comment,g_Magic,0,Blue);
  }

//--------------------------------------------------------------------------------------------

  fCurrentProfit=GetOrdersProfit(f_Magic);

  if (fCurrentProfit>=f_MinProfit || f_CLOSE_ALL)
  {
    DeletePendingOrders(f_Magic);
    CloseOrders(f_Magic);
  }

  if (MyOrdersTotal(f_Magic)==0 && f_RESTART)
  {
    OrderSend(Symbol(),OP_BUYSTOP,f_FirstLot,Ask+f_Step*Point,3,0,0,f_comment,f_Magic,0,Blue);
    OrderSend(Symbol(),OP_SELLSTOP,f_FirstLot,Bid-f_Step*Point,3,0,0,f_comment,f_Magic,0,Red);
  }

  fLSP=GetLastSellPrice(f_Magic);
  fLBP=GetLastBuyPrice(f_Magic);
  
  if((Bid-fLSP)<=5*Point)
  {
    OrderSend(Symbol(),OP_SELLSTOP,fLotSell+f_IncLot,fLSP-f_Step*Point,3,0,0,f_comment,f_Magic,0,Red);
  }

  if((fLBP-Ask)<=5*Point)
  {
    OrderSend(Symbol(),OP_BUYSTOP,fLotBuy+f_IncLot,fLBP+f_Step*Point,3,0,0,f_comment,f_Magic,0,Blue);
  }

//--------------------------------------------------------------------------------------------

//max_dd=

//--------------------------------------------------------------------------------------------

  Comment("Waddah Attar Win TradeBalancer 1",
          "\n\n\n\n", "   CurrentProfit = ", DoubleToStr(gCurrentProfit,2),
              "\n\n", "   Buy Lots = ", DoubleToStr(GLotBuy,2) + " / " + GOrder_Buy,
              "\n\n", "   Sell Lots = ", DoubleToStr(GLotSell,2) + " / " + GOrder_Sell,
          "\n\n\n\n", "   CurrentProfit = ", DoubleToStr(fCurrentProfit,2),
              "\n\n", "   Buy Lots = ", DoubleToStr(FLotBuy,2) + " / " + FOrder_Buy,
              "\n\n", "   Sell Lots = ", DoubleToStr(FLotSell,2) + " / " + FOrder_Sell);

  return(0);
}

//--------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------

int DeletePendingOrders(int Magic)
{
  int total  = OrdersTotal();
  
  for (int cnt = total-1 ; cnt >= 0 ; cnt--)
  {
    OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
    if (OrderMagicNumber() == Magic && OrderSymbol()==Symbol() && (OrderType()!=OP_BUY && OrderType()!=OP_SELL))
    {
      OrderDelete(OrderTicket());
    }
  }
  return(0);
}

//--------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------

int CloseOrders(int Magic)
{
  int total  = OrdersTotal();
  
  for (int cnt = total-1 ; cnt >= 0 ; cnt--)
  {
    OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
    if (OrderMagicNumber() == Magic && OrderSymbol()==Symbol())
    {
      if (OrderType()==OP_BUY)
      {
        OrderClose(OrderTicket(),OrderLots(),Bid,3,Blue);
      }
      
      if (OrderType()==OP_SELL)
      {
        OrderClose(OrderTicket(),OrderLots(),Ask,3,Red);
      }
    }
  }
  return(0);
}

//--------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------

int MyOrdersTotal(int Magic)
{
  int c=0;
  int total = OrdersTotal();
  
  if(Magic==g_Magic) { GLotBuy=0; GLotSell=0;  GOrder_Buy=0; GOrder_Sell=0; }
  if(Magic==f_Magic) { FLotBuy=0; FLotSell=0;  FOrder_Buy=0; FOrder_Sell=0; }
  
  for (int cnt = 0 ; cnt < total ; cnt++)
  {
    OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
    if (OrderMagicNumber() == Magic && OrderSymbol()==Symbol())
    {
      if(Magic==g_Magic) 
      {
        if(OrderType()==OP_BUY)  { GLotBuy=GLotBuy+OrderLots(); GOrder_Buy++; }
        if(OrderType()==OP_SELL) { GLotSell=GLotSell+OrderLots(); GOrder_Sell++; }
      }  
      if(Magic==f_Magic) 
      {
        if(OrderType()==OP_BUY)  { FLotBuy=FLotBuy+OrderLots(); FOrder_Buy++; }
        if(OrderType()==OP_SELL) { FLotSell=FLotSell+OrderLots(); FOrder_Sell++; }
      }  
      c++;
    }
  }
  return(c);
}

//--------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------

double GetLastBuyPrice(int Magic)
{
  int total=OrdersTotal()-1;

  for (int cnt = total ; cnt >=0 ; cnt--)
  {
    OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
    if (OrderMagicNumber() == Magic && OrderSymbol()==Symbol() && (OrderType()==OP_BUYSTOP || OrderType()==OP_BUYLIMIT || OrderType()==OP_BUY))
    {
      if(Magic==g_Magic) gLotBuy=OrderLots();
      if(Magic==f_Magic) fLotBuy=OrderLots();
      return(OrderOpenPrice());
    }
  }
  return(0);
}

//--------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------

double GetLastSellPrice(int Magic)
{
  int total=OrdersTotal()-1;

  for (int cnt = total ; cnt >=0 ; cnt--)
  {
    OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
    if (OrderMagicNumber() == Magic && OrderSymbol()==Symbol() && (OrderType()==OP_SELLSTOP || OrderType()==OP_SELLLIMIT || OrderType()==OP_SELL))
    {
      if(Magic==g_Magic) gLotSell=OrderLots();
      if(Magic==f_Magic) fLotSell=OrderLots();
      return(OrderOpenPrice());
    }
  }
  return(100000);
}

//--------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------

double GetOrdersProfit(int Magic)
{
  double eProfit=0;
  int total=OrdersTotal()-1;

  for (int cnt = total ; cnt >=0 ; cnt--)
  {
    OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
    if (OrderMagicNumber() == Magic && OrderSymbol()==Symbol() && (OrderType()==OP_BUY || OrderType()==OP_SELL))
    {
      eProfit=eProfit+OrderProfit();
    }
  }
  return(eProfit);
}

//--------------------------------------------------------------------------------------------

Last edited by matrixebiz; 08-30-2008 at 02:01 PM.
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
  #1255 (permalink)  
Old 08-30-2008, 12:55 PM
Member
 
Join Date: Dec 2005
Posts: 71
LazyForex is on a distinguished road
Quote:
Originally Posted by IN10TION View Post
:: did use some more keys for this one... but u can use it for other currencies also, was only set for EURUSD... don't know why, you will know better I hope
Hi IN10TION,

Sent you a PM...
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
  #1256 (permalink)  
Old 08-31-2008, 03:19 AM
Junior Member
 
Join Date: Apr 2007
Posts: 23
reza1982 is on a distinguished road
Quote:
Originally Posted by IN10TION View Post
:: did use some more keys for this one... but u can use it for other currencies also, was only set for EURUSD... don't know why, you will know better I hope
Hi
This Ea need forex_Nn_Ind_juna.ex4 indicator, i need this indicator have you it?
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
  #1257 (permalink)  
Old 08-31-2008, 10:49 PM
Junior Member
 
Join Date: Feb 2008
Posts: 12
cjcornelius is on a distinguished road
I please need Price(Close) crossing EMA Indicator with Alert

I am in need of an indicator with alert

It should be in seperate indicator window and have sound alert

I need it in histogram that changes colour

barlength=EMA(externalparameter)-close
if barlengthnow<barlengthprevious then bar is red
if barlengthnow>barlengthprevious then bar is green
if barlengthnow=barlengthprevious then bar is yellow

see example of bars below in pic

must offer sound alert if external parameter is set when bar change from red to green or fromgreen to red and also when bar is crossing zero line

Can anyone please help?

Thanks
PipSqweez
Attached Images
File Type: gif ScreenHunter_01 Aug. 31 22.31.gif (4.6 KB, 175 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
  #1258 (permalink)  
Old 09-02-2008, 05:57 AM
Junior Member
 
Join Date: Aug 2007
Posts: 8
dan5767 is on a distinguished road
Change Open Bar Time

Hello,
My current EA generates buys/sells based off the daily time frame of an indicator. This causes trades to be opened at 00:00 when the correct conditions are met. How can I change the starting time of the daily time frame? For example, right now the daily bar opens at 00:00 and closes at 24:00. I need to make the bar opens at a different time, say 02:00, not 00:00.

Any help would be greatly appreciated! My main goal is to spread out my trades throughout the day so im not always buying/selling at the same time. This would allow for more trades : )
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
  #1259 (permalink)  
Old 09-02-2008, 12:45 PM
Junior Member
 
Join Date: Jan 2008
Posts: 17
forexarchitect is on a distinguished road
hello guys
I have a question here... how do I change the following;

extern double MaxLot = 1.50;

double max_lot = GetMaxLot(OP_BUY, OP_SELL);
if (max_lot >= MaxLot) lot = CalcHedgeLot(order_type);
(order_type)]: ", lot);


if (lot == -1) return (lot);

lot = NormalizeDouble(lot, LotPrec);
if (lot > MaxLot) lot = MaxLot;
if (lot < MinLot) lot = MinLot;

return (lot);
}
double max_lot = GetMaxLot(OP_BUY, OP_SELL);
if (max_lot >= MaxLot) lot = CalcHedgeLot(order_type);

the above check for OP_BUY AND OP_SELL

question: how do I change it to any OP_BUY OR any OP_SELL

appreciate
__________________
creativity + common sense + a bit of humor = lots of pipp

Last edited by forexarchitect; 09-02-2008 at 12:55 PM.
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
  #1260 (permalink)  
Old 09-03-2008, 12:07 AM
Member
 
Join Date: May 2008
Posts: 60
fireslayer26 is on a distinguished road
*bump* for my previous post on page 125. I just saw that I didnt put the parameters I wanted on there. They are there now, so if anyone can help I'd appreciate it!!
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, crossover, dll, eli hayun, Eur_harvester.ex4, expert adviser, expert advisor, forex, Gann Hilo, higher high, how to code, indicator, I_XO_A_H, kehedge, mechanical trading, metatrader command line, mql4, mt4, MT4-LevelStop-Reverse, OrderReliable.mqh, programming, rectangle tool, strings, time range high low, 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 04:22 PM


All times are GMT. The time now is 11:25 AM.



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