
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
ok somewhere down here I think I have to make the logic conditions that use the indicator to filter...
// ENTRY
if(total < 2 || isNewSumbol(Symbol())) //I have modified the if condition too: it was total<1 (orBanAway aka cucurucu)
{
double HedgeLots = (HedgePercent/100)*Lots; //calculates the Lots for the hedged position
if(isCrossed == 1)
{
if(UseStopLoss)
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,comment,MAGICMA,0,Green);
else
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,comment,MAGICMA,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());
//###################################################################### the added code starts here
if(UseStopLoss)
ticket=OrderSend(Symbol(),OP_SELL,HedgeLots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,comment,MAGICMA,0,Red);
else
ticket=OrderSend(Symbol(),OP_SELL,HedgeLots,Bid,3,0,Bid-TakeProfit*Point,comment,MAGICMA,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
}
else Print("Error opening SELL order : ",GetLastError());
//###################################################################### ends here
return(0);
}
if(isCrossed == 2)
{
if(UseStopLoss)
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,comment,MAGICMA,0,Red);
else
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,comment,MAGICMA,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
}
else Print("Error opening SELL order : ",GetLastError());
//###################################################################### the added code starts here
if(UseStopLoss)
ticket=OrderSend(Symbol(),OP_BUY,HedgeLots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,comment,MAGICMA,0,Green);
else
ticket=OrderSend(Symbol(),OP_BUY,HedgeLots,Ask,3,0,Ask+TakeProfit*Point,comment,MAGICMA,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());
//###################################################################### ends here
return(0);
}
return(0);
}
return(0);
}
return(0);
}
}
//+------------------------------------------------------------------+I'm thinking to make this...
if(isCrossed == 1 && point < **the top line variable from the custom indicator**- 25)
if(isCrossed == 2 && point > **the bottom line variable from the custom indicator** +20)
would that work, would that make the indicator filter the orders?
no that's not right that doesn't separate the buys from the sells because it triggers both a sell and a buy on a buy signal and on a sell signal ...oy
but which variable from the indicator? I'm still not certain which to use?
if(isCrossed == 1 && Point < topindicatorlinevalue - longrange)
if(isCrossed == 2 && Point < bottomindicatorlinevalue + shortrange)
I have trouble getting the variable out of the indicator. I tried making a global variable to do it but that didn't work for me, I don't know why.
I put this in the top part...
//---- Filter Parameters
extern double longrange = 25;
extern double shortrange = 20;
the compiler was ok with that....
I put this in the top part too..
double t[];
double b[];
then i tried to put the t and b where the indicator would give them it's values....right with the others...
avg = findAvg(period, x);
upper[x] = middle2 + (3.5*avg);
lower[x] = middle2 - (3.5*avg);
t[x] = middle2 + (3.5*avg);
b[x] = middle2 - (3.5*avg);
the compiler was still ok with all this...
then i tried to do this where it orders buys...
if(isCrossed == 1 && Point < t - longrange)
it didn't work and I got this from the compiler...
Compiling 'EMA_CROSSmodv4.mq4'...
'-' - left square parenthesis expected for array C:\Program Files\Interbank FX Trader 4-live mini\experts\EMA_CROSSmodv4.mq4 (350, 38)
'-' - unexpected token C:\Program Files\Interbank FX Trader 4-live mini\experts\EMA_CROSSmodv4.mq4 (350, 38)
')' - assignment expected C:\Program Files\Interbank FX Trader 4-live mini\experts\EMA_CROSSmodv4.mq4 (350, 48)
3 error(s), 0 warning(s)
https://www.mql5.com/en/forum/general I like the trend bands...but which variable do I use to embed it in the EA?
If you are writing icustom in EA for trend bands indicator so you will have the following lines (see image).
So in icustom you may have the following:
where:
- NULL - EA will work for any currency (otherwise place simbol instead of NULL);
- 0 - EA will work with the chart for any timeframe you attached to (otherwise place PERIOD_M30 for example or any);
- "Trend Bands v2" - exact name of custom indicator;
- period - period in indicator. This indicator is having some settings. In our case it is one only - period. It is 34 by default. You should place the folowing in the beginning of the EA:
[CODE]extern int period = 34;Or place 34 in icustom instead of period and you do not need to place this additional line in this case (extern int period = 34;);
- 0 - it is line 0 (see image).
- 1 - is first bar. Previous bar starting from current one.
If I am wrong so somebody may correct me.
As I saw Kalenzo did it in different way.
I mean this one:
He did as following:
int limit;
int counted_bars=IndicatorCounted();
if(counted_bars<0) counted_bars=0;
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;[/CODE]
And after that:
It is for line 0.
For line 2 (blue one) it may be the following:
[CODE]double dtb_low1=iCustom(NULL,0,"Trend Bands v2",period,2,i);
double dtb_low2=iCustom(NULL,0,"Trend Bands v2",period,2,i+1);So the price should be above or below some lines (double dtb_low1, dtb_low2, double dtb_high1 and double dtb_high2). And there is middle line as well (the same but with 1). It may be double dtb_middle1 and double dtb_middle2 for example.
It was Trend Bands v2 indicator. It was custom indicator and because of that we were talking about icustom.
If you want to use standard Bollinger Bands indicator so the lines may be the following.
It is upper line:
It is middle line:
it is lower line:
21,2,0 is Period, Deviation and Shift in Bollinger Bands indicator. You may type by words (Period, Deviation, Shift) but in this case you should define the default values of Period, Deviation and Shift in the beginning of the EA.
This zero 0 but we are using closed price so it is ok.
Close price may be the following:
[CODE]double diClose1=iClose(NULL,0,1);where 1 is previous close bar (previous from current one).
Simlpe value (for above or below zero for example) may be the following:
[CODE]double d22=(0);We need simple number (value) for signal indicators. For example ASCTrend indicator is having two buffers: red and blue one. It is arrows. So we see arrow of the value of the line (arrow) is above zero, or above d22 in our case.
When you "constructing" everything and all single line in the current, previous or any bar number you need will be defined and named (as diBands3 for example) you may start to write the condition for buy and sell.
And the condition for buy or sell may be the following:
[CODE]if ((double diClose1>double diBands11 && diStochastic4>diStochastic5 ....)){
OpenBuy();
return(0);
}It was for buy order.