pending order error on ea backtesting

Back to topics list To post a new topic, please log in or register
avatar
2
dannyarcher 2015.10.22 11:04
 
Hello  i take this many error like 2015.10.22 11:54:38.295	2015.10.20 23:59  USDTRYdemosistem USDTRYm,H1: OrderSend error 130
   error when i tried to run ea for backtest.I didnt get any compile error code looks fine .At here my goal  sending a pending order with fibonacci level price.Probably i miss something but i couldnt find any problem.If you could show me any tips i would be appreciate. Thank you ...


// Girdi Değişkenleri tanımla
input int EMAperiod=20;
input int Stochuplevel=90;
input int Stochuplowlevel=80;
input int Rsitoplevel = 70;
input int ADchange = 500;
input double pivottrendsapma = 0.4 ;
input double pivotnotrsapma = 0.2 ;
input double pivotslsapma = 0.4 ;
input double s1slsapma = 0.1;
input double riskrate = 0.05;
input int balance=50;
input double pipvalue=0.03;
input double lotsize = 0.02;
 
 //Global değişkenleri tanımla

   double entrylongprice;
 double sllongpoint;
   double tplongprice;
   int ordercheck;


// Ana Trend Buy/Sell Sinyal Belirle
int Maintrendsignal ()

{
//Maintrendsignal fonksiyonu için değişkenleri tanımla

double nowmainrsi =iRSI(NULL,240,9,PRICE_CLOSE,0);
double prvmainrsi =iRSI(NULL,240,9,PRICE_CLOSE,0);
double priceclose = iClose(NULL,240,0);
double pricehigh =iHigh(NULL,240,0);
double pricelow = iLow (NULL,240,0);
double prv1priceclose =iClose(NULL,240,1);
double prv2priceclose = iClose(NULL,240,2);
double prv1pricehigh = iHigh(NULL,240,0);
double prv2pricehigh = iHigh(NULL,240,0);

double nowmainma =  iMA(NULL,240,EMAperiod,0,MODE_EMA,PRICE_CLOSE,0);



//Uptrend için kriterleri tanımla


if ( nowmainrsi > 50 && (nowmainrsi > prvmainrsi) && priceclose> nowmainma && pricelow > nowmainma )
{
return 1;
}
else if ( ((pricehigh>prv1pricehigh>prv2pricehigh && priceclose> nowmainma && prv1priceclose> nowmainma && prv2priceclose > nowmainma)
|| ( (pricehigh>prv1pricehigh<prv2pricehigh) && (pricehigh > prv2pricehigh) && priceclose> nowmainma && prv1priceclose> nowmainma && prv2priceclose > nowmainma)
|| (  prv1pricehigh>prv2pricehigh && ((prv2pricehigh>pricehigh || prv2pricehigh<pricehigh ) && priceclose> nowmainma && prv1priceclose> nowmainma && prv2priceclose > nowmainma ) ) 
)&& (nowmainrsi > 50 ) )
{
return 1;
}
//else if ( for (s=0,s<=2;priceclose[s]<nowmainma;s++) && for (s=3,s<=8;priceclose[s]>iMA(NULL,240,EMAperiod,0,MODE_EMA,PRICE_CLOSE,5) 
//&& pricehigh[0] > nowmainma ) || (for(s=1,s<=3;priceclose[s]<nowmainma;s++ ) && for (s=4,s<=8;priceclose[s]>iMA(NULL,240,EMAperiod,0,MODE_EMA,PRICE_CLOSE,7) ) 
//&& priceclose[0]> nowmainma ) || (for(s=1,s<=2;priceclose[s]<nowmainma;s++) && for (s=3,s<=8;priceclose[s]>iMA(NULL,240,EMAperiod,0,MODE_EMA,PRICE_CLOSE,7)) && priceclose[0]> nowmainma) )


else 
{
return 0;
}
}


//orta vadeli al/sat sinyallerini üretir
  int Midtrendsignal()
  {
 double nowstoch = iStochastic(NULL,60,10,3,3,MODE_SMA,1,1,0);
 double prevstoch = iStochastic(NULL,60,10,3,3,MODE_SMA,1,1,1);
double  nowrsi =iRSI(NULL,60,9,PRICE_CLOSE,0);
double prevrsi=iRSI(NULL,60,9,PRICE_CLOSE,1);
  //stochastic check ve buy signal
  if ( (  nowstoch <= Stochuplevel && nowstoch >= Stochuplowlevel ) && (nowstoch > prevstoch)&& (nowrsi >= 60 )  ) 
  {
  return 1;
  }
  else if( nowrsi >=50  &&  nowstoch < Stochuplowlevel)
  {
  return 1;
  }
  else if ( nowrsi < 50 && nowrsi > 30 && (nowrsi-prevrsi)>0 &&  nowstoch >= 20 )
  {
  return 1;
  }
  else if ( 29>=nowrsi<=31 && 21>=nowstoch>=19 && (nowrsi-prevrsi)<0 )
  {
  return 1;
  }
  else if ( prevrsi < 28  && 29<=nowrsi<=31 && 21>=nowstoch>=19   )  
  {
  return 1;
  }
 else
 {
 return 0;
 }
  }
  
  //entry için giriş sinyalleri üretir  buy 1 sell 2  nötr 0
  int lowtrendsignal()
  {
  double nowrsi = iRSI (NULL,15,7,PRICE_CLOSE,0);
  double prvrsi = iRSI (NULL,15,7,PRICE_CLOSE,1);
  double nowADvol = iAD( NULL,15,0);
  double prvADvol = iAD(NULL,15,1);
  if( 70> nowrsi > 50  && (nowADvol-prvADvol) >= ADchange )
  return 1;
  else if (nowrsi > 70 &&  nowrsi > prvrsi && (nowADvol-prvADvol) >= ADchange )
  return 1;
  else if (30< nowrsi <50  && (nowADvol-prvADvol ) >=ADchange )
  return 2;
  else if (nowrsi <30 && nowrsi < prvrsi && (nowADvol-prvADvol) >= ADchange )
  return 2;
  else 
  {
  return 0;
  }
  }
  
  //Entry TP ve SL hesaplama modülü
   
   int CalculateOrder ()
   {
  
   double nowhigh=iHigh(NULL,60,0);
   double nowlow=iLow(NULL,60,0);
   double nowclose=iClose(NULL,60,0);
   double PP=(nowhigh + nowlow + nowclose) / 3;
   double r3fibo =PP + ( nowhigh - nowlow) ;
   double r2fibo = PP + ( ( nowhigh - nowlow)*0.618);
   double r1fibo = PP + (( nowhigh - nowlow)*0.382);
   double s1fibo = PP - (( nowhigh - nowlow)*0.382);
      double s2fibo = PP - (( nowhigh - nowlow)*0.618);
      double s3fibo =PP - ( nowhigh - nowlow) ;

     
     
    if(NormalizeDouble(PP,Digits)<Ask<NormalizeDouble(s1fibo,5))
{
sllongpoint = Ask ;
entrylongprice = Ask + 0.40 ;
tplongprice = NormalizeDouble(r2fibo,5) + 0.20 ;
}
   
//Fibonacci pivot noktaları hesapla

//Entry price buy/sell hesapla
if (lowtrendsignal () == 1 && Midtrendsignal () == 1 )
{

//lotsize = ( (balance*riskrate)/((Ask-NormalizeDouble(sllongpoint,Digits))) * pipvalue) ;
ordercheck = OrderSend(NULL,OP_BUYLIMIT,lotsize,NormalizeDouble(entrylongprice,5),0,NormalizeDouble(sllongpoint,5),tplongprice,"order",MAGICMA,10,clrRed);
return 1;
}
return 0;
}



//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+

      
      
      
//---


  

  
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
   EventKillTimer();
      
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
     Maintrendsignal();
      Midtrendsignal();
      CalculateOrder ();
     if (CalculateOrder () != 1)
     {

 if ( (entrylongprice-(entrylongprice*0.2)) <Ask<(entrylongprice+(entrylongprice*0.2)))
 {
  ordercheck =OrderSend(NULL,OP_BUY,lotsize,Ask,0,sllongpoint,tplongprice,"order",MAGICMA,0,clrRed) ;
    }
    else
    {
    Print("OrderClose error ",GetLastError());
    }
  }
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Tester function                                                  |
//+------------------------------------------------------------------+
double OnTester()
  {
//---
   double ret=0.0;
//---

//---
   return(ret);
  }
//+------------------------------------------------------------------+


//+------------------------------------------------------------------+

avatar
2
dannyarcher 2015.10.22 12:13 #
 

Hello

 My goal is a creating a order for example " when the buy signal is triggered and  the Ask price  was between at my special range (pivot point-support 1 etc )" . For this if i type a function "CheckForOpen"  and i put function call  to inside of  Void On Tick ().

Can the EA check  "checkforopen" function  and the Ask price  for my order  on every  sec  ?.

avatar
13008
WHRoeder 2015.10.22 15:28 #
 
pricehigh>prv1pricehigh>prv2pricehigh
That won't work. true = 1 and false = 0 so you get
if( 3 < 2 < 1 )
if( false < 1 )
if(     0 < 1 )
if(     true  )
if( 3 > 2 > 1 )
if(  true > 1 )
if(     1 > 1 )
if(     false )
Back to topics list  

To add comments, please log in or register