Coding help..How do I get indicator to filter instead of alert? - page 4

 
Aaragorn:
I boiled it down to this...but wait...

if this is just using the simple moving average of this one bar multiplied by 3.5 to find a high point. How is it possible that the point could ever reach this? isn't the line value being calculated from the same bar that would have to touch it to signal? As the bar goes up so does the edge line???

Moving average if calculated from more then 1 bar so the line can be 1 value and the price another

 
elihayun:
If u want to know if the upper line is close to the price, one way to find out is if the difference between them is small (let say 2 points).

I don't care (which is not a good idea) if the price is under the line or above the line. For me 2 points distance its all it take. so the diff is

upper - High will give u the diff but not in points (its something like 0.0004 or -0.0004) . To make sure that the diff is positive we are using the finction MathAbs that returns the absolute (positive) value . Now we have to check if it is less then 2 points. the reserved word Point will return the value when the price go up with 1 pip. It is different with every pair.

Put it all together

if (MathAbs(upper - High) < 2*Point) means if the different is less then 2 pips, and for us is close enough

Actually to use High is not good, because the High maybe above, but the current price is far away. We have to use Ask instead of High (in the indicator we have to use Close[x])

To make sure that the price is above the line we can do this

if ((Ask > upper) && (Ask - upper < 2 * Point))

.....(alert or open a trade)

[/PHP]

you are very good to answer so many of my questions I hope I'm not wearing you out I am eager to learn.

I understand the absolute value. I wonder what it would change to use the ask instead of the close? would it not be good to use the close? or would that make much difference? the only thing that still confuses me is the 2 * point side of the second condition. Would not the point be multiplied by 2? Am I interpereting the '*' symbol wrong or is that the multiplication symbol?

I see that ask-upper gives the difference between the upper line and the present ask value. but multiplying the point by 2? I'm not sure what that would result in that could be used for comparision.

could I do this to only allow buys when signal occurs below my filtered buy tolerance?

[php]

extern double longrange = 25; //--the proximity allowed to approach to the top band line before disallowing buys

extern double shortrange = 20; //--the proximity allowed to approach to the bottom band line before disallowing sells

// 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 && Ask < upper-longrange)

{

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());
 

u are missing one thing. To understand the Point stuff imagine this

in USDJPY the price is 114.95 and in EURUSD the price is 1.2773

so in USDJPY Ask - upper will be like : 114.95 - 114.93 = 0.02

and in EURUSD the price will be 1.2773 - 1.2771 = 0.0002

Both are 2 points but in different precision so in USDJPY we have to multiply 2 by 0.01 and in EURUSD we have to multiply it by 0.0001 and in every pair this is exactly what Point is equal to.

 
elihayun:
Moving average if calculated from more then 1 bar so the line can be 1 value and the price another

exactly! how can it be an average of only one bar?

//----------channel filter

int x = 0;

double middle2= iMA(NULL, 0, back, 0, MODE_SMA, PRICE_TYPICAL, x);// only used to calculate outer bands

double avg;

avg = findAvg(back, x);

double upper = middle2 + (3.5*avg);

double lower = middle2 - (3.5*avg); [/PHP]

I don't see how this works....also the compiler say, 'findAvg' - function is not defined

it's looking for the shift value x which is zero so that is only going to be the current bar right? So what is it averaging?

ok let me see what might be...if i'm telling it to go 'back' 300 periods that is what it's averaging is 300 periods. ok i get it now i think....

now about the undefined function error? what do I do about that? just get rid of it as unnecessary?

[PHP]//----------channel filter

int x = 0;

double middle2= iMA(NULL, 0, back, 0, MODE_SMA, PRICE_TYPICAL, x);// only used to calculate outer bands

double avg;

avg = (back, x);

double upper = middle2 + (3.5*avg);

double lower = middle2 - (3.5*avg);
 
elihayun:
u are missing one thing. To understand the Point stuff imagine this

in USDJPY the price is 114.95 and in EURUSD the price is 1.2773

so in USDJPY Ask - upper will be like : 114.95 - 114.93 = 0.02

and in EURUSD the price will be 1.2773 - 1.2771 = 0.0002

Both are 2 points but in different precision so in USDJPY we have to multiply 2 by 0.01 and in EURUSD we have to multiply it by 0.0001 and in every pair this is exactly what Point is equal to.

