Wednesday, July 27, 2022

Double Order same time

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

This EA place One BUT and One SELL same time. Before use on real account please test on demo account first. Profit-Loss your own responsitivy .


//|                                                 double-order.mq4 |

//|                        Copyright 2022, MetaQuotes Software Corp. |

//|                                             https://www.mql5.com |

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

#property copyright "Copyright 2022, MetaQuotes Software Corp."

#property link      "https://www.mql5.com"

#property version   "1.00"

#property strict

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

//| Expert initialization function                                   |

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

extern int MagicNumber=10001;


extern double Lots =0.01;


extern double TakeProfit=50;


extern int Slippage=3;


void OnTick()

  {

//---

double lotmax = AccountEquity()/1000;

double speared =DoubleToStr(Ask-Bid,Digits);

double open = 0;

if (Lots > lotmax){

   Alert(" Lotsize more then fund Please set lot size less then " , lotmax); } 

   else{ open = Ask; }



double buyticket = 0;

double lastbuy = 0;

double buytarget = 0;

double buyprofit = 0;

datetime buydate = 0;

double sellticket = 0;

double lastsell = 0;

double selltarget = 0;

double sellprofit = 0;

datetime selldate = 0;

double accountplus1 = AccountBalance()+0.10,Digits;

double askplus1 = Ask+TakeProfit*Point;


int result=0;    

 for (int cntl = 0; cntl < OrdersTotal(); cntl++)

      {

if(OrderSelect(cntl,SELECT_BY_POS,MODE_TRADES) && OrderMagicNumber()== MagicNumber){


if(OrderMagicNumber()== MagicNumber && OrderType() == OP_BUY){

buyticket = OrderTicket();

lastbuy = OrderOpenPrice();

buydate = OrderOpenTime();

buyprofit = OrderProfit();

buytarget = lastbuy+(TakeProfit*Point);}



if(OrderMagicNumber()==  MagicNumber && OrderType() == OP_SELL){

sellticket = OrderTicket();

lastsell = OrderOpenPrice();

selldate = OrderOpenTime();

sellprofit = OrderProfit();

selltarget = lastsell-(TakeProfit*Point);}

        


        }

}

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

double exit = 0;

 

 if(sellprofit > 0 && High[1] < Close[0] && selltarget >= Close[0]){Alert("Close sell and open send new order");

  

  if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)

  { exit = 1;

  result=OrderClose(sellticket,OrderLots(),Ask,Slippage,Red);

  if(result > 0){

   OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,"SELL_Double_Order_EA",MagicNumber,0,Green);

   OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,"SELL_Double_Order_EA",MagicNumber,0,Green);

   }

   }

   

 }

   if(buyprofit > 0  &&  Low[1] > Close[0] && buytarget <= Close[0]){Alert("Close buy and open send new order");

   exit = 2;

   if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)

  { result=OrderClose(buyticket,OrderLots(),Bid,Slippage,Green);

   if(result>0){

   OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,"BUY_Double_Order_EA",MagicNumber,0,Yellow);

   OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,"BUY_Double_Order_EA",MagicNumber,0,Yellow);

   }

   }

 }

   if(lastbuy == 0  &&  lastsell == 0 && OrdersTotal() == 0){Alert("open send new order");

   exit=3;

   OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,"open_send_new_order",MagicNumber,0,Blue);

   OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,"open_send_new_order",MagicNumber,0,Blue);

  }

 // All close

 if((AccountEquity() > AccountBalance() && AccountEquity() > accountplus1 && High[1] < Close[0]) || (AccountEquity() > AccountBalance() &&  AccountEquity() > accountplus1 && Low[1] > Close[0])){Alert("All Close "); 

  if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)

  { 

  OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red);

  }   

 }  

//----------------------------   

  

    Comment(" Account Balance ", AccountBalance() ," accountplus1 ",accountplus1, " Equity " , AccountEquity(), " lotmax ",lotmax, " open ",open , " speard ", speared," ask ",Ask," askplus1 ",askplus1," exit ", exit, 

    "\n boy order ", buyticket, " last buy price " ,lastbuy , " buy target ", buytarget," buy profit ",buyprofit," buy date ",buydate, 

    "\n sell order ",sellticket, " last sell price ",lastsell,"sell target", selltarget," sell profit ",sellprofit," sell date ",selldate);

}

Wednesday, July 20, 2022

Trend Line Indicator for mt4

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

//|                                                        trend.mq4 |

//|                        Copyright 2022, MetaQuotes Software Corp. |

//|                                             https://www.mql5.com |

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

#property copyright "Copyright 2022, MetaQuotes Software Corp."

#property link      "https://www.mql5.com"

#property version   "1.00"

#property strict

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

//| Expert tick function                                             |

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

void OnTick()

  {

int CandlesOnChart=WindowFirstVisibleBar();

int HighestCandle = iHighest(_Symbol,_Period,MODE_HIGH,CandlesOnChart,0);

int lowestCandle = iLowest(_Symbol,_Period,MODE_LOW,CandlesOnChart,0);


ObjectDelete("hightrend");

ObjectCreate(0,"hightrend",OBJ_TREND,0,Time[HighestCandle],

High[HighestCandle],Time[0],High[0]);

   

  ObjectSetInteger(0,"hightrend",OBJPROP_COLOR,Red);

  ObjectSetInteger(0,"hightrend",OBJPROP_STYLE,STYLE_SOLID);

  ObjectSetInteger(0,"hightrend",OBJPROP_WIDTH,1);

  ObjectSetInteger(0,"hightrend",OBJPROP_RAY,true);

  

  ObjectDelete("lowtrend");

ObjectCreate(0,"lowtrend",OBJ_TREND,0,Time[lowestCandle],

Low[lowestCandle],Time[0],Low[0]);

   

  ObjectSetInteger(0,"lowtrend",OBJPROP_COLOR,Yellow);

  ObjectSetInteger(0,"lowtrend",OBJPROP_STYLE,STYLE_SOLID);

  ObjectSetInteger(0,"lowtrend",OBJPROP_WIDTH,1);

  ObjectSetInteger(0,"lowtrend",OBJPROP_RAY,true);

 

  };

  

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


Friday, July 8, 2022

buyticket under development mode

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


//|                                                  2_candle_breakout.mq4 |


//|                        Copyright 2022, MetaQuotes Software Corp. |


//|                                             https://www.mql5.com |


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


#property copyright "Copyright 2022, MetaQuotes Software Corp."


#property link      "https://www.mql5.com"


#property version   "1.00"


#property strict


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


//| Expert initialization function                                   |



 

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


extern int MagicNumber=10001;


extern double Lots =0.01;


extern double TakeProfit=50;


extern int TrailingStop=50;


extern int Slippage=3;


extern int candle=20;


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


//    expert start function


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


int start()


{


double MyPoint=Point;


if(Digits==3 || Digits==5) MyPoint=Point*10;


double high3 = DoubleToStr(High[iHighest(NULL, 0, MODE_HIGH, candle, 1)],Digits);   


double low3 =  DoubleToStr(Low[iLowest(NULL, 0, MODE_LOW, candle, 1)],Digits);



 

double sma9 = DoubleToStr(iMA(_Symbol,_Period,9,0,MODE_SMA,PRICE_CLOSE,0),Digits);



 

double fib23 = DoubleToStr(high3-(high3-low3)*77/100);


double fib77 = DoubleToStr(low3+(high3-low3)*77/100);


double speared =DoubleToStr(Ask-Bid,Digits);


double riskv = MathRound(AccountBalance()-AccountBalance()*98/100);


double StopLoss = riskv/1000;


double buystoploss = DoubleToStr(Bid-StopLoss,Digits);


double sellstoploss = DoubleToStr(Ask+StopLoss,Digits);


double nmax = DoubleToStr(High[iHighest(NULL, 0, MODE_HIGH, 2, 1)],Digits); 


double nmin = DoubleToStr(Low[iLowest(NULL, 0, MODE_LOW, 2, 1)],Digits); 


double sclose = DoubleToStr(nmax+speared,Digits);


double bclose = DoubleToStr(nmin-speared,Digits);


datetime ctime = TimeCurrent();


datetime lastclose = 0;


int c = OrdersHistoryTotal(); 


  int a = OrdersHistoryTotal() - 10;


  int b = OrdersHistoryTotal();


   


  for (c = a;c < b ;c++)


     {


           if (OrderSelect(c,SELECT_BY_POS, MODE_HISTORY) == true)


              {      


                


               //  Alert("orders found"+ OrderTicket() + " " + OrderCloseTime());


             lastclose = OrderCloseTime();


              }


     }


double buyon = 0;


if(Close[0] > nmax){buyon = 1;}


double sellon = 0;


if(Close[0] < nmin){sellon = 1;}


double buyticket = 0;


double sellticket = 0;

for (int cntl = 0; cntl < OrdersTotal(); cntl++)

      {

      if(OrderSelect(cntl,SELECT_BY_POS,MODE_TRADES) && OrderMagicNumber()== MagicNumber){


        if(OrderMagicNumber()== MagicNumber && OrderType() == OP_BUY){


buyticket = OrderTicket();}

        if(OrderMagicNumber()==  MagicNumber && OrderType() == OP_SELL){


sellticket = OrderTicket();}

        


        }

}


double lotsize = OrderLots()+Lots;

double lot = 0;

if(lotsize > 0.00){lot = lotsize;}else{lot = Lots;}

if( TotalOrdersCount() <= 7 )




  {




     int result=0;




//     if((buyon == 1 && OrdersTotal() == 0) || (buyon == 1 && OrderType() == 1 && OrdersTotal() == 1) || (buyon == 1 && OrderType() == 0 && OrdersTotal() <= 5 && OrderOpenPrice() > Ask)) // Here is your open buy rule


if(buyon == 1 && OrdersTotal() <= 7 && ctime > lastclose)


     {




    result=OrderSend(Symbol(),OP_BUY,lot,Ask,Slippage,bclose,0,"2_candle_breakout EA",MagicNumber,0,Blue);




        if(result>0)




        {




         OrderSelect(result,SELECT_BY_TICKET);




         OrderModify(OrderTicket(),OrderOpenPrice(),bclose,OrderTakeProfit(),0,Green);




        }




        return(0);




     }




  //   if((sellon == 1 && OrdersTotal() == 0) || (sellon == 1 && OrderType() == 0 && OrdersTotal() == 1) || (sellon == 1 && OrderType() == 1 && OrdersTotal() >= 1 && OrderOpenPrice() < Bid))  // Here is your open Sell rule


    // if((sellon == 1 && OrdersTotal() == 0) || (sellon == 1 && OrderType() == 0 && OrdersTotal() == 1) || (sellon == 1 && OrderType() == 0 && OrdersTotal() <= 6 && OrderOpenPrice() > Bid))  // Here is your open Sell rule



 

    if(sellon == 1 && OrdersTotal() <= 7 && ctime > lastclose)


     {


        result=OrderSend(Symbol(),OP_SELL,lot,Bid,Slippage,sclose,0,"2_candle_breakout EA",MagicNumber,0,Red);




        if(result>0)




        {                  




         OrderSelect(result,SELECT_BY_TICKET);




        OrderModify(OrderTicket(),OrderOpenPrice(),sclose,OrderTakeProfit(),0,Green);




         }




        return(0);




     }



  }


  


  Comment(" speared " , speared , "candle high " , high3 , " candle low " , low3, " buy signal ", buyon ," sell signal " ,sellon , "fibo 77 ",fib77, " fibo 23 ", fib23 , " amount " , AccountBalance(), " buystop " , buystoploss, "stop " , StopLoss , " type ", OrderType()," orderticket ", OrderTicket(), " nmax " , nmax , " nmin " , nmin , " lastclose " ,lastclose , "\n time ",Time[0],"time" ,ctime ,"\n buy ticket " , buyticket, " sell ticket ", sellticket, " lot ", lot, " lotsize ", lotsize);




  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((OrderOpenPrice() <= Bid && nmin > Close[0]))//here is your close buy rule




              {




                   OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red);




              }




            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((OrderOpenPrice() >= Ask && nmax < Close[0]))// here is your close sell rule




                {




                   OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red);




                }




            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);




}