Thursday, June 20, 2024

RSI using php and mysql database

 For rsi calculation in php and database .

// Step 1: Store Data in Database

store 16 close data in database

// Step 2: Fetch Data from Database

$sqlrsi = "SELECT close FROM $cand ORDER BY id ASC LIMIT 16";

$rdata = $connection->query($sqlrsi);

$closePrices = [];

while($rowrsi = $rdata->fetch_assoc()) {

    $closePrices[] = $rowrsi["close"];

}


// Step 3: Calculate RSI for 14-Period

function calculate_rsi($closePrices, $period = 14) {

    $deltas = [];

    for ($i = 1; $i < count($closePrices); $i++) {

        $deltas[] = $closePrices[$i] - $closePrices[$i - 1];

    }


    $seed = array_slice($deltas, 0, $period);

    $up = 0;

    $down = 0;

    foreach ($seed as $delta) {

        if ($delta >= 0) {

            $up += $delta;

        } else {

            $down += abs($delta);

        }

    }

    $up /= $period;

    $down /= $period;

    $rs = $up / $down;

    $rsi = [100 - 100 / (1 + $rs)];


    for ($i = $period; $i < count($closePrices) - 1; $i++) {

        $delta = $deltas[$i - 1];

        if ($delta > 0) {

            $upval = $delta;

            $downval = 0;

        } else {

            $upval = 0;

            $downval = abs($delta);

        }

        $up = ($up * ($period - 1) + $upval) / $period;

        $down = ($down * ($period - 1) + $downval) / $period;


        $rs = $up / $down;

        $rsi[] = 100 - 100 / (1 + $rs);

    }


    return $rsi;

}


$rsi0 = calculate_rsi($closePrices, 14);


// Output the RSI values

//echo "RSI values: ";

//print_r($rsi);

$rsi = $rsi0["1"];

echo " rsi ". $rsi;

Monday, January 29, 2024

Quantity Calculation for trading

 How to calculation quantity for trading ?

If your fund is INR.100000.

You want to Risk in per trade INR.2000 ( 2% of total fund ).

Current price : 500

Stoploss point : 400

Two method for calculation 

First formula

quantity = risk fund / (current price - stoploss point)

quantity = 2000 / ( 500-400)

quantity = 2000/100

quantity =20


Second formula

Use fund for trade = amount

amount =   risk fund * 100 / 100-stoploss point( current price/100)

amount = 20 / 200000

amount = 200000/20

amount = 10000

quantity =amount / current price


For bank nifty indian exchange

current bank nifty lots size = 15

lots = quantity/15

lot  =  1.33

lot = 1 round you can buy 1 lot in bank nifty

Monday, May 29, 2023

Trading With Three Time Frames

  Determine Main Trend

The largest time frame we consider our main trend – this shows us the big picture of the pair we wanna trade.

For example, on the daily chart, EUR/USD is trading above the 200 SMA which tells you that the main trend is UP.

Determine Current Market Bias

The next time frame down is what we normally look at, and it signals to us the medium-term buy or selling bias.

on the 4-hour  EUR/USD chart must continues bullish trend.

Determine Entry and Exit

The smallest time frame (1-hour ) also trend up then you can find really good entry and exit points.

Multiple Time Frame Combinations

You can use any time frame you like as long as there is enough time difference between them to see a difference in their movement.

You might use:

  • 1-minute, 5-minute, and 30-minute
  • 5-minute, 30-minute, and 4-hour
  • 15-minute, 1-hour, and 4-hour
  • 1-hour, 4-hour, and daily
  • 4-hour, daily, and weekly and so on.

Tuesday, January 3, 2023

Draw a rectangal on your MT4 chart using expert advisory

 Draw a rectangal on your MT4 chart using expert advisory

ObjectsDeleteAll();

ChartSetInteger(ChartID(),CHART_FOREGROUND,0,false);

ObjectCreate(ChartID(),"obj_rect",OBJ_RECTANGLE_LABEL,0,0,0) ;

ObjectSetInteger(ChartID(),"obj_rect",OBJPROP_XDISTANCE,1);

ObjectSetInteger(ChartID(),"obj_rect",OBJPROP_YDISTANCE,10);

ObjectSetInteger(ChartID(),"obj_rect",OBJPROP_BACK,false);

ObjectSetInteger(ChartID(),"obj_rect",OBJPROP_XSIZE,350);

ObjectSetInteger(ChartID(),"obj_rect",OBJPROP_YSIZE,300);

ObjectSetInteger(ChartID(),"obj_rect",OBJPROP_BGCOLOR,Red);

Friday, December 16, 2022

forexpark average order

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

//|                                                       ForexPerk-Copy.mq4 |

//|                        Copyright 2022, MetaQuotes Software Corp. |

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

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

extern int MagicNumber=10001;

extern double Lots =0.01;

extern int Takeprofit=100;

extern int gap = 100;

extern int Slippage=3;

extern double Maxbuyposition=10;

extern double Maxsellposition=10;

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

//| Expert initialization function                                   |

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


int OpenBuyOrders;


int OpenSellOrders;


int total;

 

void OnTick()

 

int speared = SymbolInfoInteger(OrderSymbol(), SYMBOL_SPREAD);

double profit = AccountProfit();  

  OpenBuyOrders=0;


  OpenSellOrders=0;


  total=0;


//Count Pending Stop Orders


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


   {


    if(OrderSelect(i, SELECT_BY_POS)==true)


     {


      if (OrderType()==OP_BUY && OrderSymbol() == Symbol())


        OpenBuyOrders++;


      if (OrderType()==OP_SELL && OrderSymbol() == Symbol())


        OpenSellOrders++;


     }


    total=OpenBuyOrders + OpenSellOrders;


   }

//last close

datetime ctime = Time[0];

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  && OrderMagicNumber()== MagicNumber)

              {      

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

             lastclose = OrderCloseTime();

              }

     }

 //lastprice

 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;

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


      {


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


//buy details

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


buyticket = OrderTicket();


lastbuy = OrderOpenPrice();


buydate = OrderOpenTime();


buyprofit = OrderProfit();

}


//sell details

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


sellticket = OrderTicket();


lastsell = OrderOpenPrice();


selldate = OrderOpenTime();


sellprofit = OrderProfit();

}

}}    

double buygap = lastbuy-gap*Point;

double sellgap = lastsell+gap*Point;

   //signal

string signal="";   

if ((OpenBuyOrders < Maxbuyposition) && (ctime > lastclose) && (ctime > OrderOpenTime()) && (Close[0] > High[1]))

{

//set the signal variable to buy

signal="buy";

}

//buy 2nd

if ((OpenBuyOrders < Maxbuyposition) && (ctime > lastclose) && (ctime > OrderOpenTime())&& (buygap > Ask) && (OrderOpenPrice() > Ask) && (Close[0] > High[1]))

{

//set the signal variable to buy

signal="buy";

}


//if the moving average above the current price

if ((OpenSellOrders < Maxsellposition) && (ctime > lastclose) && (ctime > OrderOpenTime()) &&  (Close[0] < Low[1]))

{

//set the signal variable to sell

signal="sell";

}  

//sell 2nd

if ((OpenSellOrders < Maxsellposition) && (ctime > lastclose) && (ctime > OrderOpenTime()) && (sellgap < Bid) && (OrderOpenPrice() < Bid)  &&  (Close[0] < Low[1]))

{

//set the signal variable to sell

signal="sell";

}   

   //

//average buy

double Lotsb   = 0.0;

   double OrderPriceb = 0.0;

   double LotsPriceb = 0.0;

   double averagebuy = 0.0;

   double buytar = 0.0;

   for (int ba = OrdersTotal() - 1; ba >= 0; ba--)

   {

      OrderSelect(ba, SELECT_BY_POS, MODE_TRADES);

      if (OrderSymbol() == Symbol() && OrderType() == OP_BUY)

      {

         Lotsb = Lotsb + OrderLots();

         LotsPriceb = LotsPriceb + OrderLots()*OrderOpenPrice();


         //Print("Lotsb : ", OrderLots(), "   OrderOpenPrice : ", OrderOpenPrice());

buytar = LotsPriceb/Lotsb+Takeprofit*Point;  

      }

    

   }   

//average sell

double Lotss   = 0.0;

   double OrderPrices = 0.0;

   double LotsPrices = 0.0;

   double averagesell = 0.0;

   double selltar = 0.0;

   for (int sa = OrdersTotal() - 1; sa >= 0; sa--)

   {

      OrderSelect(sa, SELECT_BY_POS, MODE_TRADES);

      if (OrderSymbol() == Symbol() && OrderType() == OP_SELL)

      {

         Lotss = Lotss + OrderLots();

         LotsPrices = LotsPrices + OrderLots()*OrderOpenPrice();


        // Print("Lotss : ", OrderLots(), "   OrderOpenPrice : ", OrderOpenPrice());

selltar = LotsPrices/Lotss-Takeprofit*Point;

      }

      

   }   

//

double buytp = Ask+Takeprofit*Point;

double selltp = Bid-Takeprofit*Point;

//double target = 1.00+(speared*0.01);

   Comment ("Speared",speared , " Equity ",profit," Ask ",Ask, " Bid ",Bid, " buygap ",buygap," sellgap ",sellgap,

   "\n Total buy ",OpenBuyOrders," Total sell ",OpenSellOrders," total ",total," order close ",OrderClosePrice()," order open ",OrderOpenPrice(),

   "\n current time " ,TimeCurrent(), " current open time ",ctime," last closed order ",lastclose, " buytp ",buytp, " selltp ",selltp,

   "\n last buy ",lastbuy, "average buy",averagebuy, " buy tar ",buytar," last sell ",lastsell, "average sell",averagesell," selltar ",selltar,

   "\n The current signal is : ",signal);

 int result=0;

double lots = Lots;//0;

//if(OrdersTotal() == 0){lots = Lots;}else{lots = Lots*(OrdersTotal()+1);}

if ((signal == "buy" && OpenBuyOrders < Maxbuyposition))//Here is your open Buy rule

     {Alert("open buy");

result=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,"100pip EA https://forexwithcandlestick.blogspot.com",MagicNumber,0,Green);

  if(result>0)

        {

         OrderSelect(result,SELECT_BY_TICKET);

         OrderModify(OrderTicket(),OrderOpenPrice(),0,0,0,Red);

        }      

     }

if ((signal == "sell" && OpenSellOrders < Maxsellposition)) //Here is your open Sell rule

     { Alert("open sell");

 result=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,"100pip EA https://forexwithcandlestick.blogspot.com ",MagicNumber,0,Red);

        if(result>0)

        {

         OrderSelect(result,SELECT_BY_TICKET);

         OrderModify(OrderTicket(),OrderOpenPrice(),0,selltp,0,Red);

        }

       

        

     } 

if(Ask < selltar && OrderClosePrice() < selltar)

{

for (int ss = OrdersTotal()-1; ss >= 0; ss--)

{    

if(OrderSelect(ss,SELECT_BY_POS) && OrderType() == OP_SELL && OrderSymbol() == Symbol()){

   ulong orderticket = OrderTicket();

   Print(orderticket);

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

  }



}//order closed end


//

if(Bid > buytar && OrderClosePrice() > buytar)

{

for (int bb = OrdersTotal()-1; bb >= 0; bb--)

{    

if(OrderSelect(bb,SELECT_BY_POS) && OrderType() == OP_BUY && OrderSymbol() == Symbol()){

   ulong orderticketb = OrderTicket();

   Print(orderticketb);

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

  }


}

}//buy closed  

 

 }  

Saturday, November 26, 2022

range trading

this mt4 ea open trade in 14 candles low and high range.

this ea good for 1 hour and biggest chart.

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

//|                                                        range_trading.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


extern int MagicNumber=10002;

extern double Lots =0.01;

extern int TrailingStop=100;

extern int Slippage=3;


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

//| Expert tick function                                             |

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

int start()

  {

string signal="";

  double MyPoint=Point;

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

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

datetime ctime = Time[0];

datetime lastclose = 0;

double sellstoploss = DoubleToStr(High[1]+(High[1]-Low[1]),Digits);

double selltp = DoubleToStr(Low[1]-2*(High[1]-Low[1]),Digits);


double buystoploss = DoubleToStr(Low[1]-(High[1]-Low[1]),Digits);

double buytp = DoubleToStr(High[1]+2*(High[1]-Low[1]),Digits);


//double rsi = iRSI(NULL,0,14,PRICE_CLOSE,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  && OrderMagicNumber()== MagicNumber)

              {      

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

             lastclose = OrderCloseTime();

              }

     }

int tllow =   iLowest(_Symbol,_Period,MODE_LOW,14,0);

int tlhigh =   iHighest(_Symbol,_Period,MODE_HIGH,14,0);

double lowa = Low[tllow];

double higha = High[tlhigh];


if ((Low[2] > lowa) && (Low[1] > lowa) && (Open[2] < Close[2]) && (Open[1] < Close[1]) && (Close[1] > Close[2]) && (Close[0] > High[1]))

{

//set the signal variable to buy

signal="buy";

}

//if the moving average above the current price

if ((High[2] < higha) && (High[1] < higha) && (Open[2] > Close[2]) && (Open[1] > Close[1]) && (Close[1] < Close[2]) && (Close[0] < Low[1]))

{

//set the signal variable to sell

signal="sell";

}    

     

Comment("ASK ",Ask, " BID ",Bid, " SPEARD ", speared , "\n CURRENT TIME ",ctime, " LAST ORDER CLOSED TIME ",lastclose,

"\n The current signal is : ",signal);   

 

  if( TotalOrdersCount()==0)

  {

     int result=0;

if ((signal == "buy" && TotalOrdersCount() ==0))//Here is your open Buy rule

     {

        result=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,buystoploss,0,"range_trading EA https://forexwithcandlestick.blogspot.com",MagicNumber,0,Green);

        if(result>0)

        {         

         OrderSelect(result,SELECT_BY_TICKET);

         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(buystoploss,Digits),0,0,Green);

        }

        return(0);

     }

     //if the fast SMA is now above

if ((signal == "sell" && TotalOrdersCount() ==0)) //Here is your open Sell rule

     {

        result=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,sellstoploss,0,"range_trading EA https://forexwithcandlestick.blogspot.com ",MagicNumber,0,Red);

        if(result>0)

        {

         OrderSelect(result,SELECT_BY_TICKET);

         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(sellstoploss,Digits),0,0,Red);

        }

        return(0);

     }

     

  } 

   ObjectDelete("tpl");

ObjectCreate(0,"tpl",OBJ_HLINE,0,Time[20],

OrderTakeProfit(),Time[1],OrderTakeProfit());

ObjectSetInteger(0,"tpl",OBJPROP_COLOR,Blue);

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

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

//object pivot

   ObjectDelete("SL");

ObjectCreate(0,"SL",OBJ_HLINE ,0,Time[20],

OrderStopLoss(),Time[1],OrderStopLoss());

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

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

ObjectSetInteger(0,"SL",OBJPROP_WIDTH,3);


   ObjectDelete("trendlow");

ObjectCreate(0,"trendlow",OBJ_TREND,0,Time[14],

lowa,Time[0],lowa);

ObjectSetInteger(0,"trendlow",OBJPROP_COLOR,White);

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

ObjectSetInteger(0,"trendlow",OBJPROP_WIDTH,3);


   ObjectDelete("trendhigh");

ObjectCreate(0,"trendhigh",OBJ_TREND,0,Time[14],

higha,Time[0],higha);

ObjectSetInteger(0,"trendhigh",OBJPROP_COLOR,Green);

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

ObjectSetInteger(0,"trendhigh",OBJPROP_WIDTH,3);


  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((OrderProfit() > 0 && Low[1]>Bid)) //here is your close buy rule

              { Alert("close buy",Bid);

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

              }


            if(TrailingStop>0)

              {               

               if(Bid-OrderOpenPrice()>MyPoint*TrailingStop)

                 {

                  if(OrderStopLoss()<Bid-MyPoint*TrailingStop && OrderStopLoss()<Bid-buystoploss)

                    {

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

                     return(0);

                    }

                 }

              }

           }

         else

           {

           if((OrderProfit() > 0 && High[1]<Ask)) // here is your close sell rule

                {

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

                }


            if(TrailingStop>0)

              {               

               if((OrderOpenPrice()-Ask)>(MyPoint*TrailingStop))

                 {

                  if((OrderStopLoss()>(Ask+MyPoint*TrailingStop && OrderStopLoss()> sellstoploss)) || (OrderStopLoss()==0))

                    {

                     OrderModify(OrderTicket(),OrderOpenPrice(),sellstoploss,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);

Wednesday, November 9, 2022

pivot and poc for 1 hour timeframe

pivot and poc for 1 hour timeframe

ea calculate pivot weakly

poc = ( 20 candle high - 20 candle low )/2


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

//|                                                        pivot-poc.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


extern int MagicNumber=10002;

extern double Lots =0.01;

extern int TrailingStop=1;

extern int Slippage=3;


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

//| Expert tick function                                             |

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

int start()

  {

string signal="";

  double MyPoint=Point;

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

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

datetime ctime = Time[0];

datetime lastclose = 0;

double sellstoploss = DoubleToStr(High[1]+(High[1]-Low[1]),Digits);

double selltp = DoubleToStr(Low[1]-2*(High[1]-Low[1]),Digits);


double buystoploss = DoubleToStr(Low[1]-(High[1]-Low[1]),Digits);

double buytp = DoubleToStr(High[1]+2*(High[1]-Low[1]),Digits);


//double rsi = iRSI(NULL,0,14,PRICE_CLOSE,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  && OrderMagicNumber()== MagicNumber)

              {      

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

             lastclose = OrderCloseTime();

              }

     }

int LowestCandle =   iLowest(_Symbol,_Period,MODE_LOW,20,0);

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

double poc = Low[LowestCandle]+(High[HighestCandle]-Low[LowestCandle])/2;

double MH =  iHigh(_Symbol,PERIOD_W1,1); //iHigh(_Symbol,PERIOD_MN1,1);  

double ML =  iLow(_Symbol,PERIOD_W1,1); //iLow(_Symbol,PERIOD_MN1,1);  

double MC =  iClose(_Symbol,PERIOD_W1,1); //iClose(_Symbol,PERIOD_MN1,1);

double pivot = (MH+ML+MC)/3;  

  if ((Open[1] < Close[1]) && (Close[0] > High[1]) && (Close[1] > pivot) && (Close[1] > poc))

{

//set the signal variable to buy

signal="buy";

}

//if the moving average above the current price

if ((Open[1] > Close[1]) && (Close[0] < Low[1]) && (Close[1] < pivot) && (Close[1] < poc))

{

//set the signal variable to sell

signal="sell";

}    

     

Comment("ASK ",Ask, " BID ",Bid, " SPEARD ", speared , "\n CURRENT TIME ",ctime, " LAST ORDER CLOSED TIME ",lastclose,

"\n PIVOT POINT ",pivot , " POC POINT ",poc ,"\n The current signal is : ",signal , "",PERIOD_CURRENT );   

 

  if( TotalOrdersCount()==0)

  {

     int result=0;

if ((signal == "buy" && TotalOrdersCount() ==0))//Here is your open Buy rule

     {

        result=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,buystoploss,0,"Pivot-POC EA https://forexwithcandlestick.blogspot.com",MagicNumber,0,Green);

        if(result>0)

        {         

         OrderSelect(result,SELECT_BY_TICKET);

         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(buystoploss,Digits),0,0,Green);

        }

        return(0);

     }

     //if the fast SMA is now above

if ((signal == "sell" && TotalOrdersCount() ==0)) //Here is your open Sell rule

     {

        result=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,sellstoploss,0,"Pivot-POC EA https://forexwithcandlestick.blogspot.com ",MagicNumber,0,Red);

        if(result>0)

        {

         OrderSelect(result,SELECT_BY_TICKET);

         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(sellstoploss,Digits),0,0,Red);

        }

        return(0);

     }

     

  } 

   ObjectDelete("tpl");

ObjectCreate(0,"tpl",OBJ_HLINE,0,Time[20],

OrderTakeProfit(),Time[1],OrderTakeProfit());

ObjectSetInteger(0,"tpl",OBJPROP_COLOR,Blue);

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

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

//object pivot

   ObjectDelete("PIVOTL");

ObjectCreate(0,"PIVOTL",OBJ_HLINE ,0,Time[20],

pivot,Time[1],pivot);

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

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

ObjectSetInteger(0,"PIVOTL",OBJPROP_WIDTH,3);


   ObjectDelete("POC");

ObjectCreate(0,"POC",OBJ_HLINE,0,Time[20],

poc,Time[1],poc);

ObjectSetInteger(0,"POC",OBJPROP_COLOR,White);

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

ObjectSetInteger(0,"POC",OBJPROP_WIDTH,3);


  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((OrderProfit() > 0 && Low[1]>Bid)) //here is your close buy rule

              { Alert("close buy",Bid);

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

              }


            if(TrailingStop>0)

              {               

               if(Bid-OrderOpenPrice()>MyPoint*TrailingStop)

                 {

                  if(OrderStopLoss()<Bid-MyPoint*TrailingStop && OrderStopLoss()<Bid-buystoploss)

                    {

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

                     return(0);

                    }

                 }

              }

           }

         else

           {

           if((OrderProfit() > 0 && High[1]<Ask)) // here is your close sell rule

                {

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

                }


            if(TrailingStop>0)

              {               

               if((OrderOpenPrice()-Ask)>(MyPoint*TrailingStop))

                 {

                  if((OrderStopLoss()>(Ask+MyPoint*TrailingStop && OrderStopLoss()> sellstoploss)) || (OrderStopLoss()==0))

                    {

                     OrderModify(OrderTicket(),OrderOpenPrice(),sellstoploss,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);

Tuesday, October 4, 2022

range trade

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

//|                                                     00000000.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 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 buystop = 0;

double sellstop = 0;

double buytp = 0;

double selltp =0;

double buylots=0;

double selllots=0;

double buysl=0;

double sellsl=0;

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


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

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


//buy details

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


buyticket = OrderTicket();


lastbuy = OrderOpenPrice();


buydate = OrderOpenTime();


buyprofit = OrderProfit();

buytp = OrderTakeProfit();

buysl = OrderStopLoss();

buylots = OrderLots();}


//buystop details

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


buystop = OrderTicket();

}

//sell details

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


sellticket = OrderTicket();


lastsell = OrderOpenPrice();


selldate = OrderOpenTime();


sellprofit = OrderProfit();


selltp = OrderTakeProfit();

sellsl = OrderStopLoss();

selllots = OrderLots();}

}

//sellstop details

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


sellstop = OrderTicket();

}

}

double lotsb = DoubleToStr(buylots*1.5,2);

double lotss = DoubleToStr(selllots*1.5,2);

double accountplus2 = AccountProfit();

if(OrdersTotal() == 0){

OrderSend(Symbol(),OP_BUY,0.01,Ask,Slippage,Ask-0.003,Ask+0.002,"SELL_Double_Order_EA",MagicNumber,0,Green);

OrderSend(Symbol(),OP_SELLSTOP,0.02,Ask-0.001,Slippage,Ask+0.002,Ask-0.003,"SELL_Double_Order_EA",MagicNumber,0,Blue);

}

double pending =0;

if(buyticket < 1 && sellticket < 1){

pending = 1;

 OrderDelete(buystop);

 OrderDelete(sellstop);

}

double pending1 =0;

if(buystop < 1 && sellstop < 1){

pending1 = 1;

if(selldate > buydate){

OrderSend(Symbol(),OP_BUYSTOP,lotss,lastbuy,Slippage,buysl,buytp,"SELL_Double_Order_EA",MagicNumber,0,Blue);

}

if(buydate > selldate){

OrderSend(Symbol(),OP_SELLSTOP,lotsb,lastsell,Slippage,sellsl,selltp,"SELL_Double_Order_EA",MagicNumber,0,Blue);

}

}


Comment(" Account Balance ", AccountBalance() ," Equity " , AccountEquity(), " speard ", speared," ask ",Ask,

    "\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, " aplus2 ",accountplus2, " order count ",OrdersTotal(),

    "\n buystop ",buystop , " sellstop ",sellstop, " pending ",pending , " buytp ",buytp, " sell tp ",selltp,

    "\n buylots ",buylots," lotsb ", lotsb," buysl ",buysl, " selllots ",selllots," lotss ", lotss," sell sl ",sellsl);

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

  }


Friday, September 16, 2022

last candle breakeout

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

//|                                                       last-candle-breakeout.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

extern int MagicNumber=10001;

extern double Lots =0.01;

extern int TrailingStop=1;

extern int Slippage=3;

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

//| Expert function                                             |

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

int start()

  {

string signal="";

  double MyPoint=Point;

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

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

datetime ctime = Time[0];

datetime lastclose = 0;

double sellstoploss = DoubleToStr(High[1]+(High[1]-Low[1]),Digits);

double buystoploss = DoubleToStr(Low[1]-(High[1]-Low[1]),Digits);

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  && OrderMagicNumber()== MagicNumber)

              {      

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

             lastclose = OrderCloseTime();

              }

     }

  if ((Open[2] > Close[2] && Open[1] < Close[1]) && (Low[1] > Low[2]) && (Close[0] > High[1]))

{

//set the signal variable to buy

signal="buy";

}

if ((Open[2] < Close[2] && Open[1] > Close[1]) && (High[1] < High[2]) && (Close[0] < Low[1]))

{

//set the signal variable to sell

signal="sell";

}       

Comment("Ask ",Ask, " bid ",Bid, " speard ", speared , " ctime ",ctime, " lastclose ",lastclose, "\n last high ",High[1],"buy stop ",buystoploss, " sell stop ",sellstoploss,

"\n The current signal is : ",signal );   

 

  if( TotalOrdersCount() ==0)

  {

     int result=0;

if ((signal == "buy" && TotalOrdersCount() ==0))//Here is your open Buy rule

     {

        result=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,buystoploss,0,"New Candle EA https://forexwithcandlestick.blogspot.com",MagicNumber,0,Green);

        if(result>0)

        {         

         OrderSelect(result,SELECT_BY_TICKET);

         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(buystoploss,Digits),0,0,Green);

        }

        return(0);

     }

     if ((signal == "sell" && TotalOrdersCount() <=3)) //Here is your open Sell rule

     {

        result=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,sellstoploss,0,"New Canlde EA https://forexwithcandlestick.blogspot.com ",MagicNumber,0,Red);

        if(result>0)

        {

         OrderSelect(result,SELECT_BY_TICKET);

         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(sellstoploss,Digits),0,0,Red);

        }

        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((OrderProfit() > 0 && Low[1]>Bid)) //here is your close buy rule

              { Alert("close buy",Bid);

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

              }


            if(TrailingStop>0)

              {               

               if(Bid-OrderOpenPrice()>MyPoint*TrailingStop)

                 {

                  if(OrderStopLoss()<Bid-MyPoint*TrailingStop)

                    {

                    // OrderModify(OrderTicket(),OrderOpenPrice(),buystoploss,OrderTakeProfit(),0,Green);

                     return(0);

                    }

                 }

              }

           }

         else

           {

           if((OrderProfit() > 0 && High[1]<Ask)) // here is your close sell rule

                {

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

                }


            if(TrailingStop>0)

              {               

               if((OrderOpenPrice()-Ask)>(MyPoint*TrailingStop))

                 {

                  if((OrderStopLoss()>(Ask+MyPoint*TrailingStop)) || (OrderStopLoss()==0))

                    {

                   //  OrderModify(OrderTicket(),OrderOpenPrice(),sellstoploss,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);

}

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


Thursday, September 15, 2022

count all open order in mt4

int OpenBuyOrders;

int OpenSellOrders;

int total;


int start()

{

  OpenBuyOrders=0;

  OpenSellOrders=0;

  total=0;


//Count Pending Stop Orders

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

   {

    if(OrderSelect(i, SELECT_BY_POS)==true)

     {

      if (OrderType()==OP_BUY)

        OpenBuyOrders++;

      if (OrderType()==OP_SELL)

        OpenSellOrders++;

     }

    total=OpenBuyOrders + OpenSellOrders;

   }

   Comment ("buy_stop=",OpenBuyOrders," sell_stop=",OpenSellOrders," total=",total);

}

 

Wednesday, September 14, 2022

close all orders in mt4 script

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

//|                                            close-all-orders.mq4  |

//|                                  Copyright © 2005  |

//|                                       Custom Metatrader Systems. |

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


#property copyright "Copyright © 2005"

int start()

{

  int total = OrdersTotal();

  for(int i=total-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), 5, Red );

                          break;

      

      //Close opened short positions

      case OP_SELL      : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );

                          break;


      //Close pending orders

      case OP_BUYLIMIT  :

      case OP_BUYSTOP   :

      case OP_SELLLIMIT :

      case OP_SELLSTOP  : result = OrderDelete( OrderTicket() );

    }

    

    if(result == false)

    {

      Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );

      Sleep(3000);

    }  

  }

  

  return(0);

}





Tuesday, September 13, 2022

Daily pivot Point Indicator

 


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


//    expert start function


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


int start()


{


  double MyPoint=Point;


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


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

  double close = iClose(Symbol(),PERIOD_D1,1);


  double low = iLow(Symbol(),PERIOD_D1,1);


  double high = iHigh(Symbol(),PERIOD_D1,1);


  double pivot = (close+low+high)/3;

  double s1 = (pivot*2)-high;

  double s2 = pivot-(high-low);

  double s3 = s1-(high-low);

  double r1 = (pivot*2)-low;

  double r2 = pivot+(high-low);

  double r3 = r1+(high-low);



 ObjectDelete("lowtrend");

//ObjectCreate(0,"lowtrend",OBJ_TREND,0,Time[pivot],Low[pivot],Time[0],Low[0]);

ObjectCreate(0,"lowtrend",OBJ_HLINE,0,Time[0],pivot);

   

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

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

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

//r line

ObjectDelete("r1");

ObjectCreate(0,"r1",OBJ_HLINE,0,Time[0],r1);

   

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

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

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


ObjectDelete("r2");

ObjectCreate(0,"r2",OBJ_HLINE,0,Time[0],r2);

   

  ObjectSetInteger(0,"r2",OBJPROP_COLOR,White);

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

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

  

  ObjectDelete("r3");

ObjectCreate(0,"r3",OBJ_HLINE,0,Time[0],r3);

   

  ObjectSetInteger(0,"r3",OBJPROP_COLOR,Blue);

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

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


//s line

ObjectDelete("s1");

ObjectCreate(0,"s1",OBJ_HLINE,0,Time[0],s1);

   

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

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

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


ObjectDelete("s2");

ObjectCreate(0,"s2",OBJ_HLINE,0,Time[0],s2);

   

  ObjectSetInteger(0,"s2",OBJPROP_COLOR,White);

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

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

  

  ObjectDelete("s3");

ObjectCreate(0,"s3",OBJ_HLINE,0,Time[0],s3);

   

  ObjectSetInteger(0,"s3",OBJPROP_COLOR,Blue);

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

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


// open order line

ObjectDelete("buyline");

//ObjectCreate(0,"lowtrend",OBJ_TREND,0,Time[pivot],Low[pivot],Time[0],Low[0]);

ObjectCreate(0,"buyline",OBJ_VLINE,0,OrderOpenTime(),OrderOpenPrice());

   

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

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

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

 Comment("Pivot ",pivot , "\n S1 ",s1, " S2 ",s2 , " S3",s3 ,"\n R1 ",r1 ," R2 ",r2," R3 ",r3);

  }

  

trendline signal

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

//|                                                new-trendline.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;


int OnInit()

  {

   return(INIT_SUCCEEDED);

  }

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

//| Expert deinitialization function                                 |

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

void OnDeinit(const int reason)

  {

//---

   

  }

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

//| Expert tick function                                             |

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

void OnTick()

  {

//---

int CandlesOnChart=WindowFirstVisibleBar();

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

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

int HighestCandle0 = iHighest(_Symbol,_Period,MODE_HIGH,10,2);

int LowestCandle0 = iLowest(_Symbol,_Period,MODE_LOW,10,2);


ObjectDelete("hightrend");

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

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

   

  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[2],Low[2]);

   

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

  

double bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);

static double lastBid = bid;


string objName = "lowtrend";

string objName1 = "hightrend";

datetime time = TimeCurrent();

double price = ObjectGetValueByTime(0,objName,time);

double priceup = ObjectGetValueByTime(0,objName1,time);

//if(bid >= price && lastBid < price){

if(Close[1] > price && Close[0] > High[1] && Close[0] > High[2]){

Print("we hit line below ok Do buyy");

}

if(Low[1] > Close[0]){

Print("we hit line above ok exit buy");

}

if(Close[1] < priceup && Close[0] < Low[1] && Close[0] < Low[2]){

//if(bid <= price && lastBid > price){

Print("we hit line above ok Do selll");

}

if(High[1] < Close[0]){

Print("we hit line above ok exit sell");

}

lastBid = bid;

Comment("price",price , " priceup ",priceup,"\n bid ",bid, " lastbid ",lastBid);   

  }

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


trend line indicator

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

//|                                                    trendline-indi.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                                   |

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


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

//| Expert tick function                                             |

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

void OnTick()

  {

int HighestCandle = iHighest(_Symbol,_Period,MODE_HIGH,50,10);

int lowestCandle = iLowest(_Symbol,_Period,MODE_LOW,50,10);

int HighestCandle0 = iHighest(_Symbol,_Period,MODE_HIGH,10,10);

int LowestCandle0 = iLowest(_Symbol,_Period,MODE_LOW,10,10);


ObjectDelete("hightrend");

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

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

   

  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[2],Low[2]);

   

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

 Comment("highest",High[HighestCandle],"highest0",High[HighestCandle0],"\n lowestlow ",Low[lowestCandle], " low ",Low[LowestCandle0]);

  }

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


find first red and green candle

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

//|                                                  first-green.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                                   |

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

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

//| Expert tick function                                             |

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

void OnTick()

  {

//---

   int last_Red_candle_index=1;

   int last_Green_candle_index=1;

   static datetime last_Red_candle_time=0;

   static datetime last_Green_candle_time=0;

   static datetime alert_reference_time=0;

   static datetime alert_reference_time0=0;

   while(true)

     {

      if(iOpen(Symbol(),0,last_Red_candle_index)>iClose(Symbol(),0,last_Red_candle_index))

        {

         last_Red_candle_time=iTime(Symbol(),0,last_Red_candle_index);

         break;

        }

      last_Red_candle_index++;

      

    if(iOpen(Symbol(),0,last_Green_candle_index)<iClose(Symbol(),0,last_Green_candle_index))

        {

         last_Green_candle_time=iTime(Symbol(),0,last_Green_candle_index);

         break;

        }

      last_Green_candle_index++;

     }

   if(alert_reference_time!=last_Red_candle_time)

     {

      double red_candle_high=iHigh(Symbol(),0,last_Red_candle_index);

      for(int x=last_Red_candle_index-1;x>0;x--)

        {

         if(iClose(Symbol(),0,x)>red_candle_high)

           {

            Alert("Close Above Red Candle High  "+Symbol(),"    ",TimeToStr(CurTime(),TIME_DATE|TIME_MINUTES),

                  "   M",Period(),"  ",Open[0]);

            alert_reference_time=last_Red_candle_time;

            break;

           }

        }

     }

     

   if(alert_reference_time0 != last_Green_candle_time)

     {

      double green_candle_low=iLow(Symbol(),0,last_Green_candle_index);

      for(int y=last_Green_candle_index-1;y>0;y--)

        {

         if(iClose(Symbol(),0,y)<green_candle_low)

           {

            Alert("Close Above green Candle low  "+Symbol(),"    ",TimeToStr(CurTime(),TIME_DATE|TIME_MINUTES),

                  "   M",Period(),"  ");

            alert_reference_time0 = last_Green_candle_time;

            break;

           }

        }

     }  

//---

      Comment("last red candle",last_Red_candle_time,"last green candle",last_Green_candle_time);

  }

find first red candle

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

//|                                                     find-red.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                                   |

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

int OnInit()

  {

//---

   

//---

   return(INIT_SUCCEEDED);

  }

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

//| Expert deinitialization function                                 |

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

void OnDeinit(const int reason)

  {

//---

   

  }

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

//| Expert tick function                                             |

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

void OnTick()

  {

//---

   int last_red_bar=-1;

double red_high=-1;

for(int i=0;i<Bars-20;i++)

{

if(Close[i]<Open[i])

{

last_red_bar=i;

red_high=High[i];

break;

}

}

double redcandle =0;

for(int i=last_red_bar-1;i>=0 && last_red_bar>0;i--)

{

redcandle = Close[i]>Open[i];

if(High[i]>red_high)

{

if(i==0) Alert("Hihihhi",red_high);

break;

}

}

datetime last_Red_candle_time=0;

 while(true)

     {

      if(iOpen(Symbol(),0,last_red_bar)>iClose(Symbol(),0,last_red_bar))

        {

         last_Red_candle_time=iTime(Symbol(),0,last_red_bar);

         break;

        }}

 int      shift=iBarShift(Symbol(),0,last_Red_candle_time); 

 datetime newtime = iTime(Symbol(),0,shift);      

Comment("red high",red_high, " red candle ",last_Red_candle_time, " newtime ",newtime);

  }

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


fibonancci indicator

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

//|                                                        fibo.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 HighestCandle = iHighest(_Symbol,_Period,MODE_CLOSE,66,0);

int lowestCandle = iLowest(_Symbol,_Period,MODE_CLOSE,66,0);

int HighestCandle0 = iHighest(_Symbol,_Period,MODE_HIGH,10,2);

int LowestCandle0 = iLowest(_Symbol,_Period,MODE_LOW,10,2);


ObjectDelete("hightrend");

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

Close[HighestCandle],Time[lowestCandle],Close[lowestCandle]);

   

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

  

  

 Comment("highest",Close[HighestCandle],"highest0",High[HighestCandle0],"\n lowestlow ",Low[lowestCandle], " low ",Low[LowestCandle0]);

  };

  

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


supertrend

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

//|                                                       S_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


extern int MagicNumber=10001;

extern double Lots =0.01;

extern double StopLoss=0;

extern double TakeProfit=0;

extern int TrailingStop=1;

extern int Slippage=3;


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

//| Expert tick function                                             |

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

int start()

  {

string signal="";

  double MyPoint=Point;

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

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

datetime ctime = Time[0];

datetime lastclose = 0;

double sellstoploss = DoubleToStr(Ask+2*speared,Digits);


double buystoploss = DoubleToStr(Bid-2*speared,Digits);


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  && OrderMagicNumber()== MagicNumber)

              {      

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

             lastclose = OrderCloseTime();

              }

     }

  double uptrend=iCustom(NULL,0,"SuperTrend",10,3.0,0,0);

  double dntrend=iCustom(NULL,0,"SuperTrend",10,3.0,1,0);

      

 if (uptrend!=EMPTY_VALUE && (Open[1] < Close[1]) && (Low[1] > Low[2]) && (Close[0] > High[1]))

{

//set the signal variable to buy

signal="buy";

}

//if the moving average above the current price

if (dntrend!=EMPTY_VALUE && (Open[1] > Close[1]) && (High[1] < High[2]) && (Close[0] < Low[1]))

{

//set the signal variable to sell

signal="sell";

}    

     

Comment("Ask ",Ask, " bid ",Bid, " speard ", speared , " ctime ",ctime, " lastclose ",lastclose, 

"\nuptrend ",uptrend," / ",dntrend,"\n The current signal is : ",signal);   

 

 double TheStopLoss=0;

  double TheTakeProfit=0;

  if( TotalOrdersCount()<=10 )

  {

     int result=0;

if ((signal == "buy" && ctime > lastclose && TotalOrdersCount() ==0))

// || (signal == "buy" && ctime > lastclose && OrderType() == OP_SELL)) // Here is your open buy rule

     {

        result=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,buystoploss,0,"EMA crossover Robot 15 Minutes https://forexwithcandlestick.blogspot.com",MagicNumber,0,Green);

        if(result>0)

        {

         TheStopLoss=buystoploss;

         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 the fast SMA is now above

if ((signal == "sell" && ctime > lastclose && TotalOrdersCount() ==0))

// || (signal == "sell" && ctime > lastclose && OrderType() == OP_BUY)) // Here is your open Sell rule

     {

        result=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,sellstoploss,0,"EMA crossover Robot 15 Minutes https://forexwithcandlestick.blogspot.com ",MagicNumber,0,Red);

        if(result>0)

        {

         TheStopLoss=sellstoploss;

         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((OrderProfit() > 0 && Low[1]>Bid)) //here is your close buy rule

              { Alert("close buy",Bid);

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

              }


            if(TrailingStop>0)

              {               

               if(Bid-OrderOpenPrice()>MyPoint*TrailingStop)

                 {

                  if(OrderStopLoss()<Bid-MyPoint*TrailingStop)

                    {

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

                     return(0);

                    }

                 }

              }

           }

         else

           {

           if((OrderProfit() > 0 && High[1]<Ask)) // here is your close sell rule

                {

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

                }


            if(TrailingStop>0)

              {               

               if((OrderOpenPrice()-Ask)>(MyPoint*TrailingStop))

                 {

                  if((OrderStopLoss()>(Ask+MyPoint*TrailingStop)) || (OrderStopLoss()==0))

                    {

                     OrderModify(OrderTicket(),OrderOpenPrice(),sellstoploss,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);

}

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


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

}