Reverlsals orders

 

Hi guys can somebody help a little?

I have a EA - its working like that: ea is opening buy and sell pendings orders with sl and tp, and when sell or buy order is filled on SL is turning reversal pending order.

Is really simple algoritm But... i dont no why my reversals dont open properly - can somebody check this code? Please...

//+------------------------------------------------------------------+
//|                                            Buy sell pendings.mq4 |
//|                                                   Marcin Mrugacz |
//|                                           finansowa.blogspot.com |
//+------------------------------------------------------------------+
#property copyright "Marcin Mrugacz"
#property link      "finansowa.blogspot.com"
#property show_inputs

#define MAGICMA 456
#include <stdlib.mqh>

/////////////////////////// Before You will start go to:
//SETTINGS               // options->expert advisors-> Turn on "Allow live trading".
/////////////////////////// 

/////////////////////////  //
extern double size=0.1;    // choose lot size. 
extern int tp=100;         // choose TP in points.   //You need to setup value 0 dont off this
extern int sl=100;         // choose SL in points    //You need to setup value 0 dont off this
extern int distance=300;   // choose distance in points 
/////////////////////////////
extern string r="TP and SL for reversals: ";
///////////////////////////// SL and TP for reversals: (They are setup after reaching the price around placed pendings)
extern double tp2=200;     // tp for 2 reversal 0 - off this //
extern double sl2=0;       // sl for 2 reversal 0 - off this //
/////////////////////////////
extern string t="Setup time: ";
//extern bool turnon=true;   //  - Turn on/off setuping the time of running orders.
extern int houer=14;       //  
extern int minute=30;      //
/////////////////////////////
extern int slipage=30;

int i=0;
int c=1;
string script=" ";
int ticket[5];
int a=0;int b=0;

int init()
  {
//----
double ask=Ask;
double bid=Bid;
int ticket[6];

   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   datetime T_cur = TimeCurrent(); 
   int curenthouer= TimeHour(T_cur); 
   int curentminute=TimeMinute(T_cur);
   
  // if(curenthouer>-1+houer && curentminute>-1+minute)     {

double OldAsk=Ask;
string check[10];

double  ask=Ask;
 double bid=Bid;
 double point=Point;

 if (c==1) {
static double buyr; buyr=ask+distance*point-(sl*point);
static double selr; selr=bid-distance*point+(sl*point);

static double buy; buy=ask+distance*point;
static double sel; sel=bid-distance*point;

 ticket[1]=OrderSend(Symbol(), OP_SELLSTOP, size, ask-distance*Point, 1,ask-distance*Point+(sl*Point),ask-distance*Point-(tp*Point),"pending sellstop", MAGICMA, 0, Red);                  
 ticket[3]=OrderSend(Symbol(), OP_BUYSTOP, size, bid+distance*Point, 1,  bid+distance*Point-sl*Point, bid+distance*Point+tp*Point, "pending buystop", MAGICMA, 0, Green);
           }c++;if (c==10) c=3;
     
     string buyrev;     
     string selrev;      
     if (b==235) {buyrev="Revelsal to buy is on";}
     if (a==234) {selrev="Revelsal to sell is on";}
     
 
double minSL=MarketInfo(Symbol(), MODE_STOPLEVEL);     
   
       
    
     
            if (i==0) {script="R";}
            if (i==1) {script="Ru";}
            if (i==2) {script="Run";}
            if (i==3) {script="Runn";}
            if (i==4) {script="Runni";}
            if (i==5) {script="Runnin";}
            if (i==6) {script="Running";}
          
            i++; if (i==7) i=0; 
if (sl2>0) double slrev=buyr+(sl2*Point); else slrev=0;
if (tp2>0) double tprev=buyr-(tp2*Point); else tprev=0;
if (sl2>0) double slrev2=selr-(sl2*Point); else slrev=0;
if (tp2>0) double tprev2=selr+(tp2*Point); else tprev=0;

//double signals=obliczmi(buy,Bid,slipage*Point);    
//double signalb=obliczmi(sel,Ask,slipage*Point);

    OrderSelect(ticket[1],SELECT_BY_TICKET);
    int order=OrderType();
    
 int error;      
if ( b!=235  && OrderType()==OP_BUY) {b=235; ticket[4]=OrderSend(Symbol(), OP_SELLSTOP, size,buyr, 1,  slrev, tprev, "revelsal sell", MAGICMA, 0, Pink); 
{error=GetLastError(); Print("Sell stop Error = ",ErrorDescription(error));}  }       
    OrderSelect(ticket[3],SELECT_BY_TICKET);
     order=OrderType();
if ( a!=234  && OrderType()==OP_SELL) {a=234; ticket[2]=OrderSend(Symbol(), OP_BUYSTOP, size,selr , 1,  slrev2, tprev2, "revelsal buy", MAGICMA, 0, Pink); 
{error=GetLastError(); Print("Sell stop Error = ",ErrorDescription(error));}   }

//----
//Sleep(30); if (ticket[2]>0 || ticket[4]>0) 
         
//         }
         
           Comment(
        "min SL/TP here is ", minSL, " pips\n",
        "Revelsal to selstop is setup on: ", selr," \n", 
        "Revelsal to buystop is setup on: ", buyr," \n", 
        "a ", a," \n ",  "b ", b," \n ", 
        "Buyrev",  buyr, " \n",
        "selrev",selr, "\n",
        "buy ", buy," \n",
        "OrderTYpe", order,
        "Script is ", script," \n"
  );  
         
   return(0);
  }
//+------------------------------------------------------------------+
 

OK

I just solved the problem. Thanks :P

:)

 
migaczyk:

OK

I just solved the problem. Thanks :P

:)


might be, but if you have to restart your metatrader .......

then this is failing ...

Reason: