Indicator Question Statement

 

If I want an indicator MA crossover where the sell signal is generated 5 pips after the crossover takes place, how do I state this in the logic statement that your program will accept. If MA(1) previous crosses MA(2) current - 5 pips then sell. Can you create 2 statements such as Statement 1) And MA(1) current < MA(2) previous. Statement 2) AND MA(1) current <=MA(2) previous -.0005??

Please help me on this basic question. This program is an answer to my prayers! I hope you can help me on this question.

Sincerely,

Dave Diebold

ddiebold@sbcglobal.net

713-977-1892

 

In beta 1, there is no automatic way to do this; however, you'll need to get your hands dirty a bit for the same funcationality.

1. Leave the crossover logics intact without caring about the "5 pips thing". (Just add the crossover logics)

2. Open or Modify the expert in MetaEditor.

3. Find:


// Check for BUY, SELL, and CLOSE signal
IsBuying = .... ;
IsSelling = .... ;
IsClosing = ... ;

4. Add following lines BEFORE above code block


// Note the bid price at crossover point
defines: FilterPips(0.0005);
var: CrossBid(0),IsBuyingBak(False),IsSellingBak(False);

5. Add following lines BELOW

// Check price filter

if (IsBuying and not IsBuyingBak) or (IsSelling and Not IsSellingBak ) then {
CrossBid = pricebid ;
}
IsBuyingBak = IsBuying;
IsSellingBak = IsSelling;
IsBuying = IsBuying and (PriceBid >= CrossBid + FilterPips);
IsSelling = IsSelling and (PriceBid <= CrossBid - FilterPips);

6. Finally you'll have similar to below:



// Note the bid price at crossover point
defines: FilterPips(0.0005);
var: CrossBid(0),IsBuyingBak(False),IsSellingBak(False);

// Check for BUY, SELL, and CLOSE signal
IsBuying = ....... ;
IsSelling = ....... ;
IsClosing = ...... ;

// Check price filter
if (IsBuying and not IsBuyingBak) or (IsSelling and Not IsSellingBak ) then {
CrossBid = pricebid ;
}
IsBuyingBak = IsBuying;
IsSellingBak = IsSelling;
IsBuying = IsBuying and (PriceBid >= CrossBid + FilterPips);
IsSelling = IsSelling and (PriceBid <= CrossBid - FilterPips);

 

In case you don't know how to setup crossover properly, you should watch the Video Walkthrough: Create a simple MACD Cross expert.

 

Scorpion,

Can this pip filter hack be modified for time? Example: if cross stays true for "x" amount of time (ticks) then signal is true. Might work better for some purposes.

thanks

 

No, it's a total difference, and might require more coding. If only I had had more time on this.

 

Scorp,

is there a simple way to add a time function to a ma a cross? i had tried many variations on the code below, but i can not get it to work. seems like it should not be that hard. any ideas?

// Check for BUY, SELL, and CLOSE signal

IsBuying = (ma2_0 > ma3_0 >= (15)Minute);

IsSelling = (ma2_0 = (15)Minute);

the logic i am trying to code is to buy if ma 2 is greater than ma3 for 15 minutes or more.

 

Scorpion I phrased my program wrong. What I need is a crossover condition where a crossover takes place and then the ma averages (gap) grows apart from each other .0005 pips (Variable) (difference between one moving (2 Exp MA average) and the other (30 LWMA) within the last 3 (Variable) candles before a buy or sell signal takes place.

The program is not working right with a cross over + .0005 pips filter. I need the Moving average gap variable filter to signal a buy or sell.

This should solve one of my biggest problems I am having so far. Could I ask that you rephrase that part of my program.

I wish there was a school on coding this stuff. I asked you a question before on the phrasing to check to see if current price is lower (or higher) than the lowest low during 10 previous candles.

Your answer was:

PriceBidHighest(Mode_high,10,10)

Is this to be placed after: IsBuying=(ma2_1) etc. etc. and (ma2_0) etc. etc., Likewise IsSelling= . . . . . in my program??

I have attached the MQL File. Thanks Scorpion. You do not realize how frustrating it is not to be able to figure this programming stuff out on my own. Have you thought about writing a book on MQL for traders, by example?? If I get this program working right in the near future, tell me what you like to drink, and I will send you a bottle of it!!

 
Dave77:
Scorpion I phrased my program wrong. What I need is a crossover condition where a crossover takes place and then the ma averages (gap) grows apart from each other .0005 pips (Variable) (difference between one moving (2 Exp MA average) and the other (30 LWMA) within the last 3 (Variable) candles before a buy or sell signal takes place.

That's much simpler then; no need to do pips filter hack. Assume MA (1) is 2-period EMA, and MA (2) is 30-period LWMA. Enter below logics into ZeroCode:

Buy logics:

MA (1) Previous < MA (2) Previous + 0.0005

AND MA (1) Current > MA (2) Current + 0.0005

Sell logics:

MA (1) Previous > MA (2) Previous - 0.0005

AND MA (1) Current < MA (2) Current - 0.0005

Dave77:
Your answer was: PriceBidHighest(Mode_high,10,10) Is this to be placed after: IsBuying=(ma2_1) etc. etc. and (ma2_0) etc. etc., Likewise IsSelling= . . . . . in my program??
You can add that in ZeroCode as logics. No need to hack in the mql.

 

Thank you kindly! Now I have got to backtest and trouble shoot the unique conditions that it does not cover. Step one in the right direction has been accomplished thanks to you and your compiler. Thanks Again!

 
rondio:
Scorp, is there a simple way to add a time function to a ma a cross? i had tried many variations on the code below, but i can not get it to work. seems like it should not be that hard. any ideas? // Check for BUY, SELL, and CLOSE signal IsBuying = (ma2_0 > ma3_0 >= (15)Minute); IsSelling = (ma2_0 = (15)Minute); the logic i am trying to code is to buy if ma 2 is greater than ma3 for 15 minutes or more.

anybody know any resources on the net i can use to solve this problem? i believe i could have a very powerful system if i could get this to work. i have not been able to find anything simular. if anybody could help i would appreciate it.

thanks

 
rondio:
Scorp, is there a simple way to add a time function to a ma a cross? i had tried many variations on the code below, but i can not get it to work. seems like it should not be that hard. any ideas? // Check for BUY, SELL, and CLOSE signal IsBuying = (ma2_0 > ma3_0 >= (15)Minute); IsSelling = (ma2_0 = (15)Minute); the logic i am trying to code is to buy if ma 2 is greater than ma3 for 15 minutes or more.

You could do something like this in MT4. I don't know exactly how to code it, but you should be able to use the TimeSeconds(CurTime()) function to set maXtime = TimeSeconds(CurTime()) at the time of the cross, then keep checking to see if TimeSeconds(CurTime()) - maXtime >= 900 seconds.

Keris

Hope this helps. Sorry I can't give you the code exactly, but hopefully one of the coders here can use what I've posted.

Reason: