
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
hi everyone
does anybody have a simple piece of code that I can insert into my EA that will:
1. scan all open positions
2.determine if trade has reach predefined sl / tp
3. close trade accordingly
thanksThis is a start.. you can adjust it how you want.. you will need to look up close because glorderclose will not work for you
if(ordersTotal() !=0) // if total orders are not zero
{
total = OrdersTotal(); // the word total represents total orders
for(i = total - 1; i >= 0; i--)// count each order backwards
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES); //select each order by postiton
if(OrderSymbol() != Symbol()) continue; //if it is not equal to our symbol, skip it
if((OrderType() == OP_BUY) || (OrderType() == OP_SELL))
{
if ((OrderStopLoss()==0) && (((OrderProfit())+ 0.0003) > OrderOpenPrice()))// change this to suit your requirement.
{
if(PrintComments) Print(" closed trades!");
glOrderClose();
}
}
}
}
Hi People,
I am wanting the highest high for the last 10 days and I have been using this line.. Now I find it is not giving me the highest high. It gives me yesterdays close for some reason.
double HighTrendVal= High;
Print ("High Trend Value is",(HighTrendVal));
[/code]thanksOK, this is an answer that works. I am posting my own answer in case someone else spends a day trying to find out.
[code]
double HighTrendVal= iHigh(NULL, 1440, iHighest(NULL, 1440, MODE_HIGH, 10, 1));
This is a start.. you can adjust it how you want.. you will need to look up close because glorderclose will not work for you
[code ]
if(ordersTotal() !=0) // if total orders are not zero
{
total = OrdersTotal(); // the word total represents total orders
for(i = total - 1; i >= 0; i--)// count each order backwards
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES); //select each order by postiton
if(OrderSymbol() != Symbol()) continue; //if it is not equal to our symbol, skip it
if((OrderType() == OP_BUY) || (OrderType() == OP_SELL))
{
if ((OrderStopLoss()==0) && (((OrderProfit())+ 0.0003) > OrderOpenPrice()))// change this to suit your requirement.
{
if(PrintComments) Print(" closed trades!");
glOrderClose();
}
}
}
}
[/code]thank you , its a start I can work with.
Hi,
how can use in EA non-default indicators. If i wanna use MACD I can use function iMACD, but what if I want to use Gann HI-LO, Center of Gravity or stuff like that. I dont know how to import this to the EA
Can u help me please?
Thank you!
search in the metaeditor help file for icustom function. That's the one you need
Good luck
Lux
You can use iCustom function to fetch values from custom indicators, by passing the indicator parameters in the order how they are specified in the indicator file.
Hi,
how can use in EA non-default indicators. If i wanna use MACD I can use function iMACD, but what if I want to use Gann HI-LO, Center of Gravity or stuff like that. I dont know how to import this to the EA
Can u help me please?
Thank you!problem with drawing MA indicators
Hello
I have a problem with next code
This code must draw two moving averages ,but unfortunately nothing is done
any help will be appreciated
Thanks David.
#property indicator_chart_window // Indicator is drawn in the main window
#property indicator_buffers 2 // Number of buffers
#property indicator_color1 Blue // Color of the 1st line
#property indicator_color2 Red // Color of the 2nd line
extern int Aver5=5; // number of bars for calculation
extern int Aver8=8; // number of bars for calculation
extern int fma=0; //first moving average
extern int sma=1; //second moving average
double Buf_5[],Buf_8[]; // Declaring indicator arrays
//--------------------------------------------------------------------
int init() // Special function init()
{
//--------------------------------------------------------------------
SetIndexBuffer(fma,Buf_5); // Assigning an array to a buffer
SetIndexStyle (fma,DRAW_LINE,STYLE_SOLID,2);// Line style
SetIndexShift(fma,0);
//--------------------------------------------------------------------
SetIndexBuffer(sma,Buf_8); // Assigning an array to a buffer
SetIndexStyle (sma,DRAW_LINE,STYLE_SOLID,1);// Line style
SetIndexShift(sma,0);
//--------------------------------------------------------------------
return;
}
//--------------------------------------------------------------------
int start()
{
ma5(Aver5,Buf_5);
ma5(Aver8,Buf_8);
return;
}
//--------------------------------------------------------------------
void ma5(int& average,double& buffer[])
{
int n,i;
int Counted_bars;
int Sum;
Counted_bars=IndicatorCounted(); // Number of counted bars
i=Bars-Counted_bars-1; // Index of the first uncounted
while(i>=0) // Loop for uncounted bars
{
Sum=0; // Nulling at loop beginning
for(n=i;n<=i+average-1;n++) // Loop of summing values
{
Sum=Sum + Close[n]; // Accumulating maximal values sum
}
buffer=Sum/average; // Value of buffer on i bar
i--; // Calculating index of the next bar
}
}
...
Change int Sum; to double Sum;
regards
mladen
Hello
I have a problem with next code
This code must draw two moving averages ,but unfortunately nothing is done
any help will be appreciated
Thanks David.
#property indicator_chart_window // Indicator is drawn in the main window
#property indicator_buffers 2 // Number of buffers
#property indicator_color1 Blue // Color of the 1st line
#property indicator_color2 Red // Color of the 2nd line
extern int Aver5=5; // number of bars for calculation
extern int Aver8=8; // number of bars for calculation
extern int fma=0; //first moving average
extern int sma=1; //second moving average
double Buf_5[],Buf_8[]; // Declaring indicator arrays
//--------------------------------------------------------------------
int init() // Special function init()
{
//--------------------------------------------------------------------
SetIndexBuffer(fma,Buf_5); // Assigning an array to a buffer
SetIndexStyle (fma,DRAW_LINE,STYLE_SOLID,2);// Line style
SetIndexShift(fma,0);
//--------------------------------------------------------------------
SetIndexBuffer(sma,Buf_8); // Assigning an array to a buffer
SetIndexStyle (sma,DRAW_LINE,STYLE_SOLID,1);// Line style
SetIndexShift(sma,0);
//--------------------------------------------------------------------
return;
}
//--------------------------------------------------------------------
int start()
{
ma5(Aver5,Buf_5);
ma5(Aver8,Buf_8);
return;
}
//--------------------------------------------------------------------
void ma5(int& average,double& buffer[])
{
int n,i;
int Counted_bars;
int Sum;
Counted_bars=IndicatorCounted(); // Number of counted bars
i=Bars-Counted_bars-1; // Index of the first uncounted
while(i>=0) // Loop for uncounted bars
{
Sum=0; // Nulling at loop beginning
for(n=i;n<=i+average-1;n++) // Loop of summing values
{
Sum=Sum + Close[n]; // Accumulating maximal values sum
}
buffer=Sum/average; // Value of buffer on i bar
i--; // Calculating index of the next bar
}
}problem with drawing MA indicators Reply to Thread
thank you very much