I decided to robotize my trading a bit. I used a trend Expert Advisor from MT4 terminal "MovingAverage". I have decided to use my own EA from MT4 terminal and made some slight modifications. I added one more mask, changed entry and exit conditions, added stop and profit and limited opening time. I would like to add more.
1) The ability to open two orders at once with adjustable stop loss, take profit, move to zero loss.
2) Adjustable number of entries per day.
3) Adjustable possibility to enter the next day when a trade is open.
4)Adjustable exit by stop loss, no loss or take profit.
5)Removing calculation of maximum risk. (Particular need I do not see it, besides I do not understand how he calculates the risk, the impression that from the background, lots were opened then 0.10 then 1.00)
6) Does not work correctly on the currency pair USDJPY
Perhaps something to fix, clean to improve the work of the EA. Help or tips.
Works on more than ten charts simultaneously, in each window of the currency pair chart has its own EA. The code is attached. Thank you to everyone who responds.
//+------------------------------------------------------------------+//| MA_MA_1.mq4 |//| Copyright 2017, MetaQuotes Software Corp. |//| https://www.mql5.com |//+------------------------------------------------------------------+#property copyright"Copyright 2017, MetaQuotes Software Corp."#property link"https://www.mql5.com"#property version"1.00"//#property strict#define MAGICMA 20131112//--- Inputsinputdouble SL =500; //стоп лосinputdouble TakeProfit =1000; //тейк профитinputdouble Lots =0.01; //розмер лота//input double MaximumRisk =0.1; //отключил не понятна логика расчетаinputdouble DecreaseFactor = 3; //фактор снижение(наверно проскальзывание)inputint MovingPeriod1 =36; //медленная средняяinputint MovingPeriod2 =12; //быстрая средняяinputint MovingShift1 =10; //сдвиг медленной среднейinputint MovingShift2 = 0; //сдвиг быстрой среднейexternint TimeStart = 8; //время начала торговexternint TimeStop =20; //время окончания торгов//+------------------------------------------------------------------+//| Calculate open positions //считаем открытые позиции |//+------------------------------------------------------------------+int CalculateCurrentOrders(string symbol)
{
int buys=0,sells=0;
//---for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
{
if(OrderType()==OP_BUY) buys++;
if(OrderType()==OP_SELL) sells++;
}
}
//--- return orders volume //объём ордеров на возвратif(buys>0) return(buys);
elsereturn(-sells);
}
//+------------------------------------------------------------------+//| Calculate optimal lot size //расчет оптимального размера лота |//+------------------------------------------------------------------+double LotsOptimized()
{
double lot=Lots;
int orders=HistoryTotal(); // history orders total (история заказов всего)int losses=0; // number of losses orders without a break (количество потерь заказов без перерыва)//--- select lot size //ОТКЛЮЧИЛ выбор размер лота. //lot=NormalizeDouble(AccountFreeMargin()*MaximumRisk/1000.0,1);//(логика выбора мне не понятна)//--- calcuulate number of losses orders without a break (Расчет количества заказов на потери без перерыва)// if(DecreaseFactor>0)// {// for(int i=orders-1;i>=0;i--)// {// if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false)// {// Print("Error in history!");// break;// }// if(OrderSymbol()!=Symbol() || OrderType()>OP_SELL)// continue;//---// if(OrderProfit()>0) break;// if(OrderProfit()<0) losses++;// }// if(losses>1)// lot=NormalizeDouble(lot-lot*losses/DecreaseFactor,1);// }//--- return lot size (розмер возвращаемого лота)if(lot<0.1) lot=0.1;
return(lot);
}
//+------------------------------------------------------------------+//| Check for open order conditions //проверка условий для открытия ордера |//+------------------------------------------------------------------+void CheckForOpen()
{
double ma1; //медленная средняяdouble ma2; //быстрая средняяint res;
//--- go trading only for first tiks of new bar// торговать только на первом тике нового бараif(Volume[0]>1) return;
//--- get Moving Average //получение скользящих средних
ma1=iMA(NULL,0,MovingPeriod1,MovingShift1,MODE_SMA,PRICE_CLOSE,0);//медленная
ma2=iMA(NULL,0,MovingPeriod2,MovingShift2,MODE_SMA,PRICE_CLOSE,0);//быстрая//--- sell conditions //условия для продажиif(ma1<ma2 && Close[1]<ma1 && TimeHour(TimeCurrent())>TimeStart && TimeHour(TimeCurrent())<TimeStop)
{
res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,Bid+SL*Point,Bid-TakeProfit*Point,"",MAGICMA,0,Red);
return;
}
//--- buy conditions //условия для покупкиif(ma1>ma2 && Close[1]>ma1 && TimeHour(TimeCurrent())>TimeStart && TimeHour(TimeCurrent())<TimeStop)
{
res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,Ask-SL*Point,Ask+TakeProfit*Point,"",MAGICMA,0,Blue);
return;
}
//---
}
//+------------------------------------------------------------------+//| Check for close order conditions //проверка условий для закрытия ордера |//+------------------------------------------------------------------+void CheckForClose()
{
double ma1;//медленнаяdouble ma2;//быстрая//--- go trading only for first tiks of new bar// торговать толькона тике нового бараif(Volume[0]>1) return;
//--- get Moving Average //получение средних
ma1=iMA(NULL,0,MovingPeriod1,MovingShift1,MODE_SMA,PRICE_CLOSE,0);//медленная
ma2=iMA(NULL,0,MovingPeriod2,MovingShift2,MODE_SMA,PRICE_CLOSE,0);//быстрая//---for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
//--- check order type //проверка типа ордераif(OrderType()==OP_BUY)
{
if(Close[1]<ma2 && Open[2]>Close[1] && ma1<ma2) //(Open[1]>ma && Close[1]<ma)
{
if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,White))
Print("OrderClose error ",GetLastError());
}
break;
}
if(OrderType()==OP_SELL)
{
if(Close[1]>ma2 && Open[2]<Close[1] && ma1>ma2)
{
if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,White))
Print("OrderClose error ",GetLastError());
}
break;
}
}
//---
}
//+------------------------------------------------------------------+//| OnTick function //функция нового тика |//+------------------------------------------------------------------+voidOnTick()
{
//--- check for history and tradingif(Bars<100 || IsTradeAllowed()==false)
return;
//--- calculate open orders by current symbolif(CalculateCurrentOrders(Symbol())==0) CheckForOpen();
else CheckForClose();
//---
}
//+------------------------------------------------------------------+
Hello. Can you write an expert advisor on this strategy https://www.youtube.com/watch?v=V58JIhy2rw4. Or maybe you have an expert advisor, that stagnates on the spot or goes to profit a little bit.... For earnings on rebate on site fxcash.ru. Thanks. If that please contact https://vk.com/id16112208 or in private.
Good afternoon!
I decided to robotize my trading a bit. I used a trend Expert Advisor from MT4 terminal "Moving Average". I have decided to use my own EA from MT4 terminal and made some slight modifications. I added one more mask, changed entry and exit conditions, added stop and profit and limited opening time. I would like to add more.
1) The ability to open two orders at once with adjustable stop loss, take profit, move to zero loss.
2) Adjustable number of entries per day.
3) Adjustable possibility to enter the next day when a trade is open.
4)Adjustable exit by stop loss, no loss or take profit.
5)Removing calculation of maximum risk. (Particular need I do not see it, besides I do not understand how he calculates the risk, the impression that from the background, lots were opened then 0.10 then 1.00)
6) Does not work correctly on the currency pair USDJPY
Perhaps something to fix, clean to improve the work of the EA. Help or tips.
Works on more than ten charts simultaneously, in each window of the currency pair chart has its own EA. The code is attached. Thank you to everyone who responds.
Hello. Can you use this strategy to write an advisor https://www.youtube.com/watch?v=V58JIhy2rw4. Or do you have any advisor that stagnates in place or is slightly in the black.... For earnings on rebate on site fxcash.ru. Thanks. If that beep in Ek https://vk.com/id16112208 or in private.
Look at the branch Avalanche, there are advisors for this TS.
Hello!
Can I get some help? The Expert Advisor is retrieving trades every tick. How do I write code to take away about 5 trades or only as many as I want?
extern int tp=50;
extern int sl=200;
extern double lot=0.01;
oid OnTick()
{
OrderSend("USDJPY",OP_SELL,lot,Bid,0,Ask+sl*Point,Ask-tp*Point, "Batsasho",1,0,Red);
}
What should I change or add to the code?
Thank you!
If I don't make it difficult you can answer ***
Thank you!
I tried to re-do the ready-made templates, but in the end they give out a couple of errors, all I need is an owl:
1) opens a buy position if the closed candle is bullish, and a sell position if the closed candle is bearish.
2) and so on after EVERY candlestick.
I have the second condition does not work.
If anyone can help, I will be very grateful.
Can I get some help? The Expert Advisor will retrieve trades every tick. How do I write the code to draw about 5 trades or only as many as I want?
What should I change or add to the code?