Tout est dans le titre.
Code
PriceAsk = NormalizeDouble(Ask, Digits);
La garantie Forexagone permet de vous assurer que votre gain ne soit pas perdu. Nous négocions les meilleurs taux avec les brokers agréés par l’AMF.
PriceAsk = NormalizeDouble(Ask, Digits);
double spread = (MarketInfo(Symbol(), MODE_SPREAD));
if (!IsTradeContextBusy() && IsTradeAllowed())
{
OrderSend(Symbol(), OP_BUYSTOP, LOTS, High[1], 3, (Low[1] - (spread * Point * MathPow(0.1, Digits % 2)) - (3 * Point * MathPow(10, Digits % 2))),
Ask + TP * Point * MathPow(10, Digits % 2), NAME, MAGICNUMBER, 0, Green);
}
if (!IsTradeContextBusy() && IsTradeAllowed())
{
OrderSend(Symbol(), OP_SELLSTOP, LOTS, Low[1], 3, (High[1] + (spread * Point * MathPow(0.1, Digits % 2)) + (3 * Point * MathPow(10, Digits % 2))),
Bid - TP * Point * MathPow(10, Digits % 2), NAME, MAGICNUMBER, 0, Red);
}
}
double pip2point = Point * MathPow(10, Digits % 2);
price = High[1]; // ou Low[1] pour SELLSTOP
stopLevel = MarketInfo(Symbol(), MODE_STOPLEVEL) * Point;
spread = MarketInfo(Symbol(), MODE_SPREAD) * Point;
if (price < Ask + stopLevel) // ou (price > Bid - stopLevel) pour SELLSTOP
price = Ask + stopLevel; // ou Bid - stopLevel pour SELLSTOP
tp = price + TP * pip2point; // ou mieux encore, TP = TakeProfit * pip2point dans le init et où TakeProfit est le paramètre de l'EA ce qui évite une opération superflue ; pour un SELLSTOP on a price - TP
sl = Low[1] - spread - 3 * pip2point; // ou High[1] + spread + 3 * pip2point;
Print ("Trying to open buy stop order with price=", price, " sl=", sl, " and tp=", tp);
ticket = OrderSend(Symbol(), OP_BUYSTOP, LOTS, price, 3, sl, tp, NAME, MAGICNUMBER, 0, Green);
}
//----Trailing Stop
for (int i = 0; i < OrdersTotal(); i++){
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
//--- LONG TRADES
if(OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == MAGICNUMBER){
if (Bid - OrderOpenPrice() >= TrailingStop * pip2point){
if (OrderStopLoss() < Bid - TrailingStop * pip2point || OrderStopLoss() == 0){
OrderModify(OrderTicket(), OrderOpenPrice(), Bid - TrailingStop * pip2point, OrderTakeProfit(), Red);
}
}
}
//---SHORT TRADES
if(OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == MAGICNUMBER){
if(OrderOpenPrice() - Ask >= TrailingStop * pip2point){
if((OrderStopLoss() > Ask + TrailingStop * pip2point) || OrderStopLoss() == 0){
OrderModify(OrderTicket(), OrderOpenPrice(),Ask + TrailingStop * pip2point, OrderTakeProfit(), Red);
}
}
}
}
//----Trailing Stop
int cnt = OrdersTotal(); // préférable d'utiliser une variable pour éviter les appels à la fonction à chaque boucle
for (int i = 0; i < cnt; i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { // vérification de sélection, on ne sait jamais
//--- LONG TRADES
if(OrderSymbol() == Symbol() && OrderMagicNumber() == MAGICNUMBER) { // une seule vérification par boucle au lieu de 2
if(OrderType() == OP_BUY) {
if (Bid >= OrderOpenPrice() + TrailingStop * pip2point) {
if (OrderStopLoss() < Bid - TrailingStop * pip2point || OrderStopLoss() == 0) {
OrderModify(OrderTicket(), OrderOpenPrice(), Bid - TrailingStop * pip2point, OrderTakeProfit()); // pas de couleur pour les OrderModify pour éviter de surcharger le graphique
}
}
}
//---SHORT TRADES
if(OrderType() == OP_SELL) {
if(Ask <= OrderOpenPrice() - TrailingStop * pip2point) {
if((OrderStopLoss() > Ask + TrailingStop * pip2point) || OrderStopLoss() == 0) {
OrderModify(OrderTicket(), OrderOpenPrice(), Ask + TrailingStop * pip2point, OrderTakeProfit());
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init() {
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit() {
//----
return(0);
}
int start() // Special fonct. start
{
double ma_expo=iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,0);
double ma_simple=iMA(NULL,0,14,0,MODE_SMA,PRICE_CLOSE,0);
int ticket;
if(ma_expo==ma_simple)
{
Alert("croisement");
Print("croisement");
}
if(DoubleToStr(ma_expo,6)==DoubleToStr(ma_simple,6))
{
/*Alert("croisement 2 script 1");
Alert("ma expo= ", DoubleToStr(ma_expo,8));
Alert("ma simple= ", DoubleToStr(ma_simple,8));
Print("croisement 2");
Print(GlobalVariableGet("ma expo"));
Print(GlobalVariableGet("ma simple"));*/
if(GlobalVariableGet("ma expo")<GlobalVariableGet("ma simple"))
{
ticket = OrderSend(Symbol(),OP_BUY,1,Ask,1,0,0,NULL,1234,0,Blue);
Print("ticket ", ticket);
/*while (ticket == -1) // tant que l’ordre n’est pas passé
{
Sleep(1000); // on attend une seconde
RefreshRates(); //on rafraichit les valeurs du cours de la paire
//ticket = OrderSend(Symbol(),OP_BUY,0.1,1000,1,0,0,NULL,1234,0,Blue);
ticket=OrderSend(Symbol(), OP_BUY, 0.1, Ask, 3, Bid-15*Point, Bid+15*Point, "Premier ordre achat !", 1);
}
Alert("stop level:",MarketInfo("EURUSD",MODE_STOPLEVEL));
if(iRSI(NULL,0,14,PRICE_CLOSE,0)<25)
{
ticket=OrderSend(Symbol(), OP_BUY,1, Ask, 3, Ask-25*Point, 0, "Premier ordre achat !", 16384,0,Green);
/* while (ticket == -1) // tant que l’ordre n’est pas passé
{
Sleep(1000); // on attend une seconde
RefreshRates(); //on rafraichit les valeurs du cours de la paire
ticket = OrderSend(Symbol(), OP_BUY,1, Ask, 3, Ask-MarketInfo("EURUSD",MODE_STOPLEVEL)*Point, Ask+MarketInfo("EURUSD",MODE_STOPLEVEL)*Point, "Premier ordre achat !", 16384,0,Green);
}
Print("test ask",Ask-50*Point);
Print("ticket ", ticket);
//if(ticket<0)
// {
Print("OrderSend failed with error #",GetLastError());
//}
}*/
Alert("Acheter");
}
if(GlobalVariableGet("ma expo")>GlobalVariableGet("ma simple"))
{
ticket = OrderSend(Symbol(),OP_SELL,1,Bid,1,0,0,NULL,1234,0,Blue);
Print("ticket ", ticket);
/* while (ticket == -1) // tant que l’ordre n’est pas passé
{
Sleep(1000); // on attend une seconde
RefreshRates(); //on rafraichit les valeurs du cours de la paire
//ticket = OrderSend(Symbol(),OP_SELL,0.1,1000,1,0,0,NULL,1234,0,Blue); */
/*if(iRSI(NULL,0,14,PRICE_CLOSE,0)<25)
{
ticket =OrderSend(Symbol(), OP_SELL, 0.1, Bid, 3, Bid-MarketInfo("EURUSD",MODE_STOPLEVEL)*Point,0, "Premier ordre vente !", 16384,0,Green);
/*while (ticket == -1) // tant que l’ordre n’est pas passé
{
Sleep(1000); // on attend une seconde
RefreshRates(); //on rafraichit les valeurs du cours de la paire
ticket = OrderSend(Symbol(), OP_SELL, 0.1, Ask, 3, Ask-MarketInfo("EURUSD",MODE_STOPLEVEL)*Point, Ask+MarketInfo("EURUSD",MODE_STOPLEVEL)*Point, "Premier ordre vente !", 16384,0,Green);
}
Print("ticket ", ticket);
//if(ticket<0)
//{
Print("OrderSend failed with error #",GetLastError());
//}
}
//}
Print("ticket ", ticket);*/
Alert("Vendre");
}
}
/*int tic;
tic=OrderSend(Symbol(),OP_BUY,1,Ask,3,Ask-25*Point,Ask+25*Point,"My order #2",16384,0,Green);
Print("tic : ", tic);
/*Alert("ma1= ", DoubleToStr(ma_expo,8));
Alert("ma2= ", DoubleToStr(ma_simple,8));*/
/*Print ("ma simple= ", DoubleToStr(ma_simple,8));
Print("ma expo ", DoubleToStr(ma_expo,8));*/
//Print("gb", DoubleToStr(GlobalVariableGet("ma expo"),8));
GlobalVariableSet("ma simple", ma_simple);
GlobalVariableSet("ma expo", ma_expo);
return(0);
}
double ma_expo=iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,1);
double ma_simple=iMA(NULL,0,14,0,MODE_SMA,PRICE_CLOSE,1);
double ma_expo_avant=iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,2);
double ma_simple_avant=iMA(NULL,0,14,0,MODE_SMA,PRICE_CLOSE,2);
bool buy, sell;
if (ma_expo_avant > ma_simple_avant && ma_expo < ma_simple)
sell = true;
if (ma_expo_avant < ma_simple_avant && ma_expo > ma_simple)
buy = true;
//+------------------------------------------------------------------+
//| detect new bar formed |
//+------------------------------------------------------------------+
double savedVolume;
bool newBarFormed() {
double vol = iVolume(Symbol(), Period(), 0);
bool ret = vol < savedVolume;
savedVolume = vol;
return(ret);
}
int init () {
savedVolume = iVolume(Symbol(), Period(), 0);
}
int start () {
// placer la vérification des signaux ici
if (newBarFormed()) {
if (buy) {
// code d'achat ici
}
if (sell) {
// code de vente ici
}
}
}
if (OrderType()==OP_BUY)
{
if (OrderStopLoss()==0)
{
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-StopLoss*Point,OrderOpenPrice()+TakeProfit*Point,0,LightGreen);
return(0);
}
//---- StopEven
if (StopEven == true )
{
if (OrderStopLoss()!=OrderOpenPrice()-Point*StopLoss/StopEvenDivisedBy && OrderStopLoss()!=OrderOpenPrice())
{
if (Bid-OrderOpenPrice()>Point*StopEvenAt&&OrderStopLoss()<OrderOpenPrice()&&Bid-OrderOpenPrice()<Point*BreakEvenAt)
{
{OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-Point*StopLoss/StopEvenDivisedBy,OrderTakeProfit(),0,LightGreen);
return(0);}
}
}
}
//---- BreakEven
if (BreakEven == true)
{
if (OrderStopLoss()!=OrderOpenPrice())
{
if (Bid-OrderOpenPrice()>Point*BreakEvenAt&&OrderStopLoss()<OrderOpenPrice())
{
{OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,LightGreen);
return(0);}
} } } }
if (toto) {
{
var=0;
}
}
if (BreakEven == true)
est strictement identique à if (BreakEven)
ou l'inverse if (BreakEven != true || BreakEven == false)
est strictement identique à if (!BreakEven)
if (toto && tata)
par if (toto)
if (tata)
et ajouter des Print à chaque étape pour débugger et comprendre ce que fait l'EA.