Comment coder ? - page 186

 

Ok, pour en revenir à la question initiale :

#property indicator_chart_window

#property indicator_buffers 1

#property indicator_color1 Magenta

extern int MAPeriod=200;

extern double iController = 1.386;

//---- buffers

//double Memory[200];

double ExtMapBuffer1[];

int limit = 200;

//---- variables

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

IndicatorBuffers(1);

//---- drawing settings

SetIndexBuffer(0,ExtMapBuffer1);

SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);

IndicatorShortName( "Antaria_Rising");

//---- initialization done

return(0);

}

int start()

{

int limit;

//ExtMapBuffer1[1] = ExtMapBuffer1[0];

//ExtMapBuffer1[0] = iController;

for(int i=(0); i<=(limit-1); i++)

{

ExtMapBuffer1 = ExtMapBuffer1;

}

ExtMapBuffer1[0] = iController;

return(0);

}[/CODE]

Above is the code for the indicator. Simply, it draws a line that should be updatable via the EA using the intiially mentioned code:

[CODE]temp = iCustom(NULL, 0, "AntariaRising", 200, 1.2, 0, 0); //temp not used. Function returns a double

Je suppose que je veux remplacer le dernier morceau de code qui me permet effectivement de mettre à jour dans l'objet incicateur la variable sur laquelle il est suivi, afin que je puisse l'utiliser plus tard comme une ligne d'arrêt. Le reste du code n'est cependant pas pertinent. Lorsque j'exécute la fonction ci-dessus, je m'attends à ce qu'antaria déplace sa position de 1,39 ou de la variable de départ à 1,2. Je ne me souviens pas si j'utilise la variable 200. Je pense que j'ai supprimé mes commentaires d'en-tête et de pied de page, mais l'indicateur d'esclave entier est là, c'est-à-dire AntariaRising mentionné dans le code ci-dessus.

c'était la seule fonction que j'ai pu trouver qui parlait aux objets indicateurs, et je l'utilise pour lire les valeurs dans d'autres zones.

 

A propos de votre code indicateur. C'est faux.

La limite des variables est toujours égale à zéro.

Enlevez la chaîne :

int limit ;

de la start().

 

Aidez-moi avec ce code pls

je veux que quelqu'un m'aide avec ce code il ouvre le trade quand je le veux mais le ferme automatiquement donc je veux qu'il trade avec le stop loss ne fermant pas quand il ne croise pas encore ceci est le code

//+------------------------------------------------------------------+

//| JR300.mq4 |

//| onelove |

//| Forex Forum | Forex Tsd | Metatrader Forum |

//+------------------------------------------------------------------+

#property copyright "oneLove"

#property link "https://www.forex-tsd.com"

//---- paramètres d'entrée

extern double TakeProfit=250.0 ;

extern double Lots=0.1 ;

extern double TrailingStop=35.0 ;

//+------------------------------------------------------------------+

//| fonction d'initialisation de l'expert

//+------------------------------------------------------------------+

int init()

{

//----

//----

return(0) ;

}

//+------------------------------------------------------------------+

//| fonction de désinitialisation experte |

//+------------------------------------------------------------------+

int deinit()

{

//----

//----

return(0) ;

}

int Crossed (double ligne1 , double ligne2)

{

static int last_direction = 0 ;

static int current_direction = 0 ;

if(line1>line2)current_direction = 1 ; //haut

if(line1<line2)current_direction = 2 ; //down

if(current_direction != last_direction) //changé

{

last_direction = current_direction ;

return (last_direction) ;

}

else

{

return (0) ;

}

}

//+------------------------------------------------------------------+

//| fonction de démarrage expert |

//+------------------------------------------------------------------+

int start()

{

//----

int cnt, ticket, total ;

double shortEma, longEma ;

if(Bars<100)

{

Print("barres inférieures à 100") ;

return(0) ;

}

if(TakeProfit<10)

{

Print("TakeProfit inférieur à 10") ;

return(0) ; // vérifier TakeProfit

}

shortEma = iMA(NULL,0,1,0,MODE_EMA,PRICE_CLOSE,0) ;

longEma = iMA(NULL,0,200,0,MODE_SMA,PRICE_CLOSE,0) ;

int isCrossed = Crossed (shortEma,longEma) ;

total = OrdersTotal() ;

si(total < 1)

{

si(isCrossed == 1)

{

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,

"My EA",12345,0,Green) ;

si(ticket>0)

{

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))

Print("Ordre BUY ouvert : ",OrderOpenPrice()) ;

}

else Print("Erreur lors de l'ouverture de l'ordre BUY : ",GetLastError()) ;

return(0) ;

}

if(isCrossed == 2)

{

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,

Bid-TakeProfit*Point, "My EA",12345,0,Red) ;

si(ticket>0)

{

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))

Print("Ordre VENTE ouvert : ",OrderOpenPrice()) ;

}

else Print("Erreur lors de l'ouverture de l'ordre VENTE : ",GetLastError()) ;

return(0) ;

}

return(0) ;

}

for(cnt=0;cnt<total;cnt++)

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES) ;

if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())

{

si(OrderType()==OP_BUY) // une position longue est ouverte

{

// doit-elle être fermée ?

if(isCrossed == 2)

{

OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet) ;

// fermer la position

return(0) ; // sortie

}

// vérification du stop suiveur

si(TrailingStop>0)

{

if(Bid-OrderOpenPrice()>Point*TrailingStop)

{

si(OrderStopLoss()<Bid-Point*TrailingStop)

{

OrderModify(OrderTicket(),OrderOpenPrice(),Bid-

Point*TrailingStop,OrderTakeProfit(),0,Green) ;

retour(0) ;

}

}

}

}

else // passe en position courte

{

// faut-il la fermer ?

if(isCrossed == 1)

{

OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet) ;

// fermer la position

return(0) ; // sortie

}

// vérification du trailing stop

si(TrailingStop>0)

{

if((OrderOpenPrice()-Ask)>(Point*TrailingStop))

{

si((OrderStopLoss()>(Ask+Point*TrailingStop)) ||

(OrderStopLoss()==0))

{

OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,

OrderTakeProfit(),0,Red) ;

retour(0) ;

}

}

}

}

}

}

return(0) ;

}

//+------------------------------------------------------------------+

 

Essayez ça :

//+------------------------------------------------------------------+

//| JR300.mq4 |

//| onelove |

//| Forex Forum | Forex Tsd | Metatrader Forum |

//+------------------------------------------------------------------+

#property copyright "oneLove"

#property link "https://www.forex-tsd.com"

//---- input parameters

extern double TakeProfit=250.0;

extern double StopLoss=100.0;

extern double Lots=0.1;

extern double TrailingStop=35.0;

//+------------------------------------------------------------------+

//| expert initialization function |

//+------------------------------------------------------------------+

int init()

{

//----

//----

return(0);

}

//+------------------------------------------------------------------+

//| expert deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

//----

//----

return(0);

}

int Crossed (double line1 , double line2)

{

static int last_direction = 0;

static int current_direction = 0;

if(line1>line2)current_direction = 1; //up

if(line1<line2)current_direction = 2; //down

if(current_direction != last_direction) //changed

{

last_direction = current_direction;

return (last_direction);

}

else

{

return (0);

}

}

//+------------------------------------------------------------------+

//| expert start function |

//+------------------------------------------------------------------+

int start()

{

//----

int cnt, ticket, total;

double shortEma, longEma;

if(Bars<100)

{

Print("bars less than 100");

return(0);

}

if(TakeProfit<10)

{

Print("TakeProfit less than 10");

return(0); // check TakeProfit

}

shortEma = iMA(NULL,0,1,0,MODE_EMA,PRICE_CLOSE,0);

longEma = iMA(NULL,0,200,0,MODE_SMA,PRICE_CLOSE,0);

int isCrossed = Crossed (shortEma,longEma);

total = OrdersTotal();

if(total < 1)

{

if(isCrossed == 1)

{

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+ TakeProfit*Point,

"My EA",12345,0,Green);

if(ticket>0)

{

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES ))

Print("BUY order opened : ",OrderOpenPrice());

}

else Print("Error opening BUY order : ",GetLastError());

return(0);

}

if(isCrossed == 2)

{

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,

Bid-TakeProfit*Point,"My EA",12345,0,Red);

if(ticket>0)

{

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES ))

Print("SELL order opened : ",OrderOpenPrice());

}

else Print("Error opening SELL order : ",GetLastError());

return(0);

}

return(0);

}

for(cnt=0;cnt<total;cnt++)

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())

{

if(OrderType()==OP_BUY) // long position is opened

{

// should it be closed?

//if(isCrossed == 2)

//{

//OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet) ;

// close position

//return(0); // exit

//}

// check for trailing stop

if(TrailingStop>0)

{

if(Bid-OrderOpenPrice()>Point*TrailingStop)

{

if(OrderStopLoss()<Bid-Point*TrailingStop)

{

OrderModify(OrderTicket(),OrderOpenPrice(),Bid-

Point*TrailingStop,OrderTakeProfit(),0,Green);

return(0);

}

}

}

}

else // go to short position

{

// should it be closed?

//if(isCrossed == 1)

//{

//OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet) ;

// close position

//return(0); // exit

//}

// check for trailing stop

if(TrailingStop>0)

{

if((OrderOpenPrice()-Ask)>(Point*TrailingStop))

{

if((OrderStopLoss()>(Ask+Point*TrailingStop)) ||

(OrderStopLoss()==0))

{

OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,

OrderTakeProfit(),0,Red);

return(0);

}

}

}

}

}

}

return(0);

}

//+------------------------------------------------------------------+
 

Merci

Roger09:
Essayez ceci :
//+------------------------------------------------------------------+

//| JR300.mq4 |

//| onelove |

//| Forex Forum | Forex Tsd | Metatrader Forum |

//+------------------------------------------------------------------+

#property copyright "oneLove"

#property link "https://www.forex-tsd.com"

//---- input parameters

extern double TakeProfit=250.0;

extern double StopLoss=100.0;

extern double Lots=0.1;

extern double TrailingStop=35.0;

//+------------------------------------------------------------------+

//| expert initialization function |

//+------------------------------------------------------------------+

int init()

{

//----

//----

return(0);

}

//+------------------------------------------------------------------+

//| expert deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

//----

//----

return(0);

}

int Crossed (double line1 , double line2)

{

static int last_direction = 0;

static int current_direction = 0;

if(line1>line2)current_direction = 1; //up

if(line1<line2)current_direction = 2; //down

if(current_direction != last_direction) //changed

{

last_direction = current_direction;

return (last_direction);

}

else

{

return (0);

}

}

//+------------------------------------------------------------------+

//| expert start function |

//+------------------------------------------------------------------+

int start()

{

//----

int cnt, ticket, total;

double shortEma, longEma;

if(Bars<100)

{

Print("bars less than 100");

return(0);

}

if(TakeProfit<10)

{

Print("TakeProfit less than 10");

return(0); // check TakeProfit

}

shortEma = iMA(NULL,0,1,0,MODE_EMA,PRICE_CLOSE,0);

longEma = iMA(NULL,0,200,0,MODE_SMA,PRICE_CLOSE,0);

int isCrossed = Crossed (shortEma,longEma);

total = OrdersTotal();

if(total < 1)

{

if(isCrossed == 1)

{

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+ TakeProfit*Point,

"My EA",12345,0,Green);

if(ticket>0)

{

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES ))

Print("BUY order opened : ",OrderOpenPrice());

}

else Print("Error opening BUY order : ",GetLastError());

return(0);

}

if(isCrossed == 2)

{

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,

Bid-TakeProfit*Point,"My EA",12345,0,Red);

if(ticket>0)

{

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES ))

Print("SELL order opened : ",OrderOpenPrice());

}

else Print("Error opening SELL order : ",GetLastError());

return(0);

}

return(0);

}

for(cnt=0;cnt<total;cnt++)

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())

{

if(OrderType()==OP_BUY) // long position is opened

{

// should it be closed?

//if(isCrossed == 2)

//{

//OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet) ;

// close position

//return(0); // exit

//}

// check for trailing stop

if(TrailingStop>0)

{

if(Bid-OrderOpenPrice()>Point*TrailingStop)

{

if(OrderStopLoss()<Bid-Point*TrailingStop)

{

OrderModify(OrderTicket(),OrderOpenPrice(),Bid-

Point*TrailingStop,OrderTakeProfit(),0,Green);

return(0);

}

}

}

}

else // go to short position

{

// should it be closed?

//if(isCrossed == 1)

//{

//OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet) ;

// close position

//return(0); // exit

//}

// check for trailing stop

if(TrailingStop>0)

{

if((OrderOpenPrice()-Ask)>(Point*TrailingStop))

{

if((OrderStopLoss()>(Ask+Point*TrailingStop)) ||

(OrderStopLoss()==0))

{

OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,

OrderTakeProfit(),0,Red);

return(0);

}

}

}

}

}

}

return(0);

}

//+------------------------------------------------------------------+

merci roger09 Dieu vous bénisse

 

Merci Roger, j'ai supprimé la deuxième déclaration de limite de ma fonction de démarrage. Je suis surpris que le compilateur l'ait autorisée, mais cela n'a pas eu d'impact notable sur mon programme.

Je ne sais toujours pas comment modifier l'instance en cours de cet indicateur dans mon EA. Une méthode serait très appréciée, ou au moins la confirmation que l'API ne me permet pas actuellement de transmettre des informations aux indicateurs en cours d'exécution.

Merci.

 
yingli:
Je suis en train d'apprendre à coder l'indicateur ci-joint, mais cela n'a pas fonctionné, quelqu'un peut-il m'aider ? C'est un indicateur très fiable et si quelqu'un pouvait faire un EA pour lui, c'est presque le Saint Graal.

Le principe de base est le suivant :

1.ouvrir une position de vente lorsque la flèche rouge apparaît,

2.ouvrir une position d'achat lorsque la flèche blanche apparaît et fermer automatiquement toutes les positions de vente.

3.s'applique à n'importe quelle période de temps.

4.pas de stop loss,

5.ajouter la fonction d'ordre.

J'attends votre réponse avec impatience !

//+------------------------------------------------------------------+

//| IINWMARROWS.mq4 |

//| Basé sur EMA_CROSS.mq4 |

//| Copyright ?2006, MetaQuotes Software Corp. |

//| Logiciel de trading Forex : Plateforme de trading Forex MetaTrader 4 | //|

| //| Dernière petite modification par Iin Zulkarnain |

//+------------------------------------------------------------------+

#property copyright "Copyright ?2006, MetaQuotes Software Corp."

#property link "http://www.metaquotes.net"

//----

#property indicator_chart_window

#property indicator_buffers 2

#property indicator_color1 White

#property indicator_color2 Red

#property indicator_width1 2

#property indicator_width2 2

//----

double CrossUp[] ;

double CrossDown[] ;

extern int FasterMode=3 ; //0=sma, 1=ema, 2=smma, 3=lwma

extern int FasterMA= 3 ;

extern int SlowerMode=3 ; //0=sma, 1=ema, 2=smma, 3=lwma

extern int SlowerMA= 3 ;

//+------------------------------------------------------------------+

//| Fonction d'initialisation de l'indicateur personnalisé |

//+------------------------------------------------------------------+

int init()

{

//---- indicateurs

SetIndexStyle(0, DRAW_ARROW, EMPTY) ;

SetIndexArrow(0, 233) ;

SetIndexBuffer(0, CrossUp) ;

SetIndexStyle(1, DRAW_ARROW, EMPTY) ;

SetIndexArrow(1, 234) ;

SetIndexBuffer(1, CrossDown) ;

//----

return(0) ;

}

//+------------------------------------------------------------------+

//| Fonction personnalisée de désinitialisation de l'indicateur |

//+------------------------------------------------------------------+

int deinit()

{

//----

//----

return(0) ;

}

//+------------------------------------------------------------------+

//| Fonction d'itération de l'indicateur personnalisée |

//+------------------------------------------------------------------+

int start()

{

int limite, i, compteur ;

double fasterMAnow, slowerMAnow, fasterMAprevious, slowerMAprevious, fasterMAafter, slowerMAafter ;

double Range, AvgRange ;

int counted_bars=IndicatorCounted() ;

//---- vérifier les erreurs éventuelles

if(counted_bars<0) return(-1) ;

//---- dernière barre comptée sera recomptée

if(counted_bars>0) counted_bars-- ;

//----

limit=Bars-counted_bars ;

for(i=0 ; i<=limit ; i++)

{

counter=i ;

Gamme=0 ;

AvgRange=0 ;

for(counter=i ;counter<=i+9;counter++)

{

AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]) ;

}

Range=AvgRange/10 ;

fasterMAnow=iMA(NULL, 0, FasterMA, 0, FasterMode, PRICE_CLOSE, i) ;

fasterMAprevious=iMA(NULL, 0, FasterMA, 0, FasterMode, PRICE_CLOSE, i+1) ;

fasterMAafter=iMA(NULL, 0, FasterMA, 0, FasterMode, PRICE_CLOSE, i-1) ;

//----

slowerMAnow=iMA(NULL, 0, SlowerMA, 0, SlowerMode, PRICE_OPEN, i) ;

slowerMAprevious=iMA(NULL, 0, SlowerMA, 0, SlowerMode, PRICE_OPEN, i+1) ;

slowerMAafter=iMA(NULL, 0, SlowerMA, 0, SlowerMode, PRICE_OPEN, i-1) ;

if ((fasterMAnow > slowerMAnow) && (fasterMAprevious slowerMAafter))

{

CrossUp=Low - Range*0.5 ;

}

else if ((fasterMAnow slowerMAprevious) && (fasterMAafter < slowerMAafter))

{

CrossDown=High + Range*0.5 ;

}

}

return(0) ;

}

//+------------------------------------------------------------------+ce fil pour apprendre à coder correctement, j'apprends à coder pour

Je suis en train d'apprendre à coder l'indicateur ci-joint, mais cela ne fonctionne pas.

 

Calculatrice Oscar de George - Quelqu'un peut-il coder un indicateur pour cette calculatrice ?

Salut les amis,

Je ne sais pas si quelqu'un est familier avec Forex Made-EZ de George Smith.

Je suis en train de revoir son travail et je me demandais si quelqu'un avait codé un indicateur pour l'oscillateur Oscar qu'il utilise ?

La formule est la suivante

let A = le plus haut sommet des huit dernières barres (y compris celle-ci)

let B = le plus bas niveau des huit dernières barres (y compris celle-ci)

let C = prix de clôture de la barre actuelle

let X = la valeur précédente de l'oscillateur (Oscar)

L'oscillateur "brut" d'aujourd'hui est égal à (C-B) divisé par (A-B) multiplié par 100.

Ensuite, nous "lissons" notre chiffre brut (appelons-le Y) comme suit :

L'oscillateur final = ((X divisé par 3) fois 2), plus (Y divisé par 3).

Si quelqu'un a codé ou peut coder ceci, il serait très apprécié.

Salutations Steve

 

Stop suiveur inversé

Bonjour,

J'ai besoin d'aide pour une idée.

J'utilise des trailing stops sur mes EAs (3 step trailing), mais je veux faire le truc inversé pour protéger les pertes.

Je vais essayer d'expliquer :

J'ouvre un ordre, avec un stop loss initial.

Si la transaction va de 15 pips dans la direction de la perte et revient de 10 pips, je ferme la transaction (première étape).

Si la transaction va à 30 pips dans le sens de la perte et revient à 15 pips, je ferme la transaction (deuxième étape).

Quelque chose comme ceci.

Merci pour votre aide

 
dedreko:
Bonjour,

J'ai besoin d'aide pour une idée.

J'utilise des stops suiveurs sur mes EAs (trailing 3 étapes), mais je veux faire la chose inversée pour protéger les pertes.

Je vais essayer d'expliquer :

J'ouvre un ordre, avec un stop loss initial.

Si le trade va de 15 pips dans la direction de la perte et revient de 10 pips, je ferme le trade (première étape).

Si la transaction va à 30 pips dans le sens de la perte et revient à 15 pips, je ferme la transaction (deuxième étape).

Quelque chose comme ceci.

Merci pour votre aide

C'est quelque chose de nouveau pour moi.

Donc, la clôture d'une transaction perdante doit toujours attendre qu'elle rebondisse, n'est-ce pas ?

Et s'il ne rebondit pas ?

Clôturons-nous la transaction au niveau du SL initial ?

Raison: