ARROW problem

 

Hello, I have a problem  with my code, it doesn't place an order when the arrow from the indicators appears

Thanks for replying :-)

Those are my code for INDICATOR and EA

////// EA //////
//+------------------------------------------------------------------+
//|                                           EA TEST.mq4 
//|                                                                                |
//+------------------------------------------------------------------+
#property copyright "@TolotraFx"
#property link      "tulutr25@gmail.com"
#property description "WELCOME @ EA TEST."
#property description " "

#define EAName "EA TEST"

extern string S1="---------------- EA TEST";
extern int RSI_Period = 21;         //8-25
extern int RSI_Price = PRICE_CLOSE;           //0-6
extern int Volatility_Band = 34;    //20-40
extern int RSI_Price_Line = 2;      
extern int RSI_Price_Type = 0;      //0-3
extern int Trade_Signal_Line = 7;   
extern int Trade_Signal_Type = 0;   //0-3
extern string S2="---------------- Money EA TEST";
extern double Lots=0.1; //lots
extern bool RiskManagement=false; //money management
extern double RiskPercent=10; //risk in percentage
double My_Money_Profit_Target;
extern double TargetProfit=10;
extern bool Martingale=true; //martingale
extern double Multiplier=2; //multiplier
extern double MinProfit=0; //minimum profit to apply the martingale
extern string S3="---------------- Order Management";
extern int StopLoss=250; //stop loss
extern int TakeProfit=500; //take profit
extern int TrailingStop=300; //trailing stop
int TrailingStep=1; //margin allowe to the price before to enable the ts
extern int BreakEven=300; //breakeven
extern bool AddPositions=false; //positions cumulated
extern int MaxOrders=100; //maximum number of orders
extern int Slippage=3;
extern int Magic=0; // magic number
extern string S4="---------------- Filters";
extern bool TradeOnSunday=false; //time filter on sunday
extern bool MondayToThursdayTimeFilter=true; //time filter the week
extern int MondayToThursdayStartHour=8; //start hour time filter the week
extern int MondayToThursdayEndHour=22; //end hour time filter the week
extern bool FridayTimeFilter=true; //time filter on friday
extern int FridayStartHour=8; //start hour time filter on friday
extern int FridayEndHour=20; //end hour time filter on friday
double result;
extern string S5="----------------";
extern bool EmailAlert=false;
extern bool ReverseTheSystem=false; //sell/buy instead of buy/sell

extern int MaxTradePerBar=1;

datetime Time0;int TradePerBar=0;int BarCount=-1;

int err=0;int TK;double Balance=0.0;double maxEquity;double minEquity;

int init(){Time0=Time[0];return(0);}
int deinit(){return(0);}

//start function
int start(){int SL=StopLoss;int TP=TakeProfit;int TK=0;int j=0,limit=1;double SLI=0,TPI=0;double BV=0,SV=0;
for(int i=1;i<=limit;i++){

//PROFIT TARGET
My_Money_Profit_Target=AccountEquity()*(TargetProfit/100);
if (AccountProfit()>= My_Money_Profit_Target)
   {
    for(i=OrdersTotal()-1;i>=0;i--)
       {
       OrderSelect(i, SELECT_BY_POS);
       int type   = OrderType();
               
       bool result = false;
              
       switch(type)
          {
          //Close opened long positions
          case OP_BUY  : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),Slippage,Pink);
                         break;
               
          //Close opened short positions
          case OP_SELL : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),Slippage,Pink);
                          
          }
          
       if(result == false)
          {
            Sleep(28800000); //Sleep during 8h
          }  
       }
      Alert ("Account Profit Reached. All Open Trades Have Been Closed");
      return(0);
   }  
   
   Comment("Balance: ",AccountBalance(),"\n\nAccount Equity: ",AccountEquity(),"\n\nAccount Profit: ",AccountProfit(),
           "\n\nMy Account Profit Target: ",My_Money_Profit_Target);

//COMMENT
string Comments="SniperProFxEAFinal";
      ObjectCreate(Comments, OBJ_LABEL, 0, 0, 0, 0);

   ObjectSet(Comments, OBJPROP_XDISTANCE, 250);
   ObjectSet(Comments, OBJPROP_YDISTANCE, 0); 

   ObjectSetText(Comments, "SniperProFxEAFinal", 40, "Arial", CornflowerBlue);  
//END COMMENT

//time filter
if((TradeOnSunday==false&&DayOfWeek()==0)||(MondayToThursdayTimeFilter&&DayOfWeek()>=1&&DayOfWeek()<=4&&!(Hour()>=MondayToThursdayStartHour&&Hour()<=MondayToThursdayEndHour))||
(FridayTimeFilter&&DayOfWeek()==5&&!(Hour()>=FridayStartHour&&Hour()<=FridayEndHour))){for(i=OrdersTotal();i>=0;i--){OrderSelect(i,SELECT_BY_POS);
if(OrderType()==OP_BUY&&OrderSymbol()==Symbol()&&((OrderMagicNumber()==Magic)||Magic==0)){OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Red);return(0);}
if(OrderType()==OP_SELL&&OrderSymbol()==Symbol()&&((OrderMagicNumber()==Magic)||Magic==0)){OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Red);return(0);}
switch(OrderType()){case OP_BUYLIMIT:case OP_BUYSTOP:case OP_SELLLIMIT:case OP_SELLSTOP:result=OrderDelete(OrderTicket());}}return(0);}



//main signal
double ASC2=iCustom(NULL, 0,"test", RSI_Period,RSI_Price,Volatility_Band,RSI_Price_Line,RSI_Price_Type, 0, PRICE_CLOSE, MODE_UPPER,i);
double ASC1=iCustom(NULL, 0,"test", RSI_Period,RSI_Price,Volatility_Band,RSI_Price_Line,RSI_Price_Type, 1, PRICE_CLOSE, MODE_LOWER,i);
string BUY="false";string SELL="false";
if(ASC1>0&&ASC1!=EMPTY_VALUE&&(TradePerBar<=MaxTradePerBar))BUY="true";
if(ASC2>0&&ASC2!=EMPTY_VALUE&&(TradePerBar<=MaxTradePerBar))SELL="true";

//entry conditions
if(BUY=="true"){if(ReverseTheSystem)BV=1;else SV=1;break;}
if(SELL=="true"){if(ReverseTheSystem)SV=1;else BV=1;break;}}

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

//martingale
if(Balance!=0.0&&Martingale==True){if(Balance>AccountBalance())Lots=Multiplier*Lots;else if((Balance+MinProfit)<AccountBalance())Lots=Lots/Multiplier;
else if((Balance+MinProfit)>=AccountBalance()&&Balance<=AccountBalance())Lots=Lots;}Balance=AccountBalance();if(Lots<0.01)Lots=0.01;if(Lots>100)Lots=100;

//positions initialization
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;

//entry conditions verification
if(SV>0){OS=1;OB=0;}if(BV>0){OB=1;OS=0;}

//conditions to close positions
if((BV>0)){CS=1;if(EmailAlert)SendMail ("ASCTrend EA: ",Symbol()+" "+Period()+": Buy Order closed @ "+DoubleToStr(Bid,Digits));}
if((SV>0)){CB=1;if(EmailAlert)SendMail ("ASCTrend EA: ",Symbol()+" "+Period()+": Sell Order closed @ "+DoubleToStr(Bid,Digits));}
for(cnt=0;cnt<OrdersTotal();cnt++){OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderType()==OP_BUY&&OrderSymbol()==Symbol()&&((OrderMagicNumber()==Magic)||Magic==0)){if(CS==1){OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Red);return(0);}}
if(OrderType()==OP_SELL&&OrderSymbol()==Symbol()&&((OrderMagicNumber()==Magic)||Magic==0)){if(CB==1){OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Red);return(0);}}}

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

//open position
if((AddP()&&AddPositions&&OP<=MaxOrders)||(OP==0&&!AddPositions)){
if(OB==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,Lots,Bid,Slippage,SLI,TPI,EAName,Magic,0,Red);
if(EmailAlert)SendMail ("ASCTrend EA: ",Symbol()+" "+Period()+": Sell Order opened @ "+DoubleToStr(Bid,Digits));Time0=Time[0];if(TK>0)TradePerBar++;OS=0;return(0);}}
if(OS==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,Lots,Ask,Slippage,SLI,TPI,EAName,Magic,0,Lime);
if(EmailAlert)SendMail ("ASCTrend EA: ",Symbol()+" "+Period()+": Buy Order opened @ "+DoubleToStr(Bid,Digits));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();}}}

//not enough money message to continue the martingale
if(TK<0){if (GetLastError()==134){err=1;Print("NOT ENOGUGHT MONEY!!");}return (-1);}

return(0);}

//trailing stop and breakeven
void TrP(){int BE=BreakEven;int TS=TrailingStop;double pb,pa,pp;pp=MarketInfo(OrderSymbol(),MODE_POINT);if(OrderType()==OP_BUY){pb=MarketInfo(OrderSymbol(),MODE_BID);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+TrailingStep-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+TrailingStep-1)*pp||OrderStopLoss()==0){ModSL(pa+TS*pp);return;}}}}}

//stop loss modification function
void ModSL(double ldSL){bool fm;fm=OrderModify(OrderTicket(),OrderOpenPrice(),ldSL,OrderTakeProfit(),0,CLR_NONE);}

//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);}
////// INDICATOR //////// name: test.mq4
//------------------------------------------------------------------
#property copyright "Tolotra"
//------------------------------------------------------------------

#property indicator_buffers 10
#property indicator_color1 Black
#property indicator_color2 DodgerBlue
#property indicator_color3 Yellow
#property indicator_color4 DodgerBlue
#property indicator_color5 Green
#property indicator_color6 Red

#property indicator_color7 Blue
#property indicator_color8 Red
#property indicator_width1 2
#property indicator_width2 1
#property indicator_chart_window

extern int RSI_Period = 21;         //8-25
extern int RSI_Price = 0;           //0-6
extern int Volatility_Band = 34;    //20-40
extern int RSI_Price_Line = 2;      
extern int RSI_Price_Type = 0;      //0-3
extern int Trade_Signal_Line = 7;   
extern int Trade_Signal_Type = 0;   //0-3

double RSIBuf[25000],UpZone[25000],MdZone[25000],DnZone[25000],MaBuf[25000],MbBuf[25000];
//--- buffers
double CrossUp[];
double CrossDown[];
static int cnt=1;

int init()
  {
   IndicatorShortName("shark");
   SetIndexBuffer(0,RSIBuf);
   SetIndexBuffer(1,UpZone);
   SetIndexBuffer(2,MdZone);
   SetIndexBuffer(3,DnZone);
   SetIndexBuffer(4,MaBuf);
   SetIndexBuffer(5,MbBuf);
   
   SetIndexStyle(0,DRAW_NONE); 
   SetIndexStyle(1,DRAW_LINE); 
   SetIndexStyle(2,DRAW_LINE,0,2);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexStyle(4,DRAW_LINE,0,2);
   SetIndexStyle(5,DRAW_LINE,0,2);
   
   SetIndexLabel(0,NULL); 
   SetIndexLabel(1,"VB High"); 
   SetIndexLabel(2,"Market Base Line"); 
   SetIndexLabel(3,"VB Low"); 
   SetIndexLabel(4,"RSI Price Line");
   SetIndexLabel(5,"Trade Signal Line");
 
   SetLevelValue(0,50);
   SetLevelValue(1,68);
   SetLevelValue(2,32);
   SetLevelStyle(STYLE_DOT,1,DimGray);
   
   
   SetIndexStyle(6, DRAW_ARROW,EMPTY);
   SetIndexArrow(6, 233);
   SetIndexBuffer(6, CrossUp);
   
   SetIndexStyle(7, DRAW_ARROW, EMPTY);
   SetIndexArrow(7, 234);
   SetIndexBuffer(7, CrossDown);
   
   
   
   return(0);
  }

int start()
  {
   double MA,RSI[];
   ArrayResize(RSI,Volatility_Band);
   int counted_bars=IndicatorCounted();
   int limit = Bars-counted_bars-1;
   for(int i=limit; i>=0; i--)
   {
      RSIBuf[i] = (iRSI(NULL,0,RSI_Period,RSI_Price,i)); 
      MA = 0;
      for(int x=i; x<i+Volatility_Band; x++) {
         RSI[x-i] = RSIBuf[x];
         MA += RSIBuf[x]/Volatility_Band;
      }
      UpZone[i] = (MA + (1.6185 * StDev(RSI,Volatility_Band)));
      DnZone[i] = (MA - (1.6185 * StDev(RSI,Volatility_Band)));  
      MdZone[i] = ((UpZone[i] + DnZone[i])/2);
      }
   for (i=limit;i>=0;i--)  // ...mod realtime old stmt for (i=limit-1;i>=0;i--) old stmt
      {
       MaBuf[i] = (iMAOnArray(RSIBuf,0,RSI_Price_Line,0,RSI_Price_Type,i));
       MbBuf[i] = (iMAOnArray(RSIBuf,0,Trade_Signal_Line,0,Trade_Signal_Type,i));   
      } 
      
   if((DnZone[1]>MaBuf[1]) && (DnZone[2]<MaBuf[2]))
     {
      CrossDown[1]=High[1];
     }
   if((UpZone[2]>MaBuf[2]) && (UpZone[1]<MaBuf[1]))
     {
      CrossUp[1]=Low[1];
     }
//----
   return(0);
  }
  
double StDev(double& Data[], int Per)
{return(MathSqrt(Variance(Data,Per)));
}
double Variance(double& Data[], int Per)
{double sum, ssum;
  for (int i=0; i<Per; i++)
  {sum += Data[i];
   ssum += MathPow(Data[i],2);
  }
  return((ssum*Per - sum*sum)/(Per*(Per-1)));
}
void make_arrow(int id, int dir, int type, double price)
  {
//---- dirs: 0=up 1=down 2=sideways
   string S2[6]={" buy"," sell"," buyclose"," sellclose"," custom1"," custom2"};

   ObjectCreate("Trade "+id+S2[type],OBJ_ARROW,0,Time[0],0); 
   ObjectCreate("Trade "+id+S2[type]+" ",OBJ_ARROW,0,Time[0],price);
   switch(dir)
    {
     case 0:  ObjectSet("Trade "+id+S2[type],OBJPROP_ARROWCODE,241);
              ObjectSet("Trade "+id+S2[type],OBJPROP_PRICE1,price-avbars()-(type*Point));
              ObjectSet("Trade "+id+S2[type]+" ",OBJPROP_ARROWCODE,172); break;
     case 1:  ObjectSet("Trade "+id+S2[type],OBJPROP_ARROWCODE,242);
              ObjectSet("Trade "+id+S2[type],OBJPROP_PRICE1,price+avbars()+(type*Point));
              ObjectSet("Trade "+id+S2[type]+" ",OBJPROP_ARROWCODE,172); break;
     case 2:  ObjectSet("Trade "+id+S2[type],OBJPROP_ARROWCODE,243);
              ObjectSet("Trade "+id+S2[type],OBJPROP_PRICE1,price-avbars()-(type*Point));
              ObjectSet("Trade "+id+S2[type]+" ",OBJPROP_ARROWCODE,172); break;
     default: Alert("error: make_arrow() Unknown Direction");
    }
   switch(type)
    {
     case 0:  ObjectSet("Trade "+id+S2[type],OBJPROP_COLOR,Lime);
              ObjectSet("Trade "+id+S2[type]+" ",OBJPROP_COLOR,Lime); break;
     case 1:  ObjectSet("Trade "+id+S2[type],OBJPROP_COLOR,Red);
              ObjectSet("Trade "+id+S2[type]+" ",OBJPROP_COLOR,Red); break;
     case 2:  ObjectSet("Trade "+id+S2[type],OBJPROP_COLOR,Yellow);
              ObjectSet("Trade "+id+S2[type]+" ",OBJPROP_COLOR,Yellow); break;
     case 3:  ObjectSet("Trade "+id+S2[type],OBJPROP_COLOR,Orange);
              ObjectSet("Trade "+id+S2[type]+" ",OBJPROP_COLOR,Orange); break;
     case 4:  ObjectSet("Trade "+id+S2[type],OBJPROP_COLOR,Magenta);
              ObjectSet("Trade "+id+S2[type]+" ",OBJPROP_COLOR,Magenta); break;
     case 5:  ObjectSet("Trade "+id+S2[type],OBJPROP_COLOR,Aqua);
              ObjectSet("Trade "+id+S2[type]+" ",OBJPROP_COLOR,Aqua); break;
     default: Alert("error: make_arrow() Unknown Type");
    }
   return;
  }
//+------------------------------------------------------------------+
double avbars()
  {
   double sum=0;
   for(int i=0; i<9; i++)
     sum+=(High[i]-Low[i])/10;
   return(sum);
  }
//+------------------------------------------------------------------+
 
Tolotra Ny:

Hello, I have a problem  with my code, it doesn't place an order when the arrow from the indicators appears

Thanks for replying :-)

Those are my code for INDICATOR and EA


I have solved it

Thanks :-)

This is the correct line code

// I put some parameter //

#define EAName "EA TEST"
#define test "test"
#define CrossUp   6
#define CrossDown 7
............

int start(){
............
//main signal
double ASC2=iCustom(NULL, 0,"test", RSI_Period,RSI_Price,Volatility_Band,RSI_Price_Line,RSI_Price_Type,Trade_Signal_Line,Trade_Signal_Type, CrossDown,i);
double ASC1=iCustom(NULL, 0,"test", RSI_Period,RSI_Price,Volatility_Band,RSI_Price_Line,RSI_Price_Type,Trade_Signal_Line,Trade_Signal_Type, CrossUp,i);
..............
}
Reason: