Changes in the experts

 

hi


i want Order be changed to open conditions:


1-When indicator the color changes that open order,
Candle not Problem closed.Just change the color.

2-Until the order is now open, And the previous order is not closed, Order not to open another,Even if the new signal will give.

thanks.


//+------------------------------------------------------------------+
//|                                        Schaff Trend Cycle EA.mq4 |
//|                              Copyright © 2008, TradingSytemForex |
//|                                http://www.tradingsystemforex.com |
//+------------------------------------------------------------------+

#property copyright "Copyright © 2008, TradingSytemForex"
#property link "http://www.tradingsystemforex.com"

#define OrSt "Schaff Trend Cycle EA"

extern string STC="---------------- Schaff Trend Cycle";
extern int STCPeriod=10;
extern int FastMAPeriod=23;
extern int SlowMAPeriod=50;
extern int STCTimeFrame=0;
extern int STCMainTrend=1440;
extern string LM="---------------- Lot Management";
extern double Lots=1.0;
extern bool MM=false; //money management
extern double Risk=0; //risk in percentage
extern string TSTB="---------------- TP SL TS BE";
extern bool RealSL_Enabled=false;
extern int RealSL=0; //stop loss under 15 pîps
extern bool RealTP_Enabled=false;
extern int RealTP=0; //take profit under 10 pîps
extern int SL=0; //stop loss
extern int TP=0; //take profit
extern int TS=0; //trailing stop
extern int TS_Step=0; //trailing stop step
extern int BE=0; //breakeven
extern string EXT="---------------- Extras";
extern bool Reverse=false;
extern bool Add_Positions=true; //positions cumulated
extern int MaxOrders=100; //maximum number of orders
extern int Magic=0;
extern int MaxTradePerBar=1;
//+------------------------------------------------------------------+
datetime Time0;int TradePerBar=0;int BarCount=-1;

int Slip=3;static int TL=0;double MML=0;

int init(){Time0=Time[0];return(0);}
int deinit(){return(0);}
//+------------------------------------------------------------------+
// expert start function
int start(){int j=0,limit=1;double BV=0,SV=0;BV=0;SV=0;double STCmain0, STCmain1, STCmain2, STC0, STC1,STC2;
  if(CntO(OP_BUY,Magic)>0) TL=1;if(CntO(OP_SELL,Magic)>0) TL=-1;for(int i=1;i<=limit;i++){
  
  STCmain0=iCustom(Symbol(),STCMainTrend,"STC_COLOR",STCPeriod,FastMAPeriod,SlowMAPeriod,0,i+2);   
  STCmain1=iCustom(Symbol(),STCMainTrend,"STC_COLOR",STCPeriod,FastMAPeriod,SlowMAPeriod,0,i+1);
  STCmain2=iCustom(Symbol(),STCMainTrend,"STC_COLOR",STCPeriod,FastMAPeriod,SlowMAPeriod,0,i);
  
  STC0=iCustom(Symbol(),STCTimeFrame,"STC_COLOR",STCPeriod,FastMAPeriod,SlowMAPeriod,0,i+2);
  STC1=iCustom(Symbol(),STCTimeFrame,"STC_COLOR",STCPeriod,FastMAPeriod,SlowMAPeriod,0,i+1);
  STC2=iCustom(Symbol(),STCTimeFrame,"STC_COLOR",STCPeriod,FastMAPeriod,SlowMAPeriod,0,i);
   
   string MainTrendisUp="false"; string MainTrendisDown="false";
   string BUY="false"; string SELL="false";   
   
   if(STCmain1<STCmain0&&STCmain2>STCmain1)MainTrendisUp="true";
   if(STCmain2>STCmain0&&STCmain2<STCmain1)MainTrendisDown="true";
   
   if(MainTrendisUp=="true")
      {   
      if(STC1<STC0&&STC2>STC1&&(TradePerBar<=MaxTradePerBar))BUY="true";    // <-- OPENS A BUY ORDER
      }   
   if(MainTrendisDown=="true")
      {
      if(STC1>STC0&&STC2<STC1&&(TradePerBar<=MaxTradePerBar))SELL="true";   // <-- OPENS A SELL ORDER
      }
          
//+------------------------------------------------------------------+
  //entry conditions
if(
//MAFIB=="true"&&
BUY=="true"){if(Reverse)SV=1;else BV=1;break;}
if(
//MAFIS=="true"&&
SELL=="true"){if(Reverse)BV=1;else SV=1;break;}}
//+------------------------------------------------------------------+

// expert money management
if(MM){if(Risk<0.1 || Risk>100) {Comment("Invalid Risk Value."); return(0);}
   else {MML=MathFloor((AccountFreeMargin() *AccountLeverage()*Risk*Point*100)/(Ask*MarketInfo(Symbol(),MODE_LOTSIZE)*MarketInfo(Symbol(),MODE_MINLOT )))*MarketInfo(Symbol(),MODE_MINLOT );}}
if(MM==false){MML=Lots;}

// expert init positions
int cnt=0,OP=0,OS=0,OB=0,CS=0,CB=0;OP=0;for(cnt=0; cnt<OrdersTotal();cnt++) {OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if((OrderType()==OP_SELL || OrderType()==OP_BUY) && OrderSymbol()==Symbol() && ((OrderMagicNumber()==Magic) || Magic==0)) OP=OP+1;}
if(OP>=1){OS=0; OB=0;}OB=0;OS=0;CB=0;CS=0;

// expert conditions to open position
if(SV>0){OS=1;OB=0;}if(BV>0){OB=1;OS=0;}

// expert conditions to close position
if((SV>0) || (MainTrendisUp=="true"&&STC1>STC0&&STC2<STC1) || (RealSL_Enabled && (OrderOpenPrice()-Bid)/Point>=RealSL)||(RealTP_Enabled && (Ask-OrderOpenPrice())/Point>=RealTP)){CB=1;}
if((BV>0) || (MainTrendisDown=="true"&&STC1<STC0&&STC2>STC1) || (RealSL_Enabled && (Ask-OrderOpenPrice())/Point>=RealSL)||(RealTP_Enabled && (OrderOpenPrice()-Bid)/Point>=RealTP)){CS=1;}
for(cnt=0;cnt<OrdersTotal();cnt++){OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
        if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && ((OrderMagicNumber()==Magic) || Magic==0)){if (CB==1){OrderClose(OrderTicket(),OrderLots(),Bid,Slip,Red); return(0);}}
        if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && ((OrderMagicNumber()==Magic) || Magic==0)){
        if(CS==1){OrderClose(OrderTicket(),OrderLots(),Ask,Slip,Red);return(0);}}}double SLI=0,TPI=0;int TK=0;

if(BarCount!=Bars){TradePerBar=0;BarCount=Bars;}

// expert open position value
if((AddP() && Add_Positions && OP<=MaxOrders) || (OP==0 && !Add_Positions)) {
        if(OS==1){if(Time0!=Time[0]){if (TP==0) TPI=0; else TPI=Bid-TP*Point;if (SL==0) SLI=0; else SLI=Bid+SL*Point;TK=OrderSend(Symbol(),OP_SELL,MML,Bid,Slip,SLI,TPI,OrSt,Magic,0,Red);Time0=Time[0];if(TK>0)TradePerBar++;OS=0;return(0);}}
        if(OB==1){if(Time0!=Time[0]){if(TP==0) TPI=0; else TPI=Ask+TP*Point;if(SL==0) SLI=0; else SLI=Ask-SL*Point;TK=OrderSend(Symbol(),OP_BUY,MML,Ask,Slip,SLI,TPI,OrSt,Magic,0,Lime);Time0=Time[0];if(TK>0)TradePerBar++;OB=0; return(0);}}}
for(j=0;j<OrdersTotal();j++){if(OrderSelect(j,SELECT_BY_POS, MODE_TRADES)){if (OrderSymbol()==Symbol() && ((OrderMagicNumber()==Magic) || Magic==0)) {TrP();}}}return(0);}

// expert number of orders
int CntO(int Type,int Magic){int _CntO;_CntO=0;
for(int j=0;j<OrdersTotal();j++){OrderSelect(j, SELECT_BY_POS, MODE_TRADES);if(OrderSymbol()==Symbol()) {if((OrderType()==Type && (OrderMagicNumber()==Magic) || Magic==0)) _CntO++;}}return(_CntO);}

// expert trailing stop
void TrP(){double pb,pa,pp;pp=MarketInfo(OrderSymbol(),MODE_POINT);if (OrderType()==OP_BUY){pb=MarketInfo(OrderSymbol(),MODE_BID);

//expert breakeven
    if(BE>0){if((pb-OrderOpenPrice())>BE*pp){if((OrderStopLoss()-OrderOpenPrice())<0){ModSL(OrderOpenPrice()+0*pp);}}}
    if(TS>0){if((pb-OrderOpenPrice())>TS*pp){if(OrderStopLoss()<pb-(TS+TS_Step-1)*pp){ModSL(pb-TS*pp);return;}}}}
  if(OrderType()==OP_SELL){pa=MarketInfo(OrderSymbol(),MODE_ASK);if(BE>0){if((OrderOpenPrice()-pa)>BE*pp){if((OrderOpenPrice()-OrderStopLoss())<0){ModSL(OrderOpenPrice()-0*pp);}}}
  if (TS>0){if (OrderOpenPrice()-pa>TS*pp){if (OrderStopLoss()>pa+(TS+TS_Step-1)*pp || OrderStopLoss()==0){ModSL(pa+TS*pp);return;}}}}}

//expert stoploss
void ModSL(double ldSL){bool fm;fm=OrderModify(OrderTicket(),OrderOpenPrice(),ldSL,OrderTakeProfit(),0,CLR_NONE);}

//expert add positions function
bool AddP(){int _num=0; int _ot=0;
for (int j=0;j<OrdersTotal();j++){if(OrderSelect(j,SELECT_BY_POS)==true && OrderSymbol()==Symbol() && OrderType()<3 && ((OrderMagicNumber()==Magic) || Magic==0)) {     
         _num++;if(OrderOpenTime()>_ot) _ot=OrderOpenTime();}}
if(_num==0) return(true);if(_num>0 && ((Time[0]-_ot))>0) return(true);else return(false);}


Files:
 

For question #1, I don't quite follow. I think you mean "make it trade as soon as the colour changes", Right now it looks like the colour must be changed for two bars.

For question #2, there is a parameter, MaxTrades, that *should* limit you to that number of trades. Try changing it to 1.

Also, I reformated it for readability.

sn

Files:
Reason: