Buy and sell-signal not on correct places - page 2

 

"But it gives the same results".

it was your coding etiquette that was changed, not the code itself.

 
brewmanz:

Super-Amazing-Thunder-Profit


You forgot to add Turbo or Mega 8) in front of that. Mega-Super-Amazing-Thunder-Profit-Turbo. Ah, thats the money maker. I'll even help you make the website with the Movie Opening Big-Bang reasons why it works.

 

It is reasonable to expect a simple MA cross-over strategy to lose money, especially when you are using two fast moving averages.

Try something like a 144 period MA, and watch for it to be crossed by 21 period MA.


Oh and I have to agree with brewmanz, that is some awful looking code. An MA cross-over strategy can be written in half as much code. And storing boolean values in doubles is asking for bugs.

Look to use the MA cross-overs as a setup to go long or short depending on the direction of the cross. Then use an oscillator like William's %R or Stochastics as a signal to open your trade. This is something that can be tuned to be profitable using the optimizer over a short interval (let's say 3 months of 15M bars). It is not something that will yield long term profitability, however. Learning to code an EA like the one I've suggested is an outstanding way to learn to code your own EAs, and the optimization process is a great way to develop a feel for price movement. Don't expect immediate profitability or you'll get nothing but disappointment. Love the learning curve instead. ;)

 
ubzen:


You forgot to add Turbo or Mega 8) in front of that. Mega-Super-Amazing-Thunder-Profit-Turbo. Ah, thats the money maker. I'll even help you make the website with the Movie Opening Big-Bang reasons why it works.

Doh! Why didn't I think of that?

Anyway, I don't need to now. I've just got an email telling me I've inherited 4.5 million US dollars from someone who was killed in an aircrash (they gave a link to the BBC website about the crash so it must be true)

All I have to do is pay the lawyer fees by handing over $1,000 in used bank notes in a brown paper bag to the president's prime ministerial assistant financial legal advisor of the Egalitarian West Central People's Democratic Freedom Republic of East Africa in Asia of South America. As his office is being redecorated, I'm to meet him behind the warehouses down by the waterfront.

 
Anomalous:

It is reasonable to expect a simple MA cross-over strategy to lose money, especially when you are using two fast moving averages.

Try something like a 144 period MA, and watch for it to be crossed by 21 period MA.


Oh and I have to agree with brewmanz, that is some awful looking code. An MA cross-over strategy can be written in half as much code. And storing boolean values in doubles is asking for bugs.

Look to use the MA cross-overs as a setup to go long or short depending on the direction of the cross. Then use an oscillator like William's %R or Stochastics as a signal to open your trade. This is something that can be tuned to be profitable using the optimizer over a short interval (let's say 3 months of 15M bars). It is not something that will yield long term profitability, however. Learning to code an EA like the one I've suggested is an outstanding way to learn to code your own EAs, and the optimization process is a great way to develop a feel for price movement. Don't expect immediate profitability or you'll get nothing but disappointment. Love the learning curve instead. ;)

It was the code generated by EA Builder http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/index.html. Since I cannot coding I must use this EA Builder. I do agree that it is to much code.


When I backtested it in Excel I got much more profit than losses so there must be something wrong whit this EA. When I change 0 for current to 1 and 1 for previous to 2 I got mor profit but it still is more losses.


Thanks for the tips of using a 144 period and a 21 periods MA. I will try it. I will look for using Williams% or Stochastic.

 

It was the code generated by EA Builder http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/index.html. Since I cannot coding I must use this EA Builder. I do agree that it is to much code.

When I backtested it in Excel I got much more profit than losses so there must be something wrong whit this EA. When I change 0 for current to 1 and 1 for previous to 2 I got mor profit but it still is more losses.

Thanks for the tips of using a 144 period and a 21 periods MA. I will try it. I will look for using Williams% or Stochastic.


How are you interpreting MA cross-overs in Excel? The EA Builder code is only responding to crosses where the fast MA has moved in the direction of the trade on the previous bar. How many trades are happening in your Excel back testing vs the number of trades you see this EA making?
 
lhw1234:
Sorry I didn´know how to do it.
  1.  if (EachTickMode && Bars != BarCount) TickCheck = False;
    
    Bars is unreliable, Once you reach max bars in chart it won't change. Always use time
  2. for (int i = 0; i < Total; i ++) {
          OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
          if(OrderType() <= OP_SELL &&  OrderSymbol() == Symbol()) {
             IsTrade = True;
             if(OrderType() == OP_BUY) {
                //Close
    
    You must count down in the presence of multiple orders (multiple charts) when closing/deleting/modifying. Always test return code. No magic number means the EA in incompatible with any other EA or manual trading.
        for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
            OrderSelect(pos, SELECT_BY_POS)                 // Only my orders w/
        &&  OrderMagicNumber()  == magic.number             // my magic number
        &&  OrderSymbol()       == Symbol() ){              // and my pair.
    

  3. OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop
    EA's must adjust TP, SL, AND SLIPPAGE for 5 digit brokers.
    //++++ These are adjusted for 5 digit brokers.
    double  pips2points,    // slippage  3 pips    3=points    30=points
            pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
    int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
    int     init(){
        if (Digits == 5 || Digits == 3){    // Adjust for five (5) digit brokers.
                    pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
        } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
        // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
    
    On ECN brokers, you must orderSend and THEN set the TP/SL.
 
Anomalous:
How are you interpreting MA cross-overs in Excel? The EA Builder code is only responding to crosses where the fast MA has moved in the direction of the trade on the previous bar. How many trades are happening in your Excel back testing vs the number of trades you see this EA making?


I had the formula for the MA :s in two column s and see where they cross each other. The buy and sellsignals are not were they are in MetaTrader. So something is very wrong with what I have done in EA Builder


How should the code be if it shall be a buysignal and an opening of a buyposition when the shorter MA cross the longer MA upwards and the close the position when the shirter MA cross the longer MA downwards?

 
Anomalous:
How are you interpreting MA cross-overs in Excel? The EA Builder code is only responding to crosses where the fast MA has moved in the direction of the trade on the previous bar. How many trades are happening in your Excel back testing vs the number of trades you see this EA making?


I had the formula for the MA :s in two column s and see where they cross each other. The buy and sellsignals are not were they are in MetaTrader. So something is very wrong with what I have done in EA Builder


How should the code be if it shall be a buysignal and an opening of a buyposition when the shorter MA cross the longer MA upwards and the close the position when the shirter MA cross the longer MA downwards?

 
lhw1234:
How should the code be if it shall be a buysignal and an opening of a buyposition when the shorter MA cross the longer MA upwards and the close the position when the shirter MA cross the longer MA downwards?
double myMA6_1 = iMA(NULL, 0, 6, 0, MODE_LWMA, PRICE_WEIGHTED, Current + 1);
double myMA9_1 = iMA(NULL, 0, 9, 0, MODE_LWMA, PRICE_WEIGHTED, Current + 1);
double myMA6_0 = iMA(NULL, 0, 6, 0, MODE_LWMA, PRICE_WEIGHTED, Current + 0);
double myMA9_0 = iMA(NULL, 0, 9, 0, MODE_LWMA, PRICE_WEIGHTED, Current + 0);
bool cross = (myMA6_1-myMA9_1) * (myMA6_0-myMA9_0) <= 0,
     buy   = myMA6_0 > myMA9_0;
if (cross){
   if (buy) { 
      // Close any opoen sells
      // Open buy if none 
   }
   else     { 
      // Close any open buys
      // Open sell if none.
}
Reason: