open order after TP or SL - page 2

 

ajol, I don't have an answer for you. I copied that code from another ea, and it works so I left it.

RaptorUK, I have changed my "defining the function" code ....

int LastTradeProfit(bool closeResult, bool plResult, bool order_type; double lotsResult;);

to try and match my "calling the function" code which was ...

LastTradeProfit(bool closeResult, plResult, order_type; double lotsResult;);

But now the compiler says ':' - comma expected right after bool order_type; in defining the function code.

So I still have something wrong. What am I missing?


 

You define the variables in the Function definition not in the Function call . . . try this

LastTradeProfit(closeResult, plResult, order_type, lotsResult);

and . . .

int LastTradeProfit(bool closeResult, bool plResult, bool order_type  ;  double lotsResult ; );
 

qjol:

    if(Close[0]>10)  {Faktor=1000; Digt=3;}  else
      if(Close[0]<10)  {Faktor=100000; Digt=5;}
mr robert can u explain what r u trying to achive with Close[0] > or < 10 & how is this thing related to digt 3 or 5

The close price has NOTHING to do with 4/5 digit broker. Your Digt is not exactly my Digits.pips

On Gold for example Close > 10 ($1800/oz) but Factor would be 100 (quoted to $0.01). my Pips2dbl == 1/Faktor. Also note you need TWO values (TP, SL, AND slippage)

//++++ These are adjusted for 5 digit brokers.
int     pips2points;    // slippage  3 pips    3=points    30=points
double  pips2dbl;       // Stoploss 15 pips    0.015      0.0150
int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
int     init(){
     if (Digits % 2 == 1){      // DE30=1/JPY=3/EURUSD=5 https://www.mql5.com/en/forum/135345
                pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
    } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
 
WHRoeder:

The close price has NOTHING to do with 4/5 digit broker. Your Digt is not exactly my Digits.pips

On Gold for example Close > 10 ($1800/oz) but Factor would be 100 (quoted to $0.01). my Pips2dbl == 1/Faktor. Also note you need TWO values (TP, SL, AND slippage)

this is my question to mr. robert
 

OK guys, my real problem is not the issue that you bring up with the 3/5 digit code. I will fix that later. Instead I would like your help in whether or not my logic structure is correct in my main program code and why does the compiler continue to tell me that I am missing a comma at ...

int LastTradeProfit(bool closeResult, bool plResult, bool order_type  ; double lotsResult;);  

';' - comma expected

It wants a comma at the position of the yellow highlight, but it doesn't make sense to me to put one there, and when I do it thinks I am adding a new parameter and then requests a parameter definition.

Have I confused the compiler because my code logic is incorrect or is there something wrong with the compiler?

 

This is my updated code to show where I am getting the error.

#property copyright ""
#property link      ""

//---- input parameters
extern double    Lots=0.2;
extern double        TakeProfitPips=200;
extern double        StopLossPips=200;
extern double        magic.number=0;
      int         Faktor, Digt, cnt, PL, total, bt, st, pos;
   double         TPp, SLp, BSp, SSp, LotsD, LotsX, lotsResult;
   
   int iOrders;
   int i;
   bool plResult;
   bool otResult;
   bool closeResult;
   bool order_type;
   bool ordertypeResult;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init(){}

//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit(){}

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
      if(Close[0]>10)  {Faktor=1000; Digt=3;}  else
      if(Close[0]<10)  {Faktor=100000; Digt=5;}
      
      
      if(OrdersTotal()!=0)
         {
         for(cnt=0; cnt<OrdersTotal(); cnt++)
            {
            OrderSelect(cnt,SELECT_BY_POS);
//if(total==-1   )
     

//--------------Take Profit--------------------------------

            if(OrderTakeProfit()==0 && TakeProfitPips !=0)
               {
                  if(OrderType()==OP_BUY && OrderSymbol()==Symbol())
                     {TPp = OrderOpenPrice()+TakeProfitPips/Faktor;}
                  if(OrderType()==OP_SELL && OrderSymbol()==Symbol())                     
                     {TPp = OrderOpenPrice()-TakeProfitPips/Faktor;}
                     
               } else TPp = OrderTakeProfit();
               
               
               
//--------------Stop Loss--------------------------------

            if(OrderStopLoss()==0 && StopLossPips !=0)
               {
                  if(OrderType()==OP_BUY && OrderSymbol()==Symbol())
                     {SLp = OrderOpenPrice()-StopLossPips/Faktor;}
                  if(OrderType()==OP_SELL && OrderSymbol()==Symbol())                     
                     {SLp = OrderOpenPrice()+StopLossPips/Faktor;}
               } else SLp = OrderStopLoss();

//---------------Modify Order--------------------------
            if (OrderType()==OP_BUY || OrderType()==OP_SELL)   
            OrderModify(OrderTicket(),OrderOpenPrice(),SLp,TPp,0);
                           
//-----------------------------------------------------
  {
   int    ticket;
   double point;

   

   
   
   LastTradeProfit(closeResult, plResult, ordertypeResult, lotsResult);
   
   if(closeResult==true && plResult==true && ordertypeResult==true)
     {
      ticket=OrderSend(Symbol(),OP_BUY,Lots,0,0,0,0,"some comment",16384,0,Green);
      
      if(ticket<=0) Print("Error = ",GetLastError());
      else { Print("ticket = ",ticket); break; }
      //---- 5 seconds wait
      Sleep(5000);
     }
     //while(true)
     if(closeResult==true && plResult==false && ordertypeResult==true);
   
     {
      LotsD=Lots;
      ticket=OrderSend(Symbol(),OP_SELL,LotsD,0,0,0,0,"some comment",16384,0,Green);
      
      if(ticket<=0) Print("Error = ",GetLastError());
      else { Print("ticket = ",ticket); break; }
      //---- 5 seconds wait
      Sleep(5000);
     }
      
  
   if(closeResult==true && plResult==true && ordertypeResult==false);
     {
      ticket=OrderSend(Symbol(),OP_SELL,Lots,0,0,0,0,"some comment",16384,0,Green);
      
      if(ticket<=0) Print("Error = ",GetLastError());
      else { Print("ticket = ",ticket); break; }
      //---- 5 seconds wait
      Sleep(5000);
     }
     //while(true)
   if(closeResult==true && plResult==false && ordertypeResult==false)
   
     {
      LotsD=Lots;
      ticket=OrderSend(Symbol(),OP_BUY,LotsD,0,0,0,0,"some comment",16384,0,Green);
      
      if(ticket<=0) Print("Error = ",GetLastError());
      else { Print("ticket = ",ticket); break; }
      //---- 5 seconds wait
      Sleep(5000);
     }
  
//----
   return(0);
  }
            } // for cnt
         }//if OrdersTotal
  return(0);
  }// Start()
  
  int LastTradeProfit(bool closeResult, bool plResult, bool ordertypeResult ; double lotsResult;);  << ERROR IS HERE.
 {
    iOrders = OrdersHistoryTotal()-1;
    for (i = iOrders; i>=0; i--)
 {
    OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
    if (OrderSymbol() == Symbol())
     {  
      if ((TimeDayOfYear(OrderOpenTime()) == DayOfYear()) && (TimeYear(OrderOpenTime()) == Year()))
       {
        if (OrderProfit() >= 0)
         plResult = true;
        else
          plResult = false;
       {
         if(OrderSelect(i, SELECT_BY_POS)==true)
            {
               order_type;
               order_type=OP_BUY;
               ordertypeResult = order_type;
            }
         else
            Print("OrderSelect() returned error - ",GetLastError());
          
            if(OrderSelect(i,SELECT_BY_POS)==true)
               Print("lots for the order i ",OrderLots());
                  if(OrderLots()>0)
                     {
                        lotsResult=OrderLots();
                      }  
            else
               Print("OrderSelect returned error of ",GetLastError());
               
                  if(OrderSelect(i,SELECT_BY_POS)==true)
                     Print("Close price for the order ",i," = ",OrderClosePrice());
                        if(OrderClosePrice()>0)
                     {
                        closeResult=true;
                      } 
                  else
                        closeResult=false;
                     Print("OrderSelect failed error code is",GetLastError());    
         }             
       }
     }
   }
}
  return(0);

   
 
//+------------------------------------------------------------------+
 
RobertD517:

OK guys, my real problem is not the issue that you bring up with the 3/5 digit code. I will fix that later. Instead I would like your help in whether or not my logic structure is correct in my main program code and why does the compiler continue to tell me that I am missing a comma at ...

';' - comma expected

It wants a comma at the position of the yellow highlight, but it doesn't make sense to me to put one there, and when I do it thinks I am adding a new parameter and then requests a parameter definition.

Have I confused the compiler because my code logic is incorrect or is there something wrong with the compiler?

You are missing a comma and have surplus semi-colons . . do this . . .

int LastTradeProfit(bool closeResult, bool plResult, bool order_type, double lotsResult);  
 

OK RaptorUK, you fixed that problem, thanks. Now the compiler says ...

'LastTradeProfit' - no dll defined for the imported function

int LastTradeProfit(bool closeResult, bool plResult, bool ordertypeResult, double lotsResult);

at the yellow highlight.

I suspect that there is something incorrect with one of the other three functions below the plResult ie; ordertypeResult, lotsResult, or closeResult.

Or should I call these functions separately?

 
Why are you declaring the variable locally as part of the Function definition and also globally ?
 

Hey, I need some help please.

I am working on an ea that enters trades based on the rsi  overbought and oversold indicator.

For instance the ea finds a buying opportunity when the rsi shows an oversold region.

It will enter a buy position then place a sell stop somewhere below. If the sell stop is hit, the ea is supposed to place a buy stop  somewhere above. 

The problem is the ea does not open a buy stop when the sell stop is triggered.

I will really appreciate your help. The code is down below



void OnTick()

  {
   string signal ="";
   
   // WE WILL USE THE RSI INDICATOR TO ENTER THE FIRST TRADE
   double RSIValue = iRSI(_Symbol,_Period,14,PRICE_CLOSE,0);
   
   //IF RSI IS OVERBOUGHT(>70), THE SIGNAL IS SELL
   if (RSIValue>70)
   {
      signal="sell";
   }
   
   //IF RSI IS OVERSOLD(<30), THE SIGNAL IS BUY
   if (RSIValue<30)
   {
      signal="buy";
   }
   
// BUYING SITUATION
   // IF THE RSI SIGNAL IS A BUY AND THE NUMBER OF ORDERS PENDING/RUNNING = O(WHICH IS THE VALUE OF THE COUNTER), 
   if (signal=="buy" &&OrdersTotal()==0)
   {
      //BUY ORDER IS EXECUTED AND A SELL STOP(PENDING SELL) IS PLACED
      int buyticket1 = OrderSend (_Symbol,OP_BUY,0.03,Ask,3,Ask-210*_Point,Ask+150*_Point,NULL,0,0,Green);
      int sellticket2 = OrderSend(Symbol(),OP_SELLSTOP,0.08,(Ask-(100*_Point)),3,(Ask+(110*_Point)),(Ask-(200*_Point)),NULL,0,0,Red);
          
        //IF THERE IS A SELL ORDER(MEANING THAT THE SELL STOP ORDER HAS NOW BEEN EXECUTED TO A RUNNING SELL ORDER AND IS NOW NOT A PENDING ORDER)
        //THEN STEP 3 WHICH IS A BUY ORDER IS EXECUTED
    
      OrderSelect(1,SELECT_BY_POS);
      if(OrderType()==OP_SELL)         
      {
         int buyticket3 = OrderSend(_Symbol,OP_BUYSTOP,0.35,(Ask+(100*_Point)),3,(Ask-(210*_Point)),(Ask+(150*_Point)),NULL,0,0,Green);
      }  
 }   
    
    
Reason: