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
  #1251 (permalink)  
Old 08-30-2008, 01:23 PM
matrixebiz's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 1,174
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 03:01 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1252 (permalink)  
Old 08-30-2008, 01:55 PM
Member
 
Join Date: Dec 2005
Posts: 62
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!
Reply With Quote
  #1253 (permalink)  
Old 08-31-2008, 04:19 AM
Junior Member
 
Join Date: Apr 2007
Posts: 13
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!
Reply With Quote
  #1254 (permalink)  
Old 08-31-2008, 11: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, 132 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1255 (permalink)  
Old 09-02-2008, 06: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!
Reply With Quote
  #1256 (permalink)  
Old 09-02-2008, 01:45 PM
Junior Member
 
Join Date: Jan 2008
Posts: 14
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 01:55 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1257 (permalink)  
Old 09-03-2008, 01:07 AM
Member
 
Join Date: May 2008
Posts: 54
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!
Reply With Quote
  #1258 (permalink)  
Old 09-03-2008, 06:39 AM
Junior Member
 
Join Date: Feb 2008
Posts: 9
litcons is on a distinguished road
Need favor from a coder..ryanklefas??

I have no idea how to write code, I just need a couple more imputs and an extra indicator added to the united ea (attached)

Added imputs:

more entry options:

1. Enter on fresh signal: true or false, if true a trade would only happen at a fresh signal not in the middle or at the end
2. option to pick what indicator I want entry on
3. Lock in Pip amount
4. option of trailing stop to begin at x number of pips in profit

One more indicator added to for confirmation as well as entry and exit options:

HMA indicator ( attached)

Thanks in advance for coding help,

Mike
Attached Files
File Type: ex4 HMA.ex4 (4.1 KB, 0 views)
File Type: mq4 United_EA_v1.1.mq4 (19.1 KB, 6 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1259 (permalink)  
Old 09-03-2008, 02:53 PM
Senior Member
 
Join Date: Jan 2006
Posts: 1,119
omelette is on a distinguished road
@dan7567 - what you ask is not possible, MT uses the current brokers time and this cannot be changed. If you have the souce-code, it is much easier to just alter the time trades are opened, rather then contemplating the impossible...

@fireslayer26 - adding sl/tp code is easy - either include SL price (assuming a BUY - 'OrderOpenPrice() - SL_Pips * Point') in the OrderSend() function or modify an already open order with OrderModify() function. Ditto for TP's. The trailing stop is slightly more complicated but there are literally hundreds of EA's freely available that implement these functions...

@forexarchitect - what you are asking makes no sense - first, the code you provide is a partial custom function, that is passing pre-defined system variables (OP_BUY, OP_SELL, the values you are interested in it appears...) to another custom function which you do not include...

@litcons - not meaning to sound fasicious but the thread title is "how to code", whereas you matter-of-factly tells us you cannot code at all and are looking for someone to code an EA for you, practically from scratch - maybe the "coders for hire" thread would prove more receptive...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1260 (permalink)  
Old 09-03-2008, 06:36 PM
Junior Member
 
Join Date: Feb 2008
Posts: 9
litcons is on a distinguished road
sorry about posting at the wrong thread, I should have uploaded the indicators for review, it would have made more sense,
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:14 AM.



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