Coder sur metatrader - Forex Forum

2 Pages V   1 2 >  
Reply to this topicStart new topic
> Coder sur metatrader
lev10
post Sep 16 2005, 14:53
Post #1


Member
**

Group: Membre Actif
Posts: 59
Joined: 15-September 05
Member No.: 119



Salut,

Je m'intéresse au systèmes de trading depuis 2 ou 3 semaines.J'ai actuellement un petit problème avec une ébauche d'un système de suivi de tendance sans indics que je teste sur fxlite....Voilà le système est sensé être long ou short selon le trend défin pas deux barres succéssives.Il semble ne pas y avoir d'erreur de syntaxe mais il ne marche qu'à l'achat..... huh.gif
Peut être que j'ai mis un peu trop d'exit là où il ne faut.J'essaie actuellement de trouver le bug.
Je vous l'envoie pour un coup de main.....


/*[[
Name := UpTrend&DownTrend Break Out
Author := lev10
Link := mailto lev10 www.mataf.net
Lots := 1.00
Stop Loss := 0
Take Profit := 0
Trailing Stop := 0
]]*/


//Système de suivi de tendance qui sera long, short,
// ou Out selon que le trend soit haussier, baissier,
// ou sans tendance.
//Ce système est essentiellement basé sur les prix et,
//ne comporte donc aucun indicateur technique.

//Initialisations des Variables.

//Uptrend= successions de 2 hauts ascendants et 2 bas,
//ascendants.
//Downtrend=successions de 2 bas descendants et 2 hauts
//descendants.

Var:Uptrend(0);
Var:Downtrend(0);
Var:stopup(0);
Var:stopdown(0);

/*Définition des variables.*/

Uptrend=(High[1]>High[2]And Low[1]>Low[2]);
Downtrend=(Low[2]>Low[1]And High[2]>High[1]);
stopup=Low[2];
stopdown=High[2];

/*Check si marge suffisante */

If FreeMargin<100 then Exit;

/*On ne prend qu'une seule positions à la fois*/

If TotalTrades<1 then{

/*Entrée à l'achat si Uptrend et seulement
sur cassure haussière du plus haut précédent
High[1] avec un ordre OP_BUY*/

If Uptrend then
If Bid>High[1] then
SetOrder(OP_BUY,Lots,Ask,0,stopup,0,Green);Exit;


/*Entrée à la vente si Downtrend*/

If Downtrend then
If Ask<Low[1] then
SetOrder(OP_SELL,Lots,Bid,0,stopdown,0,Red);Exit;}

/* Gestion de la position.Le stop sera replacé à
High[2] pour Downtrend ou à Low[2] pour Uptrend
après chaque nouvelle barre*/

If TotalTrades=1 then {

If OrderValue(1,val_type)=OP_BUY then
If Downtrend then
CloseOrder(OrderValue(1,VAL_TICKET),lots,Bid,0,Yellow);Exit;

If OrderValue(1,VAL_TYPE)=OP_SELL then
If Uptrend then
CloseOrder(OrderValue(1,VAL_TICKET),lots,Ask,0,Blue);Exit;}
Go to the top of the page
 
+Quote Post
dieupip
post Sep 16 2005, 15:22
Post #2


Senior Member
***

Group: Membre+
Posts: 535
Joined: 14-September 05
Member No.: 74
Broker: FXLite
Demo/Real: Real
Leverage: 1:1



/*[[
Name := UpTrend&DownTrend Break Out
Author := lev10
Link := mailto lev10 www.mataf.net
Lots := 1.00
Stop Loss := 0
Take Profit := 0
Trailing Stop := 0
]]*/


//Système de suivi de tendance qui sera long, short,
// ou Out selon que le trend soit haussier, baissier,
// ou sans tendance.
//Ce système est essentiellement basé sur les prix et,
//ne comporte donc aucun indicateur technique.

//Initialisations des Variables.

//Uptrend= successions de 2 hauts ascendants et 2 bas,
//ascendants.
//Downtrend=successions de 2 bas descendants et 2 hauts
//descendants.

Var:Uptrend(0);
Var:Downtrend(0);
Var:stopup(0);
Var:stopdown(0);

/*Définition des variables.*/

Uptrend=(High[1]>High[2]And Low[1]>Low[2]);
Downtrend=(Low[2]>Low[1]And High[2]>High[1]);
stopup=Low[2];
stopdown=High[2];

/*Check si marge suffisante */

If FreeMargin<100 then Exit;

/*On ne prend qu'une seule positions à la fois*/

If TotalTrades<1 then{

/*Entrée à l'achat si Uptrend et seulement
sur cassure haussière du plus haut précédent
High[1] avec un ordre OP_BUY*/

If Uptrend then
If Bid>High[1] then
{
SetOrder(OP_BUY,Lots,Ask,0,stopup,0,Green);
Exit;
}


/*Entrée à la vente si Downtrend*/

If Downtrend then
If Ask<Low[1] then
{
SetOrder(OP_SELL,Lots,Bid,0,stopdown,0,Red);
Exit;
}

}

/* Gestion de la position.Le stop sera replacé à
High[2] pour Downtrend ou à Low[2] pour Uptrend
après chaque nouvelle barre*/

If TotalTrades=1 then {

If OrderValue(1,val_type)=OP_BUY then
If Downtrend then
{
CloseOrder(OrderValue(1,VAL_TICKET),lots,Bid,0,Yellow);
Exit;
}

If OrderValue(1,VAL_TYPE)=OP_SELL then
If Uptrend then
{
CloseOrder(OrderValue(1,VAL_TICKET),lots,Ask,0,Blue);
Exit;
}

}



il faut utiliser des {} quand tu as plus d'une instruction derrière
Go to the top of the page
 
+Quote Post
lev10
post Sep 17 2005, 10:08
Post #3


Member
**

Group: Membre Actif
Posts: 59
Joined: 15-September 05
Member No.: 119



Ok....merci,
Je viens de le copier!Je vais voir ce que ça donne
bon week-end!
Go to the top of the page
 
+Quote Post
lev10
post Sep 24 2005, 13:12
Post #4


Member
**

Group: Membre Actif
Posts: 59
Joined: 15-September 05
Member No.: 119



Encore un système foireux qui apparament correst: aucune erreur de syntaxe quand je le passe au vérificateur qui qui ne fonctionne pas.Il ne me réalise que 3 trades de 1996 à mainteant(je backtest sur fxlite en démo).....Pouvez-vous me dire ce qui cloche dans ce code !!!!!!!!Merci

/*[[
Name := 20 days breakouts
Author := lev10
Link := http://www.addictfx.biz/5-categorie-90719.html
Notes := Système de cassure des plus hauts/plus bas sur 20 jours.
Notes := Ce système est backtesté par addictfx sur son site dans la
Notes := rubrique backtests (cf lien) pour détails.
Lots := 0.10
Stop Loss := 0
Take Profit := 0
Trailing Stop := 0
]]*/


/* Description succinte du fonctionnement du système
tel que décrit sur le site www.addictfx.biz.

Time Frame:
Daily
Studies:
20 Days Highest Highs
20 Days Lowest Lows
Setup:
Open Long if Close price > 20 Days Highest Highs
Open Short if Close price < 20 Days Lowest Lows

Trigger:

Buy = next open after long setup
Short = next open after short setup
Stop:No Stop Loss
Exit:
Exit Long when open new Short and Exit Short when open new Long*/

//Initialisations des varibles

Var:buypoint(0);
Var:Sellpoint(0);

//Calcul des points d'entrée

buypoint=High[Highest(MODE_HIGH,21,20)];
sellpoint=Low[Lowest(MODE_LOW,21,20)];

// Condition de marge suffisante

If FreeMargin<100 then Exit;

//Exclusion de plus d'une position à la fois

If Totaltrades<1 then {

/*Achat si le prix de clôture est supérieur
au plus haut des 20 jours précédents*/

If Close[1]>buypoint then
{
SetOrder(OP_BUY,Lots,Open,0,0,0,Green);Exit;
};

If Close[1]<sellpoint then
{
SetOrder(OP_SELL,Lots,Open,0,0,0,Red);Exit;
};
};

If Totaltrades=1 then{

If OrderValue(1,VAL_TYPE)= OP_BUY then
{
If Close[1]<sellpoint then
{

CloseOrder(OrderValue(1,VAL_TICKET),Lots,OrderValue(1,VAL_OPENPRICE),0,Yellow);Exit;
};
};
If OrderValue(1,VAL_TYPE)=OP_SELL then
{
If Close[1]>buypoint then
{
CloseOrder(OrderValue(1,VAL_TICKET),Lots,OrderValue(1,VAL_OPENPRICE),0,Orange);Exit;
};
};
};
Go to the top of the page
 
+Quote Post
dieupip
post Sep 24 2005, 17:36
Post #5


Senior Member
***

Group: Membre+
Posts: 535
Joined: 14-September 05
Member No.: 74
Broker: FXLite
Demo/Real: Real
Leverage: 1:1



Je n'ai pas regardé le code précisément, généralement cela arrive quand on n'a plus assez de margin après des trades perdants.
FXLite peut développer des systèmes, ils ont une équipe pour çà.
Tu auras peut être plus de réponses sur moneytec.
Go to the top of the page
 
+Quote Post
dieupip
post Sep 24 2005, 17:37
Post #6


Senior Member
***

Group: Membre+
Posts: 535
Joined: 14-September 05
Member No.: 74
Broker: FXLite
Demo/Real: Real
Leverage: 1:1



et sur le groupe yahoo :
http://finance.groups.yahoo.com/group/Meta...and_Indicators/
Go to the top of the page
 
+Quote Post
lev10
post Oct 11 2005, 18:10
Post #7


Member
**

Group: Membre Actif
Posts: 59
Joined: 15-September 05
Member No.: 119



Salut,

Voici enfin le premier code non foireux tongue.gif biggrin.gif que je viens de terminer sur mt3.Je le teste en réel sur compte démo depuis 2 jours et j’ai donc vérifié que les trades qu’il réalise correspondent bien à ceux réalisés par le backtest MT3 qui eux sont impressionnants sur GBGUSD de 1996 à 2005.
Il s’agit donc d’un système de breakout(Take two Half Profits & Trailing Stop) des plus haut , plus bas de la veille tel que décrit par Addictfx sur son blog www.addictfx.biz
Je n’ai fais qu’écrire le code MT3 correspondant au système qu’il décrit dans la partie 5.Donc mieux vaut allez sur le lien pour comprendre le fonctionnement du système.A la différence du système de Addictfx où les ordres sont passés entre 8h et 22h ici les ordres sont passés à minuit.
J'ai joint le fichier mql pour ceux qui sont intéressés
@+

http://www.addictfx.biz/5-categorie-90719.html


*[[
Name := Take two Half Profits & Trailing Stop Breakout System
Author := lev10
Link := http://www.addictfx.biz/5-categorie-90719.html
Notes := Timeframe daily
Lots := 0.10
Stop Loss := 999
Take Profit := 999
Trailing Stop := 999
]]*/

var:cnt(0);
var:trs(0);

trs=60*Point;



If FreeMargin>100 And TimeToStrEx(CurTime,TIME_MINUTES)<"02:00"
And DayOfWeek<6 then
{
If H[0]<H[1] And L[0]>L[1] then
{
If Totaltrades=0 then
{
SetOrder(OP_BUYSTOP,lots,H[1],0,H[1]-30*Point,H[1]+60*Point,green);Exit;
};
If Totaltrades=1 then
{
SetOrder(OP_BUYSTOP,lots,H[1],0,H[1]-30*Point,H[1]+150*Point,GreenYellow);Exit;
};

If Totaltrades=2 then
{
SetOrder(OP_SELLSTOP,lots,L[1],0,L[1]+30*Point,L[1]-60*Point,red);Exit;
};

If TotalTrades=3 then
{
SetOrder(OP_SELLSTOP,lots,L[1],0,L[1]+30*Point,L[1]-150*Point,Orange);Exit;
};
};

If H[0]<H[1] And L[0]<L[1]then
{
If Totaltrades=0 then
{
SetOrder(OP_BUYSTOP,lots,H[1],0,H[1]-30*Point,H[1]+60*Point,Green);Exit;
};
If Totaltrades=1 then
{
SetOrder(OP_BUYSTOP,lots,H[1],0,H[1]-30*Point,H[1]+150*Point,GreenYellow);Exit;
};
};

If H[0]>H[1] And L[0]>L[1]then
{
If Totaltrades=0 then
{
SetOrder(OP_SELLSTOP,lots,L[1],0,L[1]+30*Point,L[1]-60*Point,Red);Exit;
};

If TotalTrades=1 then
{
SetOrder(OP_SELLSTOP,lots,L[1],0,L[1]+30*Point,L[1]-150*Point,Orange);Exit;
};
};
};

//Instructions OCO//

If Totaltrades>2 then
{
For cnt=1 to 2 Begin
If OrderValue(cnt,VAL_TYPE)=OP_BUY then
{
DeleteOrder(OrderValue(3,VAL_TICKET),red);Exit;
DeleteOrder(OrderValue(4,VAL_TICKET),Orange);Exit;
};
End;
For cnt=3 to 4 Begin
If OrderValue(cnt,VAL_TYPE)=OP_SELL then
{
DeleteOrder(OrderValue(1,VAL_TICKET),Green);Exit;
DeleteOrder(OrderValue(2,VAL_TICKET),GreenYellow);Exit;
};
End;
};

// TrailingStops//

If Totaltrades=2 then
{
For cnt=1 to 2 Begin
If OrderValue(cnt,VAL_TYPE)=OP_BUY then
{
If H[0]-OrderValue(cnt,VAL_OPENPRICE)>=trs then
{
If H[0]-trs>OrderValue(cnt,VAL_STOPLOSS) then
{
ModifyOrder(OrderValue(1,VAL_TICKET),OrderValue(1,VAL_OPENPRICE),H[0]-trs,H[1]+60*Point,Green);Exit;
ModifyOrder(OrderValue(2,VAL_TICKET),OrderValue(2,VAL_OPENPRICE),H[0]-trs,H[1]+150*Point,GreenYellow);Exit;
};
};
};
If OrderValue(cnt,VAL_TYPE)=OP_SELL then
{
If OrderValue(cnt,VAL_OPENPRICE)-L[0]>=trs then
{
If L[0]+trs<OrderValue(cnt,VAL_STOPLOSS)then
{
ModifyOrder(OrderValue(1,VAL_TICKET),OrderValue(1,VAL_OPENPRICE),L[0]+trs,L[1]-60*Point,Red);Exit;
ModifyOrder(OrderValue(2,VAL_TICKET),OrderValue(2,VAL_OPENPRICE),L[0]+trs,L[1]-150*Point,Orange);Exit;
};
};
};
End;
};

For cnt=1 to Totaltrades Begin
If OrderValue(cnt,VAL_TYPE)=OP_BUY then
{
If H[0]-OrderValue(cnt,VAL_OPENPRICE)>=trs then
{
If H[0]-trs>OrderValue(cnt,VAL_STOPLOSS) then
{
ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE),H[0]-trs,H[1]+150*Point,GreenYellow);Exit;
};
};
};
If OrderValue(cnt,VAL_TYPE)=OP_SELL then
{
If OrderValue(cnt,VAL_OPENPRICE)-L[0]>=trs then
{
If L[0]+trs<OrderValue(cnt,VAL_STOPLOSS)then
{
ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE),L[0]+trs,L[1]-150*Point,Orange);Exit;
};
};
};
End;

//Clôture des ordres non exécutés en fin de journée
//et des trades en cours.

If TimeToStrEx(CurTime,TIME_MINUTES)>=("22:45")then
Begin
//Ordres non exécutés.
If Totaltrades>0 then
{
For cnt=1 to 2 Begin
If OrderValue(cnt,VAL_TYPE)=OP_BUYSTOP then
{
DeleteOrder(OrderValue(1,VAL_TICKET),Green);Exit;
DeleteOrder(OrderValue(2,VAL_TICKET),GreenYellow);Exit;
};
If OrderValue(cnt,VAL_TYPE)=OP_SELLSTOP then
{
DeleteOrder(OrderValue(1,VAL_TICKET),Red);Exit;
DeleteOrder(OrderValue(2,VAL_TICKET),Orange);Exit;
};
End;
For cnt=3 to 4 Begin
If OrderValue(cnt,VAL_TYPE)=OP_SELLSTOP then
{
DeleteOrder(OrderValue(3,VAL_TICKET),Red);Exit;
DeleteOrder(OrderValue(3,VAL_TICKET),Orange);Exit;
};
End;
};

//Trades en cours .

If Totaltrades<=2 then
{
For cnt=1 to 2 Begin
If OrderValue(cnt,VAL_TYPE)=OP_BUY then
{
CloseOrder(OrderValue(1,VAL_TICKET),lots,Bid,0,Green);Exit;
CloseOrder(OrderValue(2,VAL_TICKET),lots,Bid,0,GreenYellow);Exit;
};
If OrderValue(cnt,VAL_TYPE)=OP_SELL then
{
CloseOrder(OrderValue(1,VAL_TICKET),lots,Ask,0,Red);Exit;
CloseOrder(OrderValue(2,VAL_TICKET),lots,Ask,0,Orange);Exit;
};
End;
};

For cnt=1 to TotalTrades Begin
If OrderValue(cnt,VAL_TYPE)=OP_BUY then
{
CloseOrder(OrderValue(1,VAL_TICKET),lots,Bid,0,GreenYellow);Exit;
};
If OrderValue(cnt,VAL_TYPE)=OP_SELL then
{
CloseOrder(OrderValue(1,VAL_TICKET),lots,Ask,0,Orange);Exit;
};
End;
End;
Attached File(s)
Attached File  Take_two_Half_Profits___Trailing_Stop_Breakout_System.zip ( 1.1K ) Number of downloads: 105
 
Go to the top of the page
 
+Quote Post
lev10
post Oct 12 2005, 7:43
Post #8


Member
**

Group: Membre Actif
Posts: 59
Joined: 15-September 05
Member No.: 119



Salut,

Contrairement à ce que j'avais dit hier sur 2jrs d'essais, les trades réels ne sont pas toujours conformes au résultat du backtest sur MT3.C'est ce matin que je m'en suis rendu compte.
Sur la journée d'hier par exemple le système a réalisé une perte de 30 pips*2 sur 2 minilots tandis que quand je regarde le backtest j'ai +60 pips sur le premier takeprofit et 67 pips sur le close de la seconde position en fin de journée.......soit 127 pips sur la journée d'hier en backtest.....contre - 60 pips en réel....ça me rend de + en + méfiant à l'égard des belles equity curves de certains systèmes sur mt3.
Mais j'accorde le bénéfice du doute au système et le laisse tourner encore une dizaine de jrs pour voir comment il se comporte.

bonne journée à tous
Go to the top of the page
 
+Quote Post
dieupip
post Oct 12 2005, 7:47
Post #9


Senior Member
***

Group: Membre+
Posts: 535
Joined: 14-September 05
Member No.: 74
Broker: FXLite
Demo/Real: Real
Leverage: 1:1



as tu backtesté avec "every 1 point" ?
Go to the top of the page
 
+Quote Post
lev10
post Oct 12 2005, 11:54
Post #10


Member
**

Group: Membre Actif
Posts: 59
Joined: 15-September 05
Member No.: 119



Oui every point!!!!!!!!!!!!!!!!
Go to the top of the page
 
+Quote Post

2 Pages V   1 2 >
Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No New Posts   0 danyja 1,427 25th September 2005 - 10:02
Last post by: danyja
No new   81 LeGlac 22,758 6th May 2007 - 17:23
Last post by: LeGlac
No new   21 pere noel 6,643 12th November 2005 - 21:08
Last post by: laurentol
No New Posts   9 mounafia 2,699 16th December 2005 - 19:54
Last post by: Dazzz
No New Posts   3 Alex 1,171 8th February 2006 - 18:28
Last post by: Alex

Lo-Fi Version Time is now: 2nd December 2008 - 18:16

Welcome Guest ( Log In | Register )

Chat

Forex Forum

English
Français

Economic calendar

[Full Economic calendar]