Please Help Me Delay My EA Trades

 
ive recently made an EA based on the stochastic indicator and need some assistance to make the EA better. I am a complete dum dum when it comes to coding so I made the EA using an online EA builder. I now need to madify the EA so that it will only place one trade on each upward and downward cycle of the stochastic. I have looked on this forum for answers and have found some ways to delay trades but the way i think is best for this EA is not described anywhere.
I would like the EA ,when placing a trade to store (timecurrent) as a variable (lastsell) or (lastbuy)
and then to call these variables and an external (delaytime) variable as part of the open trade logic.
heres what i came up with:

extern  int delaytime = 400                                   // external variable (minutes to delay trades)
datetime lastsell  ;                                          // declare other variables( these will be the
datetime lastbuy  ;                                           // time of the last buy and sell trades)

&& (timecurrent()) > (lastsell + (delaytime*60))     //insert this line into sell conditions
&&(timecurrent()) > (lastbuy + (delaytime*60))     // insert this line into buy conditions

and these commands after buy order is placed...
(timecurrent) = lastbuy                                                 // after the buy order is placed
(timecurrent) = lastsell                                                 //after the sell order is placed

anyways ive entered these line into the code and i get alot of errors and cant even compile it to test, i dont even know if this code is on the right track or completely wrong altogether. please can someone take a quick look at it and tell me where im going wrong? i dont expect it to be done for me but im a bit lost.

attached is complete EA after i have added these lines into it.


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

extern int delaytime =400;
extern int MagicNumber=10001;
extern double Lots =0.1;
extern double StopLoss=20;
extern double TakeProfit=10;
extern int TrailingStop=0;
extern int Slippage=3;
//+------------------------------------------------------------------+
//    expert start function
//+------------------------------------------------------------------+
int start()
{
  double MyPoint=Point;
  if(Digits==3 || Digits==5) MyPoint=Point*10;
  
  datetime lastbuy ;
  datetime lastsell ;
  
  double TheStopLoss=0;
  double TheTakeProfit=0;
  if( TotalOrdersCount()==0 ) 
  {
     int result=0;
     if((iStochastic(NULL,0,8,3,3,MODE_SMA,1,MODE_MAIN,0)>iStochastic(NULL,0,8,3,3,MODE_SMA,1,MODE_SIGNAL,0))&&(iRSI(NULL,0,5,PRICE_CLOSE,0)>67))
     &&((TimeCurrent)>(lastbuy+(delaytime * 60)) )             // Here is your open buy rule
     {
        result=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,MagicNumber,0,Blue,)(TimeCurrent=lastbuy);
        
       
        if(result>0)
        {
         TheStopLoss=0;
         TheTakeProfit=0;
         if(TakeProfit>0) TheTakeProfit=Ask+TakeProfit*MyPoint;
         if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
         OrderSelect(result,SELECT_BY_TICKET);
         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
        }
        return(0);
     }
     if((iStochastic(NULL,0,8,3,3,MODE_SMA,1,MODE_MAIN,0)<iStochastic(NULL,0,8,3,3,MODE_SMA,1,MODE_SIGNAL,0))&&(iRSI(NULL,0,5,PRICE_CLOSE,0)<33))
     &&((TimeCurrent)>(lastsell+(delaytime * 60)) ) // Here is your open Sell rule
     {
        result=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,MagicNumber,0,Red)(TimeCurrent=lastsell);
        if(result>0)
        {
         TheStopLoss=0;
         TheTakeProfit=0;
         if(TakeProfit>0) TheTakeProfit=Bid-TakeProfit*MyPoint;
         if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint;
         OrderSelect(result,SELECT_BY_TICKET);
         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
        }
        return(0);
     }
  }
  
  for(int cnt=0;cnt<OrdersTotal();cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()<=OP_SELL &&   
         OrderSymbol()==Symbol() &&
         OrderMagicNumber()==MagicNumber 
         )  
        {
         if(OrderType()==OP_BUY)  
           {
            if(TrailingStop>0)  
              {                 
               if(Bid-OrderOpenPrice()>MyPoint*TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-MyPoint*TrailingStop)
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*MyPoint,OrderTakeProfit(),0,Green);
                     return(0);
                    }
                 }
              }
           }
         else 
           {
            if(TrailingStop>0)  
              {                 
               if((OrderOpenPrice()-Ask)>(MyPoint*TrailingStop))
                 {
                  if((OrderStopLoss()>(Ask+MyPoint*TrailingStop)) || (OrderStopLoss()==0))
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+MyPoint*TrailingStop,OrderTakeProfit(),0,Red);
                     return(0);
                    }
                 }
              }
           }
        }
     }
   return(0);
}

int TotalOrdersCount()
{
  int result=0;
  for(int i=0;i<OrdersTotal();i++)
  {
     OrderSelect(i,SELECT_BY_POS ,MODE_TRADES);
     if (OrderMagicNumber()==MagicNumber) result++;

   }
  return (result);
}
 
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Read the docs: DateTime is the number of SECONDS.
    extern  int delaytime = 400  // external variable (minutes to delay trades)
    :
    // && (timecurrent()) > (lastsell + delaytime)      What is the sum of 2 cats and 3 cars
       && (timecurrent()) > (lastsell + delaytime * 60) //insert this line into sell conditions
 

thanks, i just edited the post and added the *60 .

i still get heaps of errors, if i slowly work through all the errors do you think it will work?

i just dont want to spend hours and hours getting rid of all the errors only to find my code doesnt make sense,

theres 45 errors and they all are on the lines i added in which makes me think i havent formatted it properly, i would assume it would be an easy fix for an experienced EA writer/coder/programmer

 
diggity:

thanks, i just edited the post and added the *60 .

i still get heaps of errors, if i slowly work through all the errors do you think it will work?

Did you declare all the variables and make the  "timecurrent()"  function ?  or did you mean to use TimeCurrent() ?
 

i used TimeCurrent() in the code, and yes i declared all variables.

i just get stupid errors that make no sense to me.... for example, the folling line of code:

&&(( TimeCurrent ) > (lastbuy+(delaytime * 60))

i get this :  '&&'  unexpected token                          (first two charcters)

                 '('     unexpected token                          (third character)

                 '>'   semicolon expected                        

                 '>'  unexpected token

                 '('   unexpected token                              (before lastbuy)

                 '+'    assignment expected

                  '('  unexpected token                                     (after +)

                  '*' assignment expected

                  '60'   unexpected token


everything except for the variables seems to be wrong.  ive read the docs about unexpected tokens and all it said was that maybe my variables were spelled wrong or conflict with reserved words.

if i remove all the parentesis then those errors go away and the othwers remain, but in my mind it doesnt really make sense with out them.

i am  still hunting for answers elswhere but im still lost as also..

 
Usually those error means you have missed some terminator or its pair. Something like { which requires its pair of this } or ( its pair )
Reason: