Download MetaTrader 5
To add comments, please log in or register
Do you need private account monitoring? The Signals will provide you one!
Floater
54
Floater 2014.11.11 17:54 

Hi

would appreciate your help and feedback

I wrote the following EA and it's a very simple strategy, but it doesn't when apply to the a chart and there fore when I do back testing it doesn't open or close any trades

Thanks 

 

#define MAGICMA  20131111

//+------------------------------------------------------------------+
//| External Parameter                                                               |
//+------------------------------------------------------------------+
input  string MarketSymbol="UK100";
input  int TimeFrame=1; 
input  double PoundPerPoint=1;
input  double StopLoss=8;
input  double Limit=15;
input  double Slippage=3;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
void OnTick(void)
{
   int TicketNo;
   ChartSetSymbolPeriod(0,MarketSymbol,TimeFrame);
   int SMA5,SMA34,CurrentDirection,TotalOrdersOpened=0;
   TotalOrdersOpened=OrdersTotal();
   
   SMA5=iMA(MarketSymbol,TimeFrame,5,0,MODE_SMMA,PRICE_CLOSE,0);
   SMA34=iMA(MarketSymbol,TimeFrame,34,0,MODE_SMMA,PRICE_CLOSE,0);
   if(SMA5>SMA34)
   {        
         Print("sma(5): "+IntegerToString(SMA5)+"         sma(34): "+IntegerToString(SMA34)+ "    (Time Frame "+IntegerToString(TimeFrame)+") ***** UP Trend ****");
         if (Ask<=SMA34) 
         {
                  if (TotalOrdersOpened==0)        // Check if there are any open orders
                  {
                        TicketNo=0;   
                        TicketNo=OrderSend(MarketSymbol,OP_BUY,PoundPerPoint,Ask,Slippage,Ask-Point*StopLoss,Ask+Point*Limit,"",MAGICMA,0,Green);
                        if(TicketNo<0){Print("Failed to open a long trade  because of '"+GetLastError()+"'");}
                        if(TicketNo>0){Print("Long Order opened @"+ IntegerToString(Ask));}
                  }
         }
   }
   if(SMA5<SMA34)
   {        
         Print("sma(5): "+IntegerToString(SMA5)+"         sma(34): "+IntegerToString(SMA34)+ "    (Time Frame "+IntegerToString(TimeFrame)+") ***** DOWN Trend ****");
         if (Bid>=SMA34) 
         {
                  if (TotalOrdersOpened==0)        // Check if there are any open orders
                  {
                        TicketNo=0;   
                        TicketNo=OrderSend(MarketSymbol,OP_SELL,PoundPerPoint,Bid,Slippage,Bid+Point*StopLoss,Bid-Point*Limit,"",MAGICMA,0,Red);
                        if(TicketNo<0){Print("Failed to open a short trade  because of '"+GetLastError()+"'");}
                        if(TicketNo>0){Print("Short Order opened @"+ IntegerToString(Bid));}
                  }
         }
   }
}
Carl Schreiber
5962
Carl Schreiber 2014.11.11 20:15  

Why don't you take the sample EA "Moving Average.mq4" from your expert folder and change this acc. to you needs?

whroeder1
13644
whroeder1 2014.11.11 22:40  
floater: but it doesn't when apply to the a chart and there fore when I do back testing it doesn't open or close any trades
   int SMA5,SMA34,CurrentDirection,TotalOrdersOpened=0;
   TotalOrdersOpened=OrdersTotal();
   
   SMA5=iMA(MarketSymbol,TimeFrame,5,0,MODE_SMMA,PRICE_CLOSE,0);
   SMA34=iMA(MarketSymbol,TimeFrame,34,0,MODE_SMMA,PRICE_CLOSE,0);
  if(SMA5>SMA34) 
  1. In the current bar, how high, must the market move before the sma's differ by at least 1.0000?
  2. Don't use the SMMA The Smoothed Moving Average or SMMA - How to Avoid It - NinjaTrader Programming | Big Mike Trading SMMA(x) == EMA(2x-1) Use EMA and you have twice the resolution and more efficiencies.


Floater
54
Floater 2014.11.12 12:06  
WHRoeder:
  1. In the current bar, how high, must the market move before the sma's differ by at least 1.0000?
  2. Don't use the SMMA The Smoothed Moving Average or SMMA - How to Avoid It - NinjaTrader Programming | Big Mike Trading SMMA(x) == EMA(2x-1) Use EMA and you have twice the resolution and more efficiencies.


much appreciate your feedback. what you've mentioned makes perfect sense.

I'm quite new to this. what I'm trying to do is  its a strategy I do manually. I’d like to automate it and do back tests though.

On 10 minute chart, use 5 and 34 Simple Moving averages. If the 5sma crosses above the 34, go long when the price touches the 34sma after the cross and you are not already in a  trade (so only enter on the first touch of the 34SMA).

Vice versa for short, if 5sma crosses below the 34sma, go short on the first price touch of the 34sma after the cross, if you are not already in a trade.  

 

would appreciate your help 

Floater
54
Floater 2014.11.12 12:14  
WHRoeder:
  1. In the current bar, how high, must the market move before the sma's differ by at least 1.0000?
  2. Don't use the SMMA The Smoothed Moving Average or SMMA - How to Avoid It - NinjaTrader Programming | Big Mike Trading SMMA(x) == EMA(2x-1) Use EMA and you have twice the resolution and more efficiencies.


Also I was under impression that iMA(MarketSymbol,TimeFrame,5,0,MODE_SMMA,PRICE_CLOSE,0); will give me the current SMA on 10 minute chart as TimeFrame=10, regardless of the open/close price of that last candle.

Am I wrong? 

Carl Schreiber
5962
Carl Schreiber 2014.11.12 12:59  

Traditionally mt4 only supports M1, M5, M15, M30, ...

In the Reference they now write that more TimeFrames seems to exists and you might get some values. But at least you can't open any chart with these new TimeFrames.

Gabor Keresztessy
201
Gabor Keresztessy 2014.11.16 12:30  

Hi floater!


I think there is a misunderstanding in the condition. I have put the MA 5 and 34 with SMMA,close settings on the eurusd chart

 if(SMA5>SMA34)
   {        
         Print("sma(5): "+IntegerToString(SMA5)+"         sma(34): "+IntegerToString(SMA34)+ "    (Time Frame "+IntegerToString(TimeFrame)+") ***** UP Trend ****");
         if (Ask<=SMA34) 

And I see misunderstanding in the 2 if conditions. If sma5>sma34 then the price is always higher than sma34. If yes it is higher, than your 2nd if condition never meets. Positions will not open. And vica versa.

Please check it one more times.

Cheers

Agent86
915
Agent86 2014.11.16 14:44  
pecskeke1976:

Hi floater!


I think there is a misunderstanding in the condition. I have put the MA 5 and 34 with SMMA,close settings on the eurusd chart. 

And I see misunderstanding in the 2 if conditions. If sma5>sma34 then the price is always higher than sma34. If yes it is higher, than your 2nd if condition never meets. Positions will not open. And vica versa.

Please check it one more times.

Cheers

Seems like he wants it that way. So if the SMA's cross up && price < 34 then trade, and if SMA's cross down && price > 34 then trade
If indeed he wants this, I can see how very limited number of trades would occur if any.

Not sure the OP wants this or not. Perhaps he wanted 5 crosses above 34 && ask also > 34/above then trade. ? and vice versa
/
To add comments, please log in or register