Forex
Google
New signals service!

Go Back   Forex Trading > Metatrader Training > Metatrader 4 mql 4 - Development course > Questions


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 (2) Thread Tools Display Modes
  #901 (permalink)  
Old 01-06-2008, 01:55 PM
Putz's Avatar
Junior Member
 
Join Date: Aug 2006
Posts: 24
Putz is on a distinguished road
Need more help

Hi all,

I am still trying to build my first basic EA. I finally have parts of it working but not all of it.

My idea is to buy/sell on retracements. So far, I am only working on the "Sell" portion of the EA. The "Buy" part will come later...hopefully.

The way that I want it to work is that I want to track the lowest point (CurrentLow) and when the price retraces by Ret1 (75 pips), to put a sell order in. If price comes back to CurrentLow, take profit and start the process over.

If price keeps going against me and it retraces by Ret2 (150 pips from CurrentLow), I want to put another sell order x 2 lots with take profit at the point of the first order plus one pip.

Stop Loss is placed at 225 pips from CurrentLow.

My EA is placing the order from the first level but not from the second level. I was able to get it to place orders from the second level but only at the same price as the first level.

Can someone please look at my code to see how I am screwing up.

Thanks,
Putz

Code:
//+------------------------------------------------------------------+
//|                                                  Bruno test1.mq4 |
//|                      Copyright © 2007, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, Putz Canada Corp"
#property link      "http://www.Putzfx,com"

extern string     Expert_Name    = "Albatross v1";
extern int        MagicNumber    = 757575;
extern int        Slippage       =     3.0;

//---- input parameters
extern double    TP1=75;
extern double    SL1=150;
extern double    Ret1=75;
extern double    TP2=76;
extern double    Ret2=150;
extern double    Lots=0.1;
double Entry1 = 0;
double Entry2 = 0;
double TPA = 0;
double TPB = 0;
double SL = 0;
double CurrentLow = 1000;


//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----  
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
//----
   return(0);
  }
  
//+------------------------------------------------------------------+
//| Check Open Position Controls                                     |
//+------------------------------------------------------------------+
  
int CheckOpenTrades()
{
 int cnt;
 int NumTrades;   // Number of buy and sell trades in this symbol
   
 NumTrades = 0;
 for(cnt=OrdersTotal()-1;cnt>=0;cnt--)
  {
   OrderSelect (cnt, SELECT_BY_POS, MODE_TRADES);
   if ( OrderSymbol() != Symbol()) continue;
   if ( OrderMagicNumber() != MagicNumber)  continue;
      
   if(OrderType() == OP_BUY )  NumTrades++;
   if(OrderType() == OP_SELL ) NumTrades++;             
  }
 return (NumTrades);
} 
  
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+

int start()
 {
  int cnt, ticket, total;

  if(Bars<100)
   {
    Print("bars less than 100");
    return(0);  
   }
   
  total = CheckOpenTrades();
  if(total==0) 
  {
   if(Bid < CurrentLow) CurrentLow = Bid; 
    {
     Entry1 = CurrentLow + Ret1*Point;
     Entry2 = CurrentLow + Ret2*Point;
     SL = Entry1 + SL1*Point;
     TPA = Entry1 - TP1*Point;
     TPB = Entry2 - TP2*Point;
     if(Bid >= Entry1)
      {
       OrderSend(Symbol(),OP_SELL,Lots,Entry1,3,SL,TPA,"Albatross_v1",MagicNumber,0,Green);
       if(Bid >= Entry2)
        {
         OrderSend(Symbol(),OP_SELL,Lots*2,Entry2,3,SL,TPB,"Albatross_v1",MagicNumber,0,Green); 
        } 
       CurrentLow=1000; 
      } 
    } 
  }  
 }
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #902 (permalink)  
Old 01-06-2008, 06:54 PM
Junior Member
 
Join Date: Sep 2007
Posts: 23
Sendra is on a distinguished road
which low?

I think you forgot about which low you use as currentlow. See, I can't imagine if you mean the low of current bar. If you mean what I think you mean, try to use iLowest[]. See it in dictionary of Metaeditor.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #903 (permalink)  
Old 01-06-2008, 06:57 PM
Junior Member
 
Join Date: Sep 2007
Posts: 23
Sendra is on a distinguished road
missed point

sorry, I didn't see you put currentlow = 1000;. But suggestion remains. See, currentlow = 1000; 1000 what? 1.0000 like in GBP/USD? 1000 point, from where? So, still the same, use iLowest[] for currentlow. I think it would work fine.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #904 (permalink)  
Old 01-06-2008, 08:33 PM
Putz's Avatar
Junior Member
 
Join Date: Aug 2006
Posts: 24
Putz is on a distinguished road
iLowest

Hi Sendra,

Thanks for your prompt reply.

What I am trying to achieve is not based on a high or low of any timeframe but the lowest point prior to a Ret1 (75 pip) retracement. I am focusing on the EUR/USD to start.

CurrentLow is supposed to track the lowest point before the retracement.

The following is an example of what I am trying to achieve.

a) Let's say we open the EA and the price is 1.4000 and it ranges between 1.4030 and 1.3970 before going to 1.4045. I would want CurrentLow to be 1.3970 (Lowest point) and to place the first sell order at 1.4045 (Entry1) with a SL of 1.4195 (SL1 =150 pips) and a Take Profit (TPA = 75 pips) of 1.3970.

b) if the price continues to go up to 1.4120 (Entry2), I would want a 2nd sell order placed with take profit (TPB =76 pips) of 1.4044 and SL of 1.4195 (same as on the first order).

My EA seems to work for the first order but it doesn't seem to get to the second order. I have been able to get it to place the second order but the price was the same as the first order and the SL was screwed up.

My long term goal is to have it decide whether it should be a buy or sell based on long term trend indicators and of course to have a buy set up like this sell set up as shown here. I have no idea whether it will be profitable but I am trying to learn and will surely make a million modifications before it is completed. I have come to the conclusion that to find out if any strategy works, it needs to be automated and take the human error out of the decision making. Obviously, fundamentals need to be looked at but that will come later...maybe.

Any help from Sendra or anyone else will be highly appreciated.

Thanks
Putz
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #905 (permalink)  
Old 01-06-2008, 08:37 PM
Putz's Avatar
Junior Member
 
Join Date: Aug 2006
Posts: 24
Putz is on a distinguished road
i Lowest and CurrentLow

Hi Sendra,

In order to answer your question about CurrentLow, I gave it a value of 1000 as that will always be bigger than any E/U price. This is to make sure that it takes the first EU price when it opens. If I would set it to 0, the price would never be lower and therefore no trades would ever take place.

I have never seen iLowest but I will check into it to see if it would work for me.

Thanks
Putz
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #906 (permalink)  
Old 01-08-2008, 10:26 PM
Member
 
Join Date: Jul 2006
Posts: 41
khari123 is on a distinguished road
Code - Trade Once a Day

Can someone help me with a script or ea that forces only 1 trade per day?

Thanks A Bunch
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #907 (permalink)  
Old 01-09-2008, 12:18 AM
Junior Member
 
Join Date: Sep 2007
Posts: 23
Sendra is on a distinguished road
Putz, what do you mean, "seems to work"? Either it is working or it is not. if it does work for the first order, then you should base your second order upon it (use OrderOpenPrice() as the basis of your second order instead of your currentlow like the first one).
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #908 (permalink)  
Old 01-09-2008, 12:25 AM
Junior Member
 
Join Date: Sep 2007
Posts: 23
Sendra is on a distinguished road
Quote:
Originally Posted by khari123 View Post
Can someone help me with a script or ea that forces only 1 trade per day?

Thanks A Bunch
Use daily chart, put:

#property ...

static bool ITradedOnThisBar;

//+---------------------------+
//| expert initialization function |
//+---------------------------+

then, on your opening and closing conditions add:
ITradedOnThisBar!=Bars

and after OrderSend():
ITradedOnThisBar=Bars;
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #909 (permalink)  
Old 01-11-2008, 04:08 PM
Senior Member
 
Join Date: Jan 2006
Posts: 125
metastock is on a distinguished road
HI!
How make a n EA based on stop&reverse of position???

Stop&reverse -> order_buy = order_closesell and orderseel=order_closebuy

Tnx for help!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #910 (permalink)  
Old 01-11-2008, 10:10 PM
Senior Member
 
Join Date: Oct 2005
Location: Porto/Portugal
Posts: 284
hellkas is on a distinguished road
Quote:
Originally Posted by metastock View Post
HI!
How make a n EA based on stop&reverse of position???

Stop&reverse -> order_buy = order_closesell and orderseel=order_closebuy

Tnx for help!
Try this script... experts\scripts
Attached Files
File Type: mq4 Close and Reverse.mq4 (2.2 KB, 16 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Tags
histogram, forex, ZUP_v1.mq4

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/questions/270-ask.html
Posted By For Type Date
OzFx System:) - Page 639 This thread Refback 06-21-2008 10:53 PM
Forex SRDC Sidus Sibkis EA MT4 Forum OTCSmart This thread Refback 12-08-2007 12:46 PM


All times are GMT. The time now is 06:27 AM.



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