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
To gain experience in this area, I will write 25 EAs for free for your interesting ideas and strategies
Only 19 EAs left
I have such a problem, I already have an EA and it works fine, the problem is with trailing stop block. It does not work for some reason and will not open when traded. Here is the EA itself. Maybe you have some idea what is wrong with trailing stop? I have no idea what to do without it.
Ishimoku - MACD.mq4 |
//| TO |
//| http://www.forex-tradexperts-to.narod.ru |
//+------------------------------------------------------------------+
#property copyright "TO"
#property link "http://www.forex-tradexperts-to.narod.ru"
#include <WinUser32.mqh>
extern string Parameters=" Ichimoku";
extern intern tenkan_sen=3;
extern intern kijun_sen=48;
extern intern senkou_span_b=52;
extern string Parameters="Moving Average";
extern int maPeriod=4;
extern int ma_method=1;
extern int applied_price=3;
extern string Parameters=" MACD";
extern int FastEMA=22;
extern int SlowEMA=52;
extern int SignalEMA=9;
extern string Parameters=" EA";
extern int TP=200;
extern int SL=500;
extern int slippage=3;
extern double lot=0.1;
extern bool Add1/*(TENKANSEN resp. KIJUNSEN)*/ =true;
extern bool Add2/*(TENKANSEN revised Ma)*/=true;
extern bool trailing=true;
extern double trailingStop=200;
extern int zashita=1;
bool buy1=false,buy2=false,buy3=false,buy4=false;
bool sell1=false,sell2=false,sell3=false,sell4=false,sell22=false; buy22=false;
int ticket=0;
int i;
datetime t1=0,t2=1,t3=1,t4=1,t5=1,t7=1,t8=1;
int init()
{
return(0);
}
int deinit()
{
return(0);
}
int start()
{
t1=Time[0];
double MACDRED1=iMACD(NULL,0,FastEMA,SlowEMA,SignalEMA,PRICE_CLOSE,MODE_MAIN,1);
double MACDRED2=iMACD(NULL,0,FastEMA,SlowEMA,SignalEMA,PRICE_CLOSE,MODE_MAIN,2);
double MACDBLUE1=iMACD(NULL,0,FastEMA,SlowEMA,SignalEMA,PRICE_CLOSE,MODE_SIGNAL,1);
double MACDBLUE2=iMACD(NULL,0,FastEMA,SlowEMA,SignalEMA,PRICE_CLOSE,MODE_SIGNAL,2);
double IshRed1=iIchimoku(NULL,0,tenkan_sen,kijun_sen,senkou_span_b,MODE_TENKANSEN,1);
double IshRed2=iIchimoku(NULL,0,tenkan_sen,kijun_sen,senkou_span_b,MODE_TENKANSEN,2);
double IshBlue1=iIchimoku(NULL,0,tenkan_sen,kijun_sen,senkou_span_b,MODE_KIJUNSEN,1);
double IshBlue2=iIchimoku(NULL,0,tenkan_sen,kijun_sen,senkou_span_b,MODE_KIJUNSEN,2);
double MA1=iMA(NULL,0,maPeriod,0,ma_method,applied_price,1);
double MA2=iMA(NULL,0,MaPeriod,0,ma_method,applied_price,2);
if(MACDRED1>MACDBLUE1 && MACDRED2<MACDBLUE2 && t3!=t1)
{ // MACD BUY signal
buy1=true;sell1=false;t3=Time[0];
}
if(MACDRED1<MACDBLUE1 && MACDRED2>MACDBLUE2 && t3!=t1)
{ // MACD SELL signal
sell1=true;buy1=false;t3=Time[0];
}
if(IshRed1>MA1 && IshRed2<=MA2 && t4!=t1)
{ // Ishimoku signal crosses the MA on BUY
buy2=true;sell2=false;t4=Time[0];
}
if(IshRed1<MA1 && IshRed2>=MA2 && t4!=t1)
{ // Ishimoku signal crosses MA on SELL
sell2=true;buy2=false;t4=Time[0];
}
if(IshRed1>IshBlue1 && IshRed2<IshBlue2 && t5!=t1)
{ // Ishimoku signal Fast crosses Slow to BUY
buy3=true;sell3=false;t5=Time[0];
}
if(IshRed1<IshBlue1 && IshRed2>IshBlue2 && t5!=t1)
{ // Signal on Ishimoku Fast crosses Slow on SELL
sell3=true;buy3=false;t5=Time[0];
}
if(Add1==true && buy3==true && buy4==true && t1!=t8)
{ //open additions
PlaySound("Alert.wav");
int=MessageBox("Add an order to Buy?",MB_YESNO|MB_ICONQUESTION);
if(ret==6){ticket=OrderSend(Symbol(),OP_BUY,lot,Ask,slippage,Bid-SL*Point,Ask+TP*Point,NULL,0,0,Blue);if(ticket>0)PlaySound("ok.wav");if(ticket<0)Alert("Order not set!!! error - "+GetLastError()+"set manually");}
t8=Time[0];buy3=false;buy4=false;
}
if(Add1==true && sell3==true && sell4==true && t1!=t7)
{ //open additions
PlaySound("Alert.wav");
int ret2=MessageBox("Add a Sell order?",MB_YESNO|MB_ICONQUESTION);
if(ret2==6){ticket=OrderSend(Symbol(),OP_SELL,lot,Bid,slippage,Ask-SL*Point,Bid+TP*Point,NULL,0,0,Red);if(ticket>0)PlaySound("ok.wav");if(ticket<0)Alert("Order not set!!! error - "+GetLastError()+"set manually");}
t7=Time[0];sell3=false;sell4=false;
}
for(i=OrdersTotal()-1;i>=0;i--)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderType()==OP_BUY)
{
buy1=false;buy2=false;buy22=true;
break;
}
}
if(Add2==true && buy22 && IshRed1>MA1 && IshRed2<=MA2 && t4!=t1)
{ // Adding by Ma and Tenkan_Sen to Buy
PlaySound("Alert.wav");
int ret3=MessageBox("Add an order to Buy?",MB_YESNO|MB_ICONQUESTION);
if(ret3==6){ticket=OrderSend(Symbol(),OP_BUY,lot,Ask,slippage,Bid-SL*Point,Ask+TP*Point,NULL,0,0,Blue);if(ticket>0)PlaySound("ok.wav");if(ticket<0)Alert("Order not set!!! error - "+GetLastError()+"set manually");}
t4=Time[0];buy22=false;
}
if(Add2==true && sell22 && IshRed1<MA1 && IshRed2>=MA2 && t4!=t1)
{ // Adding by Ma and Tenkan_Sen at Sell
PlaySound("Alert.wav");
int ret4=MessageBox("Add an order to Sell?",MB_YESNO|MB_ICONQUESTION);
if(ret4==6){ticket=OrderSend(Symbol(),OP_SELL,lot,Bid,slippage,Ask-SL*Point,Bid+TP*Point,NULL,0,0,Red);if(ticket>0)PlaySound("ok.wav");if(ticket<0)Alert("Order not set!!! error - "+GetLastError()+"set manually");}
t4=Time[0];sell22=false;
}
if(buy1==true && buy2==true && t1!=t2)
{ //open initial orders
for(i=OrdersTotal()-1;i>=0;i--)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderType()==OP_SELL)OrderClose(OrderTicket(),OrderLots(),Ask,slippage,Gold);
}
PlaySound("Alert.wav");
ticket=OrderSend(Symbol(),OP_BUY,lot,Ask,slippage,Bid-SL*Point,Ask+TP*Point,NULL,0,0,Blue);
if(ticket>0)PlaySound("ok.wav");
if(ticket<0)Alert("Order not set!!! error - "+GetLastError()+"set manually");
t2=Time[0];buy1=false;buy2=false;buy4=true;
}
for(i=OrdersTotal()-1;i>=0;i--)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderType()==OP_SELL)
{
sell1=false;sell2=false;sell22=true;
break;
}
}
if(sell1==true && sell2==true && t1!=t2)
{ //open initial orders
for(i=OrdersTotal()-1;i>=0;i--)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderType()==OP_BUY)OrderClose(OrderTicket(),OrderLots(),Bid,slippage,Gold);
}
PlaySound("Alert.wav");
ticket=OrderSend(Symbol(),OP_SELL,lot,Bid,slippage,Ask+SL*Point,Bid-TP*Point,NULL,0,0,Red);
if(ticket>0)PlaySound("ok.wav");
if(ticket<0)Alert("Order not set!!! error - "+GetLastError()+"set manually");
t2=Time[0];sell1=false;sell2=false;sell4=true;buy22=false;
}
//Trailing stop
double SL,TP,openprice,profit;
int ticketOrder,zamok,type;
string comm;
for(i=OrdersTotal();i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(trailing==true && OrderProfit()/MarketInfo(Symbol(),MODE_TICKVALUE)>0 && MathFloor(OrderProfit()/MarketInfo(Symbol(),MODE_TICKVALUE)/trailingStop)!=0 && (OrderProfit()/MarketInfo(Symbol(),MODE_TICKVALUE))>=trailingStop*MathFloor(OrderProfit()/MarketInfo(Symbol(),MODE_TICKVALUE)/trailingStop))
{
if(OrderType()==0){SL=Bid-trailingStop*Point;if(SL==OrderOpenPrice())SL+=zashita*Point;}
if(OrderType()==1){SL=Ask+trailingStop*Point;if(SL==OrderOpenPrice())SL-=zashita*Point;}
TP=OrderTakeProfit();
if(OrderType()==0)if(SL>=OrderStopLoss()+trailingStop*Point)OrderModify(OrderTicket(),OrderOpenPrice(),SL,TP,0);
if(OrderType()==1)if(SL<=OrderStopLoss()-trailingStop*Point)OrderModify(OrderTicket(),OrderOpenPrice(),SL,TP,0);
}
}
return(0);
}
I won't answer all of them, but it's definitely a bug:
The last order is OrdersTotal()-1.
can you write/write a multi EA for free?
The dummy is available.
Hello, I would like to ask you for your help in prescribing T/P and Magic_Number in my EA. Regards Timofey.
Good afternoon.
how would you write a piece like this?
double a; //
double b; // both a and b can take absolutely any values: numbers, indicators readings, number of ticks for 500 candles etc.
double X; // deviation value +-X
if
(a+x and a-x) falls into the field of values (b+x and b-x)
{action}
else
{return 0}
Good afternoon.
how would you write a piece like this?
double a; //
double b; // both a and b can take absolutely any values: numbers, indicators readings, number of ticks for 500 candles etc.
double X; // deviation value +-X
if
(a+x and a-x) falls into the field of values (b+x and b-x)
{action}
else
{return 0}
If x is the same value in all cases, you are essentially comparing two numbers a and b. There's no question about getting into an interval here.
For example, take a = 10, b = 11. So you want the interval 12 to 8 to fall into the interval 13 to 9?
If x is the same in all cases, you are essentially comparing two numbers a and b. There is no question of any interval.
For example, take a = 10, b = 11. So you want the interval 12 to 8 to fall into the interval 13 to 9?
That's right.