Beginner's coding issue

 

Hi,

Have been working at this for a while but I cant get my EA to work. It is based on a simple MA cross within a extern defined range. Unfortunately there is no trade being made and I cant work out why;

I dont beleive it is the actual trading mechanism as this has worked consistently up till now (not Any help most appreciated.


double GTop = NormalizeDouble (GoldenTop, 6);
double GBottom = NormalizeDouble (GoldenBottom, 6);
double FastMA = iMA(NULL,0,3,0,MODE_SMA, PRICE_CLOSE, 0);
double SlowMA = iMA (NULL,0,5,0,MODE_SMA, PRICE_CLOSE, 0);
//+----------------------------+
//| Buy Signal |
//+----------------------------+
if (!openOrder && (TradeCount == 0) && (Close[1] < GTop) && (Close[1] > GBottom) && (FastMA > SlowMA)) {
buySignal = 1;
TradeCount = 1;

}
else {
//+----------------------------+
//| close BUY order |
//+----------------------------+

if (openOrder && (buySignal == 1) && (FastMA == 1)) {
closeOrder = true;
}


}


//+----------------------------+
//| Sell Signal |
//+----------------------------+
if (!openOrder && (TradeCount == 0) && (Close[1] < GTop) && (Close[1] > GBottom) && (FastMA < SlowMA)) {
sellSignal = 1;
TradeCount = 1;
}
else {
//+----------------------------+
//| close SELL order |
//+----------------------------+

if (openOrder && (sellSignal == 1) && (FastMA == 100)) {
closeOrder = true;
}
}

 

Please use the SRC button to post your code . . or attach a file.

To place a trade it's usual to use an OrderSend . . I don't see one in your code . . . should I just assume it is correct ? should I assume that you gather it's return code correctly, analyse it and report the error to somewhere that you can see it ?

 
RaptorUK:

Please use the SRC button to post your code . . or attach a file.

To place a trade it's usual to use an OrderSend . . I don't see one in your code . . . should I just assume it is correct ? should I assume that you gather it's return code correctly, analyse it and report the error to somewhere that you can see it ?

It is there, the engine for sending orders, trailing sl and so on I have been using for a long time. I have tested this with the above code taking out the (Close[1] < GTop) && (Close[1] > GBottom) and it works so it is not the MA Cross or the OrderSend that is the problem. It must be setting the actual range.


Can you help me with how you would go about setting a range. What I have done is;

1. Coded an Extern Double which I then put in the price range (eg 1.31 - 1.32)

2. Use the above code to 'Normalise' that number and get GTop/GBottom parameters which I then use in the trigger.

For some reason this does not seem to work in backtesting.

Thanks for any help.

 
  1. Is is never necessary to use NormalizeDouble, ever. Don't use it, forget it. Don't compare doubles for equality
  2. Add Print statements so you find out why
  3. What is openorder and TradeCount and do you reset them - post ALL the code - no mind readers here.
Reason: