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 Thread Tools Display Modes
  #201 (permalink)  
Old 02-14-2007, 09:56 AM
Senior Member
 
Join Date: Mar 2006
Location: La Verne,CA
Posts: 552
MrPip is on a distinguished road
trailing ea

I posted this on the yahoo MTE&I group.
I combined 7 different trailing stop ideas into a single ea.

I have not tested this for manual trades but I have used many of the functions in eas and they do work.

It will only trail positions entered for the currency pair where attached.

It also sounds like what you want is the type 2, delayed trailing stop.

Also try the type 3 with 3 levels,

First level moves stop by the setting for that level, second level for that level and thirrd level trails from there.

For example

First move is 20 pips. To move to breakeven set the first stop to 20.

Second move 30, lock in 15 by setting second stop to 15.

Third move 40 trail by 10 by setting trailling to 10.

Robert
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #202 (permalink)  
Old 03-02-2007, 04:36 PM
Member
 
Join Date: Mar 2007
Posts: 39
jerrydeng is on a distinguished road
Post Help! i need simple code

Hello!everybody

I found almost all indicators very good, BUT indicator-- "arrow" in this forum is always above or below the bar. Many times, when i see the arrow, the best entry time has passed. It confuses me, what and when did the arrow appear?? So, i want to see the arrow display at the price positon when the arrow come out, better with the comment "XX:XX open price XXXX" on the chart left-up corner so that i may know what happened just now and deside the next step. i'm not a programmer, so i dont know how to write the code. Who here can help me finish it? thanks very much first.

Sorry for poor english..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #203 (permalink)  
Old 03-06-2007, 07:12 PM
Member
 
Join Date: Feb 2007
Posts: 30
justize is on a distinguished road
Open-Range-Breakout (Larry Williams)

Hi,

I cant go on with programming until i found that %$§!!€-error.

The EA analyse the last 3 days. After that, it has to send two stop-orders. Both got initial stops. Later There is a trailing-stop running, when break-even is reached.

Now my problem is, that it doesn t send the long order?! No idea why not...

Can someone help me?

Quote:
//+------------------------------------------------------------------+
//| Open-Range-Breakout.mq4 |
//| JustiZe |
//| |
//+------------------------------------------------------------------+
#property copyright "JustiZe"
#property link ""


extern string Set1 = "Trade-Zeitraum";
extern int MaxOrderTime_h= 24; // Zeit in Stunden-Bars
extern string Set2 = "Stopp-Parameter";
extern double Trailing_stop = 40;

datetime TradeTime;


//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
// Variablen für die letzten Hochs
double hoch1, hoch2, hoch3;
// Variablen für die letzten drei Tiefs
double tief1, tief2, tief3;
// Variablen für die Min/Max
double hoch, tief;
// Variable für Volatilität
double vola;
// Variablen für Kaufen/Verkaufen-Tag
int kauftag = 0;
int verkauftag = 0;
// Variablen für Stopp-Order-Preisbildung
double kauf_stopp_preis = 0;
double verkauf_stopp_preis = 0;
// Maß der durchschnittlichen Spanne
double spanne = 0;
// Variable für wahre Spanne
double wahre_spanne = 0;
// Variable für anfänglichen Stopp
double anfangs_stopp = 0;
// Variable zur Ermittlung der dreifachen Spanne
int go_bep_long = 0; //BEP in Long?
int go_bep_short = 0;//BEP in Short?
int bep_stopp = 0;
// Variable für nahen Stopp
double naher_stopp;

// Ordervariablen, Systemvariablen...
int ticket = 0;
int total = 0;
double lots = 0.1;
double take_profit = 100;
int magic_number1 = 1234;
int magic_number2 = 1235;
int cnt = 0;

//================================================== ==================
//Berechne das höchste Hoch und das tiefste Tief der letzten drei Tage
//und lege den Unterschied zwischen den beiden Punkten als Maß der
//Volatilität fest.
//================================================== ==================

// Variablen füllen
hoch1 = High[1];
hoch2 = High[2];
hoch3 = High[3];
tief1 = Low[1];
tief2 = Low[2];
tief3 = Low[3];
// Maximum / Minimum bestimmen
if(hoch1 >= hoch2 && hoch1 >= hoch3) hoch = hoch1;
if(hoch2 >= hoch1 && hoch2 >= hoch3) hoch = hoch2;
if(hoch3 >= hoch1 && hoch3 >= hoch2) hoch = hoch3;
if(tief1 <= tief2 && tief1 <= tief3) tief = tief1;
if(tief2 <= tief1 && tief2 <= tief3) tief = tief2;
if(tief3 <= tief1 && tief3 <= tief2) tief = tief3;
// Unterschied bestimmen
vola = hoch - tief;

//================================================== ===================
//Stelle fest, ob morgen ein Leichter kaufen- oder ein leichter Verkau-
//fen-Tag ist. Ist der heutige Schlusskurs gleich oder höher als der
//gestrige Schlusskurs, dann ist morgen ein leichter Verkaufen-Tag. Ist
//der heutige Schlusskurs tiefer als der gestrige, dann ist morgen ein
//leichter Kaufen-Tag
//---------------------------------------------------------------------
//Anmerkung:#
//Zeitreihe um eins verschoben!!!
//================================================== ===================
if(Close[1] >= Close[2]) verkauftag = 1;
if(Close[1] < Close[2]) kauftag = 1;

//================================================== ===================
//Ist heute ein leichter Kaufen-Tag, dann wird die Stopp-Order zum Kauf
//folgendermaßen berechnet: Teile das Maß der Volatilität durch zwei
//und addiere das Ergebnis zum Eröffnungskurs. Die Stopp-Order zum Ver-
//kauf an einem leichten Kaufen-Tag wird ermittelt, indem das Maß der
//Volatilität vom Eröffnungskurs abgezogen wird.
//================================================== ===================
if(verkauftag == 0 && kauftag == 1) // Kaufen-Tag?
{
kauf_stopp_preis = vola/2 + Open[0];
verkauf_stopp_preis = Open[0] - vola;
}

//================================================== ===================
//Ist heute ein leichter Verkaufen-Tag, dann wird die Stopp-Order zum
//Verkauf folgendermaßen berechnet: Teile das Maß der Volatilität durch
//zwei und ziehe das Ergebnis von Eröffnungskurs ab. Die Stopp-Order
//zum Kauf an einem leichten Verkaufen-Tag wird ermittelt, indem das
//Maß der Volatitilität zum Eröffnungskurs addiert wird.
//================================================== ===================
if(verkauftag == 1 && kauftag == 0) // Verkaufen-Tag?
{
verkauf_stopp_preis = Open[0] - vola/2;
kauf_stopp_preis = Open[0] + vola;
}
//================================================== ===================
//Anmerkung:
//Runden der Werte!
//================================================== ===================
verkauf_stopp_preis = MathRound(verkauf_stopp_preis);
kauf_stopp_preis = MathRound(kauf_stopp_preis);

//================================================== ===================
//Berechne die durchschnittliche wahre Spanne der letzten zehn Tage.
//================================================== ===================
wahre_spanne = iATR(NULL,0,10,0);

//================================================== ===================
//Setze die dreifache durchschnittliche Spanne als anfänglichen Stopp.
//================================================== ===================
anfangs_stopp = 3 * wahre_spanne;
//================================================== ===================
//Anmerkung:
//Runden des Wertes!
//================================================== ===================
anfangs_stopp = MathRound(anfangs_stopp);

//================================================== ===================
//Anmerkung:
//Wenn flat, dann Orders in den Markt stellen.
//Begrenzte Zeit für Order hinzugefügt
//================================================== ===================
// Überprüfung auf Signale und Handel
total = OrdersTotal(); //Anzahl momentaner Order
// Trade-Time-Management
TradeTime = iTime(NULL,PERIOD_D1,0);

// if-Block für Einstieg
if(total<2) //total=0 : flat
{
ticket = OrderSend(Symbol(),OP_BUYSTOP, lots,kauf_stopp_preis*Point, 3,kauf_stopp_preis*Point - anfangs_stopp*Point, 0,NULL,magic_number1,TradeTime+MaxOrderTime_h*60*6 0,Blue);
ticket = OrderSend(Symbol(),OP_SELLSTOP,lots,verkauf_stopp_ preis*Point,3,verkauf_stopp_preis*Point + anfangs_stopp*Point,0,NULL,magic_number2,TradeTime +MaxOrderTime_h*60*60,Red);
return(0);
}

//================================================== ===================
//Ist die Position um die dreifache durchschnittliche wahre Spanne in
//der Gewinnzone, ziehe den schützenden Stopp auf den Kostendeckungs-
//punkt nach.
//================================================== ===================
//Vergleiche den Trailing-Stop, den schützenden Stop und den Umkehrstop
//un wende immer den Stopp an, der momentan dem Kurs am nächsten liegt.
///================================================== ==================

for(cnt=0;cnt<total;cnt++)
{
wahre_spanne = iATR(NULL,0,10,0);

if(OrderSymbol()==Symbol() && OrderType() == OP_BUY)
{
if((Close[0]-OrderOpenPrice())>=3*wahre_spanne && OrderStopLoss() != OrderOpenPrice()) // Stopp muss auf BreakEvenPoint nachgezogen werden
{
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOp enPrice()+(Ask-Bid),OrderTakeProfit(),0,Green);
return(0);
}
}

if(OrderSymbol()==Symbol() && OrderType() == OP_SELL)
{
if((OrderOpenPrice()-Close[0])>=3*wahre_spanne && OrderStopLoss() == OrderOpenPrice()) // Stopp muss auf BreakEvenPoint nachgezogen werden
{
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOp enPrice()-(Ask-Bid),OrderTakeProfit(),0,Green);
return(0);
}
}


naher_stopp = 30;
//EDIT

}


return(0);
}
//+------------------------------------------------------------------+
Attached Files
File Type: mq4 Open-Range-Breakout.mq4 (8.2 KB, 70 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #204 (permalink)  
Old 03-10-2007, 01:53 PM
Senior Member
 
Join Date: Nov 2006
Posts: 230
teldon is on a distinguished road
code sought

how to write this code .....

i need to measure the height of a wave and make decision according to that.
For example ... I am looking at a 5 min chart. I see lots of up and down waves. I want to choose a wave which has a height of 40 pips or greater. How to write such a code?

Anyone?
thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #205 (permalink)  
Old 03-13-2007, 12:41 PM
SaxMan's Avatar
Member
 
Join Date: Mar 2006
Posts: 27
SaxMan is on a distinguished road
Question Programmer Help -- Code Logic help

Hi Programmers,

I'm programming my close order logic and I don't seem to have it right:

PHP Code:
bool LongClose()
   {
   if(
MAFastC<MASlowC && MAFastP>=MASlowP)
      {
       
CrossedUp=false;
       
CrossedDn=true;
       
BarCount=0;
      }
   else
   if(
MAFastC>MASlowC && MAFastP<=MASlowP)
      {
       
CrossedUp=true;
       
CrossedDn=false;
       
BarCount=0;
       
Alert("Crossed Down");
      }
   if(
CrossedDn==true && NewBar()==true && Candle3mP=="Bear"BarCount++;
      {
      if(
BarCount>=&& Candle3mC=="Bear")
         {
         
Alert("Close Long Position");
         return(
true);
         }
      else  return(
false);
      } 
CrossedUP/DN & BarCount are static variables.

My closing logic is: When Cross occurs it stimulates the Bar count which counts the bars since the cross. When that count reaches 2 (i.e. 2 bars after the cross) and if current bar is Bear it triggers a true return to the function.

Problem: Cross notifys ok but count doesn't occur and consequently never reaches "true" state.

Thanks for your help,
SaxMan
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #206 (permalink)  
Old 03-13-2007, 01:13 PM
Senior Member
 
Join Date: Jan 2006
Posts: 1,084
omelette is on a distinguished road
Hi. Try this.

PHP Code:
bool LongClose() 
   { 
   if(
MAFastC<MASlowC && MAFastP>=MASlowP
      { 
       
CrossedUp=false
       
CrossedDn=true
       
BarCount=0
      } 
   else 
   if(
MAFastC>MASlowC && MAFastP<=MASlowP
      { 
       
CrossedUp=true
       
CrossedDn=false
       
BarCount=0
       
Alert("Crossed Down"); 
      } 
   if(
CrossedDn==true && NewBar()==true && Candle3mP=="Bear")
    
BarCount++; 
   if(
BarCount>=&& Candle3mC=="Bear"
     { 
      
Alert("Close Long Position"); 
      return(
true); 
     } 
   else  return(
false); 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #207 (permalink)  
Old 03-13-2007, 01:53 PM
Kalenzo's Avatar
Senior Member
 
Join Date: Dec 2005
Location: Bydgoszcz - Poland
Posts: 693
Kalenzo is on a distinguished road
You can always write int crossTime = Time[0] when you had a cross, and then use iBarShift function using crossTime variable to check how many bars passed.
__________________
You need proffesional mql coder? Contact me! I will help you!
........................................
http://www.fxservice.eu/
........................................
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #208 (permalink)  
Old 03-13-2007, 03:09 PM
SaxMan's Avatar
Member
 
Join Date: Mar 2006
Posts: 27
SaxMan is on a distinguished road
Hi Kalenzo,

Quote:
Originally Posted by Kalenzo
You can always write int crossTime = Time[0] when you had a cross, and then use iBarShift function using crossTime variable to check how many bars passed.
How would you write this code to only include "Bear Bars" in the count?
I understand the ibarshift but this would include all bars since cross. You would still need to use a count system like I have it to count "Bear Bars" and I believe this is where my issue lies.

I originally tested my code with this code .... Which worked fine.... but didn't translate into the code above that would actually be listed in my EA
PHP Code:
int start()
  {
//----
 
double f=iMA(NULL,0,3,0,MODE_SMA,PRICE_CLOSE,0);
 
double s=iMA(NULL,0,7,0,MODE_SMA,PRICE_CLOSE,0);
 
double fp=iMA(NULL,0,3,0,MODE_SMA,PRICE_CLOSE,1);
 
double sp=iMA(NULL,0,7,0,MODE_SMA,PRICE_CLOSE,1);
 static 
bool CrossedUP,CrossedDn;
 static 
int Count=0;
 
if(
f>&& fp<=sp)
 {
 
CrossedUP=true;
 
CrossedDn=false;
 
Alert(Symbol()," Crossed UP");
 
Count=0;
 }
else
if(
f<&& fp>=sp)
 {
 
CrossedUP=false;
 
CrossedDn=true;
 
Alert(Symbol()," Crossed Down");
 
Count=0;
 }
if(
NewBar()==true && f>|| f<sCount++;
Comment("Crossed UP: ",CrossedUP,"    Crossed Down: ",CrossedDn,"   Bars since Cross: ",Count); 
//----
   
return(0);
  } 
Any other thoughts would be appreciated.
Thanks,
SaxMan
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #209 (permalink)  
Old 03-13-2007, 03:26 PM
SaxMan's Avatar
Member
 
Join Date: Mar 2006
Posts: 27
SaxMan is on a distinguished road
Sorry Omelette,

This doesn't work either

Thanks,
SaxMan

Quote:
Originally Posted by omelette
Hi. Try this.

PHP Code:
bool LongClose() 
   { 
   if(
MAFastC<MASlowC && MAFastP>=MASlowP
      { 
       
CrossedUp=false
       
CrossedDn=true
       
BarCount=0
      } 
   else 
   if(
MAFastC>MASlowC && MAFastP<=MASlowP
      { 
       
CrossedUp=true
       
CrossedDn=false
       
BarCount=0
       
Alert("Crossed Down"); 
      } 
   if(
CrossedDn==true && NewBar()==true && Candle3mP=="Bear")
    
BarCount++; 
   if(
BarCount>=&& Candle3mC=="Bear"
     { 
      
Alert("Close Long Position"); 
      return(
true); 
     } 
   else  return(
false); 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #210 (permalink)  
Old 03-18-2007, 05:02 PM
islandrock's Avatar
Member
 
Join Date: Jan 2007
Posts: 87
islandrock is on a distinguished road
Unhappy time limit with EA code

I cant seame to place a time limit on my EA
code line is as follows:
OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,0, Ask+TakeProfit*Point,"timetest",16384,0,Green)
I've tried changing that ZERO to a 1 or to a 12 and i can't get it to stop the trade ... i would like to have the trade expire in 12 hours how can i do this?
i'm useing a backtesting. to nake sure it works.. the expire function does work with that right?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

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 On
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 01:53 AM.



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