newbie questions...

 

Hello everyone


i am new to MQL so i have a few questions.


how to deal with negative values of some indicators, how to compare them. its so confusing...

could you please tell me what structure (algorithm) for opening and closing i have to use.

i'd tryed to write an absolutly simple strategy with ma15, ma15(shfl 5) and rsi12 but it doesnt work. here is the code. there are no syntaxys errors, only logic errors. could pls somebody fix them. here is the code


#property copyright "......"
#property link      ""
 
int order = 0;
int timeframe = PERIOD_M15;
double vol = 0.1;
string symbol;
string type = "";
 
double ma;     // -- moving avg
double mash;   // -- moving avg shuffled
double rsi;    // -- RSI
 
int init()     // initializing
  {
   symbol = Symbol();
   
   ma = iMA(symbol, timeframe, 15, 0, MODE_SMA, PRICE_CLOSE, 0);
   mash = iMA(symbol, timeframe, 15, 5, MODE_SMA, PRICE_CLOSE, 5);
   rsi = iRSI(symbol, timeframe, 12, PRICE_CLOSE, 0);
   
   return(0);
  }
 
void closeshort()       //    Close SHORT positions
{
   OrderClose(order, vol, Ask, 3, Red);
   order = 0;
   type = "";
}
 
void closelong()        //    Close LONG positions
{
   OrderClose(order, vol, Bid, 3, Green);
   order = 0;
   type = "";
}
 
int start()
  {
 
   init();
   
   Print(ma);
   Print(mash);
   Print(rsi);
 
   if(order == 0)
   {
      if(ma < mash)        // Check for SHORT position
      {
         if(rsi < 49)
         {
            order = OrderSend(symbol, OP_SELL, vol, Bid, 3, Ask+30*Point, 0, "", NULL, 0, Red);
            type = "short";
         }
      }
 
 
      if(ma > mash)       // Check for LONG position
      {
         if(rsi > 53)
         {
            order = OrderSend(symbol, OP_BUY, vol, Ask, 3, Bid-30*Point, 0, "", NULL, 0, Green);
            type = "long";
         }
      }
 
   }
   
   if(order != 0)          // Check for CLOSE
   {
      if(type == "short")     // Check for close SHORT
      {
         if(ma > mash)
         {
            closeshort();
         }
      }
      
      if(type == "long")      // Check for close LONG
      {
         if(ma < mash)
         {
            closelong();
         }
      }
   }
   return(0);
  }


thx in advance :)

 

S

Try this to get a more definite signal

   ma = iMA(symbol, timeframe, 4, 0, MODE_SMA, PRICE_CLOSE, 0);
   mash = iMA(symbol, timeframe, 20, 0, MODE_SMA, PRICE_CLOSE, 0);

Any errors in the Journal tab?

Keep trying

-BB-

 

i changed the ma and mash and now loss trades are 91.74 %


the journal log is about 3 mb and is full with error like:

2008.09.10 18:24:39 2008.09.10 18:22 MA GBPUSD,M15: 37.2582
2008.09.10 18:24:39 2008.09.10 18:22 MA GBPUSD,M15: 1.7574
2008.09.10 18:24:39 2008.09.10 18:22 MA GBPUSD,M15: 1.7557
2008.09.10 18:24:39 2008.09.10 18:22 MA GBPUSD,M15: 37.7692
2008.09.10 18:24:39 2008.09.10 18:22 MA GBPUSD,M15: 1.7574
2008.09.10 18:24:39 2008.09.10 18:22 MA GBPUSD,M15: 1.7558
2008.09.10 18:24:39 2008.09.10 18:22 MA GBPUSD,M15: 37.5119
2008.09.10 18:24:39 2008.09.10 18:22 MA GBPUSD,M15: 1.7574
-------------------------------------------------------------------------------


is the algorith for opening and closing positions correct?

Reason: