what's wrong with my EA?

 

Dear Gurus

I need some help here. I was trying to write an EA where it requires the recording of the Signal value (or in general any data, for example the bid and offer prices) at the moment of MACD crossover. The recorded reading will be used for comparison as the condition to trigger trades (I want to open trades only if the Signal value is below certain predefined value, for example 0.001). However, my approach does not work. It appeared as if the values are recorded successfully but the recorded value does not seem to take effect at all. I am attaching the scripts here.

int start()
{
double MacdPrevious,MacdPPrevious,MacdPPPrevious,SignalPrevious,SignalPPrevious,SignalPPPrevious,SignalCheck1;

MacdPrevious=iMACD(NULL,PERIOD_M15,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
MacdPPrevious=iMACD(NULL,PERIOD_M15,12,26,9,PRICE_CLOSE,MODE_MAIN,2);
MacdPPPrevious=iMACD(NULL,PERIOD_M15,12,26,9,PRICE_CLOSE,MODE_MAIN,3);
SignalPrevious=iMACD(NULL,PERIOD_M15,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);
SignalPPrevious=iMACD(NULL,PERIOD_M15,12,26,9,PRICE_CLOSE,MODE_SIGNAL,2);
SignalPPPrevious=iMACD(NULL,PERIOD_M15,12,26,9,PRICE_CLOSE,MODE_SIGNAL,3);

if((MacdPrevious-SignalPrevious)*(MacdPPrevious-SignalPPrevious)<0)
{
SignalCheck1=SignalPrevious;
Alert("Cross over happened and SignalCheck is updated, value is ",SignalCheck1);
}

if(total<1)
{
if(MacdPrevious>SignalPrevious && 0.001>MathAbs(SignalCheck1))
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,ask,3,0,0,"GOOD luck ",760618,0,Green); //NormalizeDouble(ask-StopLoss*point,digits)
if(ticket<0)
{RefreshRates();}
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
Print("Buy order opened : ",OrderOpenPrice());
}

else Print("Error opening BUY order : ",GetLastError());
return(0);
}

The problem here is the control condition: 0.001>MathAbs(SignalCheck1) does not seem to take effect at all. No matter 0.001 or 0.002 or 0.003, it opens similar number of trades. But strangely enough, when I make the value 0, no trades were opened. Anyone can point out the mistake I made here?

Another thing is, since during the current bar (MacdPrevious-SignalPrevious)*(MacdPPrevious-SignalPPrevious)<0) is the condition that can be always true, such that it repeatedly updates the value of SignalPrevious into SingalCheck1, and creates a lot of alerts. I want to stop it from repeated alerting, then I modified the script into

if(SignalCheck1!=SignalPrevious)
{if((MacdPrevious-SignalPrevious)*(MacdPPrevious-SignalPPrevious)<0)
{
SignalCheck1=SignalPrevious;
Alert("Cross over happened and SignalCheck is updated, value is ",SignalCheck1);
}
}

I assume it will then update only once, since the rest of condition will be blocked by SignalCheck1!=SignalPrevious fuction. But it does not work. within a defined time frame, it still generates a lot alerts. Can someone help me on this also? How the scripts shall be written in this case?

Thank you so much!

yours

John

 
wang:

..

if(MacdPrevious>SignalPrevious && 0.001>MathAbs(SignalCheck1))

...

The problem here is the control condition: 0.001>MathAbs(SignalCheck1) does not seem to take effect at all. No matter 0.001 or 0.002 or 0.003, it opens similar number of trades. But strangely enough, when I make the value 0, no trades were opened. Anyone can point out the mistake I made here?


0.001>MathAbs(SignalCheck1)

is only true when SignalCheck1 has a 'very small' value, and

0>MathAbs(SignalCheck1)

is NEVER true

 
brewmanz:

is only true when SignalCheck1 has a 'very small' value, and

is NEVER true


Dear brewmanz

Thank you for your input!

However, the issue here is not 0.001 is small or big. I use it for filtering. If 0.001 is very small, it should be able to restrict the order opening effectively, but it doesn't. I compared 0.001 and 1, the EA opens the same number of trades. I used 0.0001, it it the same ... Only 0 makes difference.

I don't know why it is the case ...

yours

John

Reason: