Petit robot auto-adaptatif
Code
//+------------------------------------------------------------------+
//| Easiest_ATR_V2.mq4 |
//| Copyright 2020, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
extern int MagicNumber =22112020;
extern string mn="Easiest";
extern double LotFactor = 126;
extern int atrMultipleSL=36;
extern int atrMultipleTP=86;
extern int PeriodATR=28;
extern int ShiftATR=0;
int last_bar = 0;
int start()
{
if (last_bar == Bars) return(0);
last_bar = Bars;
if (OrdersTotal() == 0)
{
//+------------------------------------------------------------------+
// Dynamic stoploss and takeprofit
//+------------------------------------------------------------------+
double atr = iATR(NULL, 0, PeriodATR, ShiftATR);
double stop_loss = (atr * atrMultipleSL / Point);
double take_profit = (atr *atrMultipleTP / Point);
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
int ticket1 = (OrderSend(Symbol(), OP_BUY, (AccountBalance() * 0.01 /LotFactor) ,Ask, 3, Ask - stop_loss * Point, Bid + take_profit * Point,"Easiest", MagicNumber, 0, Blue));
int ticket2= (OrderSend(Symbol(), OP_SELL, (AccountBalance() * 0.01 /LotFactor) ,Bid, 3, Bid + stop_loss * Point, Ask - take_profit * Point, "Easiest", MagicNumber, 0, Red));
}
return(0);
}