- Ea's must adjust for 5 digit brokers TP, SL, AND slippage. On ECN brokers you must open order and THEN set stops
//++++ These are adjusted for 5 digit brokers. int pips2points; // slippage 3 pips 3=points 30=points double pips2dbl; // Stoploss 15 pips 0.0015 0.00150 int Digits.pips; // DoubleToStr(dbl/pips2dbl, Digits.pips) int init(){ if (Digits == 5 || Digits == 3){ // Adjust for five (5) digit brokers. pips2dbl = Point*10; pips2points = 10; Digits.pips = 1; } else { pips2dbl = Point; pips2points = 1; Digits.pips = 0; } // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
- You MUST count down when closing orders in the presence of multiple orders (multiple charts)
while (OrderClose(OrderTicket(),OrderLots(),Bid,3) == false && f < 10) { f++; RefreshRates(); OrderClose(OrderTicket(),OrderLots(),Bid,3); Sleep(1000); }
If the second close succeeds the first will never and you know have an infinite loop. You MUST refreshRates AFTER sleep.
Thanks for your help. But i am not a coder and do not really understand what you mean.
Is there a chance for you to change te things that needed to work this EA?
Thanks!
No slaves here, learn to code or pay someone.
what are the costs?
Oanda send me to here because they have no idea of MT4. Little bit strange when you work with them.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello,
I have an EA that not work on Oanda MT4, but it is working on Alpari, EA is on at the platform etc.. so it must work.
Any idea? many many thanks.
#property copyright "Tous droits réservés, Nicolas Tuffier (2011)"
#property link "http://www.furyweb.fr/forex/"
#import "stdlib.ex4"
string ErrorDescription(int error_code);
#import
#include <stderror.mqh>
#define NAME "TDI Trend"
#define VERSION "1.0"
extern double lotSize=0.2;
extern int StopLoss=100;
extern int FirstEven=60;
extern int BreakEven=120;
extern int TakeProfit=180;
extern bool CloseAtOpositeCross = true;
extern int Minutes=0;
extern int RSIperiod=26;
extern int RSIprice=5;
extern int VolatilityBand=68;
extern int RsiPriceLine=2;
extern int RsiPriceType=0;
extern int TradeSignalLine=14;
extern int TradeSignalType=0;
extern bool Alerts = true;
extern int ADXFilterLimit=0;
extern int AdxPeriod=14;
extern int AdxTimeFrame=0;
extern string InfosValues="Label Settings";
extern bool ShowOtherInfos = true;
extern bool ShowSpreadAndDailyRange = true;
extern int DailyAtrPeriod=40;
extern int LabelXpos=10;
extern int LabelYpos=15;
extern string Capture="Screeshots (Stocked in ..\experts\files)";
extern bool TakeScreenShot = true;
extern int size_x = 1280;
extern int size_y = 720;
int ticket;
int a = 0;
int i, f;
int magicNumber = 915274;
double savedVolume;
double adx, TPPoints, SLPoints;
string symbolpair, time;
bool Buy,Sell, Nothing, Nothing2;
double MA1, MA2, MA3, MA4;
string MAvalue, MAvalue2;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int init()
{
// TPPoints = TakeProfit * Point * MathPow(10, Digits % 2);
//SLPoints = StopLoss * Point * MathPow(10, Digits % 2);
return(0);}
bool newBarFormed() {
bool ret=Volume[0] < savedVolume;
savedVolume = Volume[0];
return(ret);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
if (OrdersTotal()>0)
OrdersList();
adx = iADX(NULL,AdxTimeFrame,AdxPeriod,PRICE_CLOSE,MODE_MAIN,0);
MA1 = iCustom(NULL, Minutes, "TDI Red Green",RSIperiod, RSIprice, VolatilityBand, RsiPriceLine, RsiPriceType, TradeSignalLine, TradeSignalType, 4, 1);
MA2 = iCustom(NULL, Minutes, "TDI Red Green",RSIperiod, RSIprice, VolatilityBand, RsiPriceLine, RsiPriceType, TradeSignalLine, TradeSignalType, 5, 1);
MA3 = iCustom(NULL, Minutes, "TDI Red Green",RSIperiod, RSIprice, VolatilityBand, RsiPriceLine, RsiPriceType, TradeSignalLine, TradeSignalType, 2, 1);
//------------------------------------------
if( MA1 > MA2 && MA1 > MA3)
{
MAvalue2 = "UP]";
//Nothing=false;
}
else
if( MA1 < MA2 && MA1 < MA3)
{
MAvalue2 = "DOWN]";
//Nothing=false;
}
else
{
MAvalue2 = "NOTHING]";
//Nothing=true;
//a = 3;
}
if (Nothing)
MAvalue="TRUE";
else
MAvalue="FALSE";
symbolpair = Symbol();
time = TimeToStr(TimeCurrent());
if (ShowOtherInfos == true)
{
ObjectCreate("BarTimer3",OBJ_LABEL,0,0,0);
ObjectSet("BarTimer3", OBJPROP_XDISTANCE, LabelXpos);
ObjectSet("BarTimer3", OBJPROP_YDISTANCE, LabelYpos);
ObjectSetText("BarTimer3", "[Trend : "+MAvalue2+" - "+MAvalue+" - [ADX("+AdxTimeFrame+") : "+DoubleToStr(adx, 0)+ "]", 11, "Arial", White);
}
if (ShowSpreadAndDailyRange == true)
{
ObjectCreate("BarTimer4", OBJ_LABEL,0,0,0);
ObjectSet("BarTimer4", OBJPROP_XDISTANCE, LabelXpos);
if (ShowOtherInfos == true)
ObjectSet("BarTimer4", OBJPROP_YDISTANCE, LabelYpos+22);
else
ObjectSet("BarTimer4", OBJPROP_YDISTANCE, LabelYpos);
ObjectSetText("BarTimer4", "[Day ATR"+DailyAtrPeriod+" : "+DoubleToStr(iATR(NULL,1440,DailyAtrPeriod,0)*10000, 0)+ "] - [Day Range : "+DoubleToStr(iATR(NULL,1440,1,0)*10000, 0)+"] - [Spread : "+DoubleToStr(MarketInfo("EURUSD",MODE_SPREAD)/10,1)+ " Pips]", 11, "Arial", Yellow);
}
else
ObjectDelete("BarTimer4");
if (a == 0)
{
if(MA1 > MA2 && MA1 > MA3 )
a=1;
else
if( MA1 < MA2 && MA1 < MA3 )
a=2;
else
a=3;
}
if (newBarFormed())
{
Buy = MA1 > MA2 && MA1 > MA3;
Sell = MA1 < MA2 && MA1 < MA3;
Nothing = !Sell && !Buy;
//Nothing2 = MA1 < MA2 && MA1 > MA3;
//------------ verif de positions
int scnt = 0,f = 0, bcnt = 0, cnt = OrdersTotal();
for (i = 0; i < cnt; i++)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
if (OrderMagicNumber() == magicNumber)
if (OrderType() == OP_BUY && OrderSymbol() == symbolpair)
{
if (CloseAtOpositeCross)
{
if(Sell || Nothing)
{
while (OrderClose(OrderTicket(),OrderLots(),Bid,3) == false && f < 10)
{
f++;
RefreshRates();
OrderClose(OrderTicket(),OrderLots(),Bid,3);
Sleep(1000);
}
a=3;
Alert(Symbol()," - TDI Trend CLOSED - ",Period()," @ ",Bid," ",time);
}
}
bcnt++;
}
else
if (OrderType() == OP_SELL && OrderSymbol() == symbolpair)
{
if (CloseAtOpositeCross)
{
if(Buy || Nothing)
{
while (OrderClose(OrderTicket(),OrderLots(),Ask,3) == false && f < 10)
{
f++;
RefreshRates();
OrderClose(OrderTicket(),OrderLots(),Ask,3);
Sleep(1000);
}
a=3;
Alert(Symbol()," - TDI Trend CLOSED - ",Period()," @ ",Ask," ",time);
}
}
scnt++;
}
// -------------- fin verif
}
if (adx>ADXFilterLimit)
{
//------------------------------------------
if((Buy) && a != 1)
{
if (Alerts == true)
Alert(Symbol()," - TDi Trend UP - BUY - ",Period()," @ ",Bid," ",time);
if (bcnt == 0)
{
//----------- passage d'ordre avec verif harcelement
ticket=OrderSend(Symbol(), OP_BUY, lotSize, Ask, 3, Ask-StopLoss*Point, Ask+TakeProfit*Point, NAME + " " + VERSION, magicNumber);
while (ticket == -1) // tant que l’ordre n’est pas passé
{
RefreshRates(); //on rafraichit les valeurs du cours de la paire
ticket = OrderSend(Symbol(), OP_BUY, lotSize, Ask, 3, Ask-StopLoss*Point, Ask+TakeProfit*Point, NAME + " " + VERSION, magicNumber);
Sleep(1000); // on attend une seconde
}
//------------ fin passage d'ordre
//OrderSend(Symbol(), OP_BUY, lotSize, Ask, 3, 0, 0, NAME + " " + VERSION, magicNumber);
if (TakeScreenShot == true)
if(!WindowScreenShot(StringConcatenate(NAME + "-" + Symbol(),"-",Period(),"-",TimeToStr(TimeCurrent(),TIME_DATE),"-",Hour(),"H",Minute(),".gif"),size_x,size_y))
Print(GetLastError());
}
a = 1;
}
if((Sell) && a != 2)
{
if (Alerts == true)
Alert(Symbol()," - TDI Trend DOWN - SELL - ",Period()," @ ",Bid," ",time);
if (scnt == 0)
{
//----------- passage d'ordre avec verif harcelement
ticket=OrderSend(Symbol(), OP_SELL, lotSize, Bid, 3, Bid+StopLoss*Point, Bid-TakeProfit*Point, NAME + " " + VERSION, magicNumber);
while (ticket == -1) // tant que l’ordre n’est pas passé
{
RefreshRates(); //on rafraichit les valeurs du cours de la paire
ticket=OrderSend(Symbol(), OP_SELL, lotSize, Bid, 3, Bid+StopLoss*Point, Bid-TakeProfit*Point, NAME + " " + VERSION, magicNumber);
Sleep(1000); // on attend une seconde
}
//------------ fin passage d'ordre
// OrderSend(Symbol(), OP_SELL, lotSize, Bid, 3, 0, 0, NAME + " " + VERSION, magicNumber);
if (TakeScreenShot == true)
if(!WindowScreenShot(StringConcatenate(NAME + "-" + Symbol(),"-",Period(),"-",TimeToStr(TimeCurrent(),TIME_DATE),"-",Hour(),"H",Minute(),".gif"),size_x,size_y))
Print(GetLastError());
}
a = 2;
}
//------------------------------------------
}
return(0); }
//+------------------------------------------------------------------+
void OrdersList()
{
for (int cnt=0;cnt<OrdersTotal();cnt++)
{
OrderSelect(cnt, SELECT_BY_POS);
if (OrderSymbol()==Symbol() && OrderMagicNumber() == magicNumber)
{
if (OrderType()==OP_BUY)
{
/* if (OrderStopLoss()==0)
{
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-StopLoss*Point,OrderOpenPrice()+TakeProfit*Point,0,LightGreen);
return(0);
} */
//---- FirstEven
if (Bid-OrderOpenPrice()>Point*FirstEven&&OrderStopLoss()<OrderOpenPrice()&&Bid-OrderOpenPrice()<Point*BreakEven)
{
{OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-StopLoss*Point/2,OrderTakeProfit(),0,LightGreen);
return(0);}
}
//---- BreakEven
if (Bid-OrderOpenPrice()>Point*BreakEven&&OrderStopLoss()<OrderOpenPrice())
{
{OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,LightGreen);
return(0);}
}
}
if (OrderType()==OP_SELL)
{
/* if (OrderStopLoss()==0)
{
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+StopLoss*Point,OrderOpenPrice()-TakeProfit*Point,0,Yellow);
return(0);
} */
//---- FirstEven
if (OrderOpenPrice()-Ask>Point*FirstEven&&OrderStopLoss()>OrderOpenPrice()&&OrderOpenPrice()-Ask<Point*BreakEven)
{
{OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+StopLoss*Point/2,OrderTakeProfit(),0,Yellow);
}
return(0);
}
//---- BreakEven
if (OrderOpenPrice()-Ask>Point*BreakEven&&OrderStopLoss()>OrderOpenPrice())
{
{OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Yellow);
}
return(0);
}
}
}
}
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit() {
//----
ObjectDelete("BarTimer3");
ObjectDelete("BarTimer4");
//----
return(0);
}