Little stuck here with Buy Sell Conditions - page 2

 
extern double TakeProfit = 25.0;
extern double TakeProfit2 = 25.0;
extern double TrailingStop = 20.0;
extern double TrailingStop2 = 20.0;
extern double StopLoss = 20.0;
extern double Lots = 1.0;
  
  color Filter10 = 68;
  color Filter12 = 9;
  color Filter6 = 80;
  color Filter4 = 35;
  color Filter2 = 47;
  color Filter9 = 46;
  string Name_EA = "sca";
  int Slippage = 30;
  bool UseSound = FALSE;
  string EAsound = "alert.wav";
  
  #define SIGNAL_BUY   1
#define SIGNAL_SELL  2
int Order ;
extern int PeriodIXO = 15;
int Current;
int BarCount;
extern bool EachTickMode = False;

int init() {
   BarCount = Bars;

  // if (EachTickMode) Current = 0; else Current = 1;

   return(0);
}
void deinit() {
  // Comment("");
}

int start() {
   if (Bars < 100) {
      Print("");
      return (0);
   }
   if (TakeProfit < 10.0) {
      Print("");
      return (0);
   }
   if (TakeProfit2 < 10.0) {
      Print("");
      return (0);
   }
    double MA21_2 = iMA(NULL, 0, 21, 0, MODE_EMA, PRICE_CLOSE, 2);
      double MA200_2 = iMA(NULL, 0, 200, 0, MODE_EMA, PRICE_CLOSE, 2);
      double MA21_1 = iMA(NULL, 0, 21, 0, MODE_EMA, PRICE_CLOSE, 1);
      double MA200_1 = iMA(NULL, 0, 200, 0, MODE_EMA, PRICE_CLOSE, 1);
      double SAR_2 = iSAR(NULL, 0, 0.005, 0.05, 2);
      double SAR_1 = iSAR(NULL, 0, 0.005, 0.05, 1);
      double MACD_1 = iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 2);
      double MACD_2 = iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 1);

      
      double diIXO10=iCustom(NULL,0,"ixoah-indicator",PeriodIXO,0,0);
      double diIXO21=iCustom(NULL,0,"ixoah-indicator",PeriodIXO,1,0);
      double d22=(0);

  if (MA21_2 < MA200_2 && MA21_1 >= MA200_1 && SAR_2 < SAR_1 && MACD_1 < MACD_2 && diIXO10 > d22) Order = SIGNAL_BUY;
     
      
     if (MA21_2 > MA200_2 && MA21_1 <= MA200_1 && SAR_2 > SAR_1 && MACD_1 > MACD_2 && diIXO21< d22) Order = SIGNAL_SELL;
   if (AccountFreeMargin() < 1000.0 * Lots) {
      Print(" Free Margin = ", AccountFreeMargin());
      return (0);
   }
   
   if (OrdersTotal()<20){
    
      if (Order == SIGNAL_SELL ) {
     
    
    
      
      Print("Inside Sell Signal");
      
         OpenSell();
         string name1 = ("arrowdown"+IntegerToString(TimeCurrent()));
    ObjectCreate(name1,OBJ_ARROW,0,TimeCurrent(),MA21_2);
    ObjectSet(name1, OBJPROP_STYLE, STYLE_SOLID);
    ObjectSet(name1, OBJPROP_WIDTH, 5);
    ObjectSet(name1, OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
    ObjectSet(name1, OBJPROP_COLOR, clrRed);
         
         return (0);
      }
      if (Order == SIGNAL_BUY ) {
       Print("Inside Buy Signal");
         OpenBuy();
          string name = ("arrowup"+IntegerToString(TimeCurrent()));
    ObjectCreate(name,OBJ_ARROW,0,TimeCurrent(),MA21_2);
    ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID);
    ObjectSet(name, OBJPROP_WIDTH, 5);
    ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
    ObjectSet(name, OBJPROP_COLOR, clrLime);
         
         
         
        
         return (0);
      }
   }
   TrailingPositionsBuy(TrailingStop);
   TrailingPositionsSell(TrailingStop2);
 
   return (0);
}


bool ExistPositions() {
   for (int l_pos_0 = 0; l_pos_0 < OrdersTotal(); l_pos_0++) {
      if (OrderSelect(l_pos_0, SELECT_BY_POS, MODE_TRADES))
         if (OrderSymbol() == Symbol()) return (TRUE);
   }
   return (FALSE);
}

void TrailingPositionsBuy(int ai_0) {
   for (int l_pos_4 = 0; l_pos_4 < OrdersTotal(); l_pos_4++) {
      if (OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderSymbol() == Symbol()) {
            if (OrderType() == OP_BUY) {
               if (Bid - OrderOpenPrice() > ai_0 * Point)
                  if (OrderStopLoss() < Bid - ai_0 * Point) ModifyStopLoss(Bid - ai_0 * Point);
            }
         }
      }
   }
}

void TrailingPositionsSell(int ai_0) {
   for (int l_pos_4 = 0; l_pos_4 < OrdersTotal(); l_pos_4++) {
      if (OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderSymbol() == Symbol()) {
            if (OrderType() == OP_SELL) {
               if (OrderOpenPrice() - Ask > ai_0 * Point)
                  if (OrderStopLoss() > Ask + ai_0 * Point || OrderStopLoss() == 0.0) ModifyStopLoss(Ask + ai_0 * Point);
            }
         }
      }
   }
}

void ModifyStopLoss(double a_price_0) {
   int l_bool_8 = OrderModify(OrderTicket(), OrderOpenPrice(), a_price_0, OrderTakeProfit(), 0, CLR_NONE);
   if (l_bool_8 && UseSound) PlaySound(EAsound);
}

void OpenBuy() {
   double l_lots_0 = GetSizeLot();
   double l_price_8 = 0;
   double l_price_16 = GetTakeProfitBuy();
   string l_comment_24 = GetCommentForOrder();
   OrderSend(Symbol(), OP_BUY, l_lots_0, Ask, Slippage, l_price_8, l_price_16, l_comment_24, 0, 0, Filter10);
   if (UseSound) PlaySound(EAsound);
}

void OpenSell() {
   double l_lots_0 = GetSizeLot();
   double l_price_8 = 0;
   double l_price_16 = GetTakeProfitSell();
   string l_comment_24 = GetCommentForOrder();
   OrderSend(Symbol(), OP_SELL, l_lots_0, Bid, Slippage, l_price_8, l_price_16, l_comment_24, 0, 0, Filter6);
   if (UseSound) PlaySound(EAsound);
}

string GetCommentForOrder() {
   return (Name_EA);
}

double GetSizeLot() {
   return (Lots);
}

double GetTakeProfitBuy() {
   return (Ask + TakeProfit * Point);
}

double GetTakeProfitSell() {
   return (Bid - TakeProfit2 * Point);
}
 
Vijay Akash T P:
I have made changes according to your advice, Where i am stuck i am unable to find out, still it is not placing sell order

I seriously suspect that this is a de-compiled code... where did you get it from?

I see that after renaming the variables, your buy and sell conditions are consistent (i.e. opposite of each other) - if it opens buy, it should open sell too... if not, check the return value range of "ixoah-indicator", or show a screenshot.

 

Yellow line MA 21

Red Line MA 200

ixoah-indicator value is -4 negative

Now it is perfect sell condition, but it is not putting sell  order. I am stuck somewhere, can you please help me 

Files:
 
//Working as aggressor scalper, example - open buy signal, next is sell signal.
//More info : info@forexsoftwareshop.com
//http://www.forexsoftwareshop.com


//MQL 5 Help asked waiting

extern double TakeProfit = 25.0;
extern double TakeProfit2 = 25.0;
extern double TrailingStop = 20.0;
extern double TrailingStop2 = 20.0;
extern double StopLoss = 20.0;
extern double Lots = 1.0;
  
  color Filter10 = 68;
  color Filter12 = 9;
  color Filter6 = 80;
  color Filter4 = 35;
  color Filter2 = 47;
  color Filter9 = 46;
  string Name_EA = "sca";
  int Slippage = 30;
  bool UseSound = FALSE;
  string EAsound = "alert.wav";
  
  #define SIGNAL_BUY   1
#define SIGNAL_SELL  2
int Order ;
extern int PeriodIXO = 15;
int Current;
int BarCount;
extern bool EachTickMode = False;

int init() {
   BarCount = Bars;

  // if (EachTickMode) Current = 0; else Current = 1;

   return(0);
}
void deinit() {
  // Comment("");
}

int start() {
   if (Bars < 100) {
      Print("");
      return (0);
   }
   if (TakeProfit < 10.0) {
      Print("");
      return (0);
   }
   if (TakeProfit2 < 10.0) {
      Print("");
      return (0);
   }
    double MA21_2 = iMA(NULL, 0, 21, 0, MODE_EMA, PRICE_CLOSE, 2);
      double MA200_2 = iMA(NULL, 0, 200, 0, MODE_EMA, PRICE_CLOSE, 2);
      double MA21_1 = iMA(NULL, 0, 21, 0, MODE_EMA, PRICE_CLOSE, 1);
      double MA200_1 = iMA(NULL, 0, 200, 0, MODE_EMA, PRICE_CLOSE, 1);
      double SAR_2 = iSAR(NULL, 0, 0.005, 0.05, 2);
      double SAR_1 = iSAR(NULL, 0, 0.005, 0.05, 1);
      double MACD_1 = iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 2);
      double MACD_2 = iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 1);

      
      double diIXO10=iCustom(NULL,0,"ixoah-indicator",PeriodIXO,0,0);
      double diIXO21=iCustom(NULL,0,"ixoah-indicator",PeriodIXO,1,0);
      double d22=(0);
      
     

  if (MA21_2 < MA21_1 && MA21_1 >= MA200_1 && SAR_2 < SAR_1 && MACD_1 < MACD_2 && diIXO10 > d22){ Order = SIGNAL_BUY;
  Print(" Buy Ixoah diIXO10 - "+diIXO10);}
     
      
     if (MA21_2 > MA21_1 && MA21_1 <= MA200_1 && SAR_2 > SAR_1 && MACD_1 > MACD_2 && diIXO21< d22) {Order = SIGNAL_SELL;
      Print("Sell Ixoah diIXO21 - "+diIXO21);}
   if (AccountFreeMargin() < 1000.0 * Lots) {
      Print(" Free Margin = ", AccountFreeMargin());
      return (0);
   }
    if (Order == SIGNAL_SELL ) {CloseBuy();}
    if (Order == SIGNAL_BUY ) {CloseSell();}
   
   if (OrdersTotal()<20){
    
      if (Order == SIGNAL_SELL ) {
     
    
    
      
      Print("Inside Sell Signal");
      
         OpenSell();
         string name1 = ("arrowdown"+IntegerToString(TimeCurrent()));
    ObjectCreate(name1,OBJ_ARROW,0,TimeCurrent(),MA21_2);
    ObjectSet(name1, OBJPROP_STYLE, STYLE_SOLID);
    ObjectSet(name1, OBJPROP_WIDTH, 5);
    ObjectSet(name1, OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
    ObjectSet(name1, OBJPROP_COLOR, clrRed);
         
         return (0);
      }
      if (Order == SIGNAL_BUY ) {
       Print("Inside Buy Signal");
         OpenBuy();
          string name = ("arrowup"+IntegerToString(TimeCurrent()));
    ObjectCreate(name,OBJ_ARROW,0,TimeCurrent(),MA21_2);
    ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID);
    ObjectSet(name, OBJPROP_WIDTH, 5);
    ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
    ObjectSet(name, OBJPROP_COLOR, clrLime);
         
         
         
        
         return (0);
      }
   }
   TrailingPositionsBuy(TrailingStop);
   TrailingPositionsSell(TrailingStop2);
 
   return (0);
}


void CloseBuy()
  {
   bool clo;
   while(CheckMarketBuyOrders()>0)
     {
      for(int i=OrdersTotal()-1; i>=0; i--)
        {
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
            //if(OrderMagicNumber()==MagicID)
            if(OrderSymbol()==Symbol() && OrderMagicNumber()==0)
               if(OrderType()==OP_BUY)
                  clo=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,clrAqua);
                  Print("Closed Sell Orders");

        }
     }

  }
//+------------------------------------------------------------------+
void CloseSell()
  {
   bool clo;
   while(CheckMarketSellOrders()>0)
     {
      for(int i=OrdersTotal()-1; i>=0; i--)
        {
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
            //if(OrderMagicNumber()==MagicID)
             if(OrderSymbol()==Symbol() && OrderMagicNumber()==0)
               if(OrderType()==OP_SELL)
                  clo=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,clrAqua);
                  Print("Closed Sell Orders");

        }
     }
  }  
bool ExistPositions() {
   for (int l_pos_0 = 0; l_pos_0 < OrdersTotal(); l_pos_0++) {
      if (OrderSelect(l_pos_0, SELECT_BY_POS, MODE_TRADES))
         if (OrderSymbol() == Symbol()) return (TRUE);
   }
   return (FALSE);
}

int CheckMarketBuyOrders()
  {
   int op=0;

   for(int i=OrdersTotal()-1; i>=0; i--)
      //+------------------------------------------------------------------+
      //|                                                                  |
      //+------------------------------------------------------------------+
     {
      int status=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(OrderMagicNumber()!=0)
         continue;
      if(OrderSymbol()==Symbol())
        {
         if(OrderType()==OP_BUY)
           {
            op++;
           }
        }
     }
   return(op);
  }

int TotalOrder(int ordertype = -1)//ok
{
   int Order = 0;

   for(int i = 0; i < OrdersTotal(); i++)
   {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      {
         if(OrderSymbol() == Symbol() && OrderMagicNumber() == 0)
         {
            if(ordertype == -1) 
               Order++;
            else if(ordertype == OrderType()) 
               Order++;
         }
      }
   }
   
   return(Order);
}

double TotalProfit()
{  
   if(TotalOrder() > 0)
   {
      double profit = 0;
    
      for(int i = 0; i < OrdersTotal(); i++)
      {
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         {
            if(OrderSymbol() == Symbol() && OrderMagicNumber() == 0) profit += OrderProfit()+OrderSwap()+OrderCommission();
         }
      }
   }
   
   return(profit);
}

int CheckMarketSellOrders()
  {
   int op=0;

   for(int i=OrdersTotal()-1; i>=0; i--)
      //+------------------------------------------------------------------+
      //|                                                                  |
      //+------------------------------------------------------------------+
     {
      int status=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(OrderMagicNumber()!=0)
         continue;
      if(OrderSymbol()==Symbol())
        {
         if(OrderType()==OP_SELL)
           {
            op++;
           }
        }
     }
   return(op);
  }

void TrailingPositionsBuy(int ai_0) {
   for (int l_pos_4 = 0; l_pos_4 < OrdersTotal(); l_pos_4++) {
      if (OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderSymbol() == Symbol()) {
            if (OrderType() == OP_BUY) {
               if (Bid - OrderOpenPrice() > ai_0 * Point)
                  if (OrderStopLoss() < Bid - ai_0 * Point) ModifyStopLoss(Bid - ai_0 * Point);
            }
         }
      }
   }
}

void TrailingPositionsSell(int ai_0) {
   for (int l_pos_4 = 0; l_pos_4 < OrdersTotal(); l_pos_4++) {
      if (OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderSymbol() == Symbol()) {
            if (OrderType() == OP_SELL) {
               if (OrderOpenPrice() - Ask > ai_0 * Point)
                  if (OrderStopLoss() > Ask + ai_0 * Point || OrderStopLoss() == 0.0) ModifyStopLoss(Ask + ai_0 * Point);
            }
         }
      }
   }
}

void ModifyStopLoss(double a_price_0) {
   int l_bool_8 = OrderModify(OrderTicket(), OrderOpenPrice(), a_price_0, OrderTakeProfit(), 0, CLR_NONE);
   if (l_bool_8 && UseSound) PlaySound(EAsound);
}

void OpenBuy() {
   double l_lots_0 = GetSizeLot();
   double l_price_8 = Ask-150*Point;
   double l_price_16 = GetTakeProfitBuy();
   string l_comment_24 = GetCommentForOrder();
   OrderSend(Symbol(), OP_BUY, l_lots_0, Ask, Slippage, l_price_8, l_price_16, l_comment_24, 0, 0, Filter10);
   if (UseSound) PlaySound(EAsound);
}

void OpenSell() {
   double l_lots_0 = GetSizeLot();
   double l_price_8 = Bid+150*Point;
   double l_price_16 = GetTakeProfitSell();
   string l_comment_24 = GetCommentForOrder();
   OrderSend(Symbol(), OP_SELL, l_lots_0, Bid, Slippage, l_price_8, l_price_16, l_comment_24, 0, 0, Filter6);
   if (UseSound) PlaySound(EAsound);
}

string GetCommentForOrder() {
   return (Name_EA);
}

double GetSizeLot() {
   return (Lots);
}

double GetTakeProfitBuy() {
   return (Ask + TakeProfit * Point);
}

double GetTakeProfitSell() {
   return (Bid - TakeProfit2 * Point);
}

I figured that out. It is issue with the Max No orders condition. Now I want to know whether my conditions are correct for buy and sell, I want to put buy order 21 cross above 200 and sell order 21 cross below 200. I want to put order only when cross over happens. Kindly help please

 
Vijay Akash T P:

I figured that out. It is issue with the Max No orders condition. Now I want to know whether my conditions are correct for buy and sell, I want to put buy order 21 cross above 200 and sell order 21 cross below 200. I want to put order only when cross over happens. Kindly help please

Check this: https://mql4tradingautomation.com/execute-action-once-per-bar-mql4/.

And I suggest that you stop seeking help here given that your code is de-compiled, and you didn't answer me where you got it form.

How to Execute an Action only Once per Bar with MQL4 - MQL4 Trading Automation
How to Execute an Action only Once per Bar with MQL4 - MQL4 Trading Automation
  • 2019.01.04
  • Luca Spinello
  • mql4tradingautomation.com
When you read about the tick and MQL4 you learned that the tick is a trigger for a portion of code. You also learned that generally there are more ticks happening in a candlestick, whether this is a short or long timeframe. In many cases you may want to execute some code only once in a bar or candlestick. In this article you will see how you...
 
Seng Joo Thio:

Check this: https://mql4tradingautomation.com/execute-action-once-per-bar-mql4/.

And I suggest that you stop seeking help here given that your code is de-compiled, and you didn't answer me where you got it form.

I got it forexfactory member