ok i see the problem...what I want to do is create a barrier based on proximity to the upper and lower lines beyond which trades won't be allowed.

-so first I get the current value of the line.

-then I add or subtract the distance I want to define as intolerable to trade in as an integer which I consider to be 1=1 pip movement.

-then I have to get the value of where the price is for each tick to make the comparision condition

so should this line be something besides 'price_Typical'

double middle2= iMA(NULL, 0, back, 0, MODE_SMA, PRICE_TYPICAL, x);// only used to calculate outer bands

i'm not sure how to keep the different precisions from causing a problem. All I want to do is compare the movement of the price relative to the movement of the line which is going to specify 'don't trade long above this level' or 'don't trade short below this level'..

I'm ready for a break my brain has turned to mush.

 

PRICE_TYPICAL have nothing to do with it. u can read about it in the MQL4 help

all u have to do to find out the diff between the price and the line is subtract one from the other. As I said, the problem is that sometimes u get 0.0006 and sometimes u get 0.06 and this the Point is solving.

(I have to close now. we can continue tomorrow)

 
elihayun:
u are missing one thing. To understand the Point stuff imagine this

in USDJPY the price is 114.95 and in EURUSD the price is 1.2773

so in USDJPY Ask - upper will be like : 114.95 - 114.93 = 0.02

and in EURUSD the price will be 1.2773 - 1.2771 = 0.0002

Both are 2 points but in different precision so in USDJPY we have to multiply 2 by 0.01 and in EURUSD we have to multiply it by 0.0001 and in every pair this is exactly what Point is equal to.

so point is like tracking pip movement in each pair regardless of the different precision required?

 
elihayun:
PRICE_TYPICAL have nothing to do with it. u can read about it in the MQL4 help

all u have to do to find out the diff between the price and the line is subtract one from the other. As I said, the problem is that sometimes u get 0.0006 and sometimes u get 0.06 and this the Point is solving.

(I have to close now. we can continue tomorrow)

thankyou so much for your patience and encouragement

 

This is what I did....

//----------channel filter

double upLevel = iCustom(NULL,TF, "Trend Bands v2", back, 0, 0);

double LowLevel = iCustom(NULL,TF, "Trend Bands v2", back, 2, 0);

// 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 && Ask < upLevel-longrange)

{

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 && Ask > LowLevel + shortrange)

{

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);

}

}

//+------------------------------------------------------------------+[/PHP]

this is what I got from the tester....

[PHP]2006.06.30 11:18:09 2006.06.06 14:00 Trend Bands v2 EURUSD,M30: Alert: EURUSD 30 reach lower edge

2006.06.30 11:18:09 2006.06.06 12:14 Trend Bands v2 EURUSD,M30: Alert: EURUSD 30 reach lower edge

2006.06.30 11:18:09 2006.06.06 10:26 Trend Bands v2 EURUSD,M30: Alert: EURUSD 30 reach lower edge

2006.06.30 11:18:09 2006.06.05 22:47 Trend Bands v2 EURUSD,M30: Alert: EURUSD 30 reach lower edge

2006.06.30 11:18:09 2006.06.05 09:00 Trend Bands v2 EURUSD,M30: Alert: EURUSD 30 reach upper edge

2006.06.30 11:18:09 2006.06.05 08:41 Trend Bands v2 EURUSD,M30: Alert: EURUSD 30 reach upper edge

2006.06.30 11:18:09 2006.06.05 07:30 Trend Bands v2 EURUSD,M30: Alert: EURUSD 30 reach upper edge

2006.06.30 11:18:09 2006.06.05 07:29 Trend Bands v2 EURUSD,M30: Alert: EURUSD 30 reach upper edge

2006.06.30 11:18:08 2006.06.02 19:55 Trend Bands v2 EURUSD,M30: Alert: EURUSD 30 reach upper edge

2006.06.30 11:18:08 2006.06.01 11:27 Trend Bands v2 EURUSD,M30: Alert: EURUSD 30 reach lower edge

2006.06.30 11:18:08 2006.06.01 06:45 Trend Bands v2 EURUSD,M30: Alert: EURUSD 30 reach lower edge

2006.06.30 11:18:08 2006.06.01 04:00 Trend Bands v2 EURUSD,M30: Alert: EURUSD 30 reach lower edge

2006.06.30 11:18:08 2006.06.01 02:44 Trend Bands v2 EURUSD,M30: Alert: EURUSD 30 reach lower edge

2006.06.30 11:18:08 2006.06.01 00:37 Trend Bands v2 EURUSD,M30: Alert: EURUSD 30 reach lower edge

2006.06.30 11:18:00 2006.05.31 04:00 Trend Bands v2 EURUSD,M30: loaded successfully

2006.06.30 11:18:00 EMA_CROSSv5 EURUSD,M5: Tester comment: ----------------------------------------

TakeProfit=10 | TrailingStop=20 | StopLoss=20 | UseStopLoss=False

----------------------------------------

immediate_trade=True | reversal=False

----------------------------------------

Lots=1 | MM=True | Risk=10%

----------------------------------------

2006.06.30 11:18:00 EMA_CROSSv5 inputs: TakeProfit=10; TrailingStop=20; StopLoss=20; ShortEma=1; LongEma=5; Lots=1; HedgePercent=1; StartHour=0; StopHour=23; Risk=10; MAGICMA=20060301; longrange=1; shortrange=1; back=30; TF=30;

2006.06.30 11:17:35 EMA_CROSSv5: loaded successfully

report shows that it got the settings but blanked....

it obviously disallows trades but ALL of them? I find that hard to believe when I only set the long and short ranges to 1 !! Surely there were SOME trade signals inside that range? I don't think this is doing what I intended.

Files:
mac5.htm  5 kb
 

I changed the trend bands indicator so it's more flexible

extern int period = 34;

extern int factor = 8;

avg = findAvg(period, x);

upper[x] = middle2 + (factor*avg);

lower[x] = middle2 - (factor*avg);[/PHP]

then i did this to the EA

//---- Trend Bands v2 and Filter Parameters

extern double back = 300; //--how many periods back for the custom indicator to average

extern double bandwidth = 6; //--how wide the trend bands are

extern double TF = 30; //--which bar period for the custom indicator to use

//----------channel filter

double upLevel = iCustom(NULL,TF, "Trend Bands v3", back, bandwidth, 0, 0);

double LowLevel = iCustom(NULL,TF, "Trend Bands v3", back, bandwidth, 2, 0);

I got this from the tester...(slightly abbreviated report)..

[PHP]2006.06.30 12:10:38 2006.06.29 23:59 Trend Bands v3 EURUSD,M30: removed

2006.06.30 12:10:38 2006.06.29 20:21 EMA_CROSSv5 EURUSD,M5: Error opening BUY order : 131

2006.06.30 12:10:38 2006.06.29 20:21 EMA_CROSSv5 EURUSD,M5: Error opening SELL order : 131

2006.06.30 12:10:38 2006.06.29 20:20 EMA_CROSSv5 EURUSD,M5: Error opening BUY order : 131

2006.06.30 12:10:38 2006.06.29 20:20 EMA_CROSSv5 EURUSD,M5: Error opening SELL order : 131

2006.06.30 12:10:38 2006.06.29 20:16 EMA_CROSSv5 EURUSD,M5: Error opening BUY order : 131

2006.06.30 12:10:38 2006.06.29 20:16 EMA_CROSSv5 EURUSD,M5: Error opening SELL order : 131

2006.06.30 12:10:38 2006.06.29 20:15 EMA_CROSSv5 EURUSD,M5: Error opening BUY order : 131

2006.06.30 12:10:38 2006.06.29 20:15 EMA_CROSSv5 EURUSD,M5: Error opening SELL order : 131

2006.06.30 12:10:38 2006.06.29 20:12 EMA_CROSSv5 EURUSD,M5: Error opening BUY order : 131

2006.06.30 12:10:38 2006.06.29 20:12 EMA_CROSSv5 EURUSD,M5: Error opening SELL order : 131

2006.06.30 12:10:38 2006.06.29 20:04 EMA_CROSSv5 EURUSD,M5: Error opening BUY order : 131

2006.06.30 12:10:38 2006.06.29 20:04 EMA_CROSSv5 EURUSD,M5: Error opening SELL order : 131

2006.06.30 12:10:38 2006.06.29 20:03 EMA_CROSSv5 EURUSD,M5: Error opening BUY order : 131

2006.06.30 12:10:38 2006.06.29 20:03 EMA_CROSSv5 EURUSD,M5: Error opening SELL order : 131

2006.06.30 12:10:38 2006.06.29 20:00 EMA_CROSSv5 EURUSD,M5: Error opening BUY order : 131

2006.06.30 12:10:38 2006.06.29 20:00 EMA_CROSSv5 EURUSD,M5: Error opening SELL order : 131

2006.06.30 12:10:38 2006.06.29 20:00 Trend Bands v3 EURUSD,M30: Alert: EURUSD 30 reach upper edge

2006.06.30 12:10:38 2006.06.29 19:59 EMA_CROSSv5 EURUSD,M5: Error opening BUY order : 131

2006.06.30 12:10:38 2006.06.29 19:59 EMA_CROSSv5 EURUSD,M5: Error opening SELL order : 131

2006.06.30 12:10:38 2006.06.29 19:32 EMA_CROSSv5 EURUSD,M5: Error opening BUY order : 131

2006.06.30 12:10:38 2006.06.29 19:32 EMA_CROSSv5 EURUSD,M5: Error opening SELL order : 131

2006.06.30 12:10:38 2006.06.29 19:25 EMA_CROSSv5 EURUSD,M5: Error opening BUY order : 131

2006.06.30 12:10:38 2006.06.29 19:25 EMA_CROSSv5 EURUSD,M5: Error opening SELL order : 131

2006.06.30 12:10:38 2006.06.29 19:21 EMA_CROSSv5 EURUSD,M5: Error opening BUY order : 131

2006.06.30 12:10:38 2006.06.29 19:21 EMA_CROSSv5 EURUSD,M5: Error opening SELL order : 131

2006.06.30 12:10:38 2006.06.29 19:20 EMA_CROSSv5 EURUSD,M5: Error opening BUY order : 131

2006.06.30 12:10:38 2006.06.29 19:20 EMA_CROSSv5 EURUSD,M5: Error opening SELL order : 131

2006.06.30 12:10:38 2006.06.29 19:09 EMA_CROSSv5 EURUSD,M5: Error opening BUY order : 131

2006.06.30 12:10:38 2006.06.29 19:09 EMA_CROSSv5 EURUSD,M5: Error opening SELL order : 131

2006.06.30 12:10:38 2006.06.29 19:08 EMA_CROSSv5 EURUSD,M5: Error opening BUY order : 131

2006.06.30 12:10:38 2006.06.29 19:08 EMA_CROSSv5 EURUSD,M5: Error opening SELL order : 131

2006.06.30 12:10:38 2006.06.29 19:06 EMA_CROSSv5 EURUSD,M5: Error opening BUY order : 131

2006.06.30 12:10:38 2006.06.29 19:06 EMA_CROSSv5 EURUSD,M5: Error opening SELL order : 131

2006.06.30 12:10:38 2006.06.29 18:35 Trend Bands v3 EURUSD,M30: Alert: EURUSD 30 reach upper edge

2006.06.30 12:10:38 2006.06.29 18:16 EMA_CROSSv5 EURUSD,M5: Error opening SELL order : 131

2006.06.30 12:10:38 2006.06.29 18:16 EMA_CROSSv5 EURUSD,M5: Error opening BUY order : 131

2006.06.30 12:10:38 2006.06.29 18:15 EMA_CROSSv5 EURUSD,M5: Error opening BUY order : 131

2006.06.30 12:10:38 2006.06.29 18:15 EMA_CROSSv5 EURUSD,M5: Error opening SELL order : 131

2006.06.30 12:10:37 2006.06.29 00:00 Trend Bands v3 EURUSD,M30: loaded successfully

2006.06.30 12:10:37 EMA_CROSSv5 EURUSD,M5: Tester comment: ----------------------------------------

TakeProfit=10 | TrailingStop=20 | StopLoss=20 | UseStopLoss=False

----------------------------------------

immediate_trade=True | reversal=False

----------------------------------------

Lots=1 | MM=True | Risk=10%

----------------------------------------

2006.06.30 12:10:37 EMA_CROSSv5 inputs: TakeProfit=10; TrailingStop=20; StopLoss=20; ShortEma=1; LongEma=5; Lots=1; HedgePercent=1; StartHour=0; StopHour=23; Risk=10; MAGICMA=20060301; back=300; bandwidth=6; TF=30;

I moved the bandwidth out to 20 after this so it never touches the bands...it's still giving me the 'error opening 131"

ERR_INVALID_TRADE_VOLUME 131 Invalid trade volume.

what's up with that?

Reason: