ช่วงเวลาที่เหมาะสมเข้าทำกำไร FOREX

เริ่มโดย admin, พฤศจิกายน 10, 2016, 11:55:29 AM

« หน้าที่แล้ว - ต่อไป »

admin

ช่วงเวลาที่เหมาะสมเข้าทำกำไร
   
   ส่วนช่วงเวลา กราฟ มักจะ ขยับขยาย บิดเมื่อย ยักไหล่ เตรียมวิ่ง มักจะช่วง ตลาดยุโรปเปิด คือ ช่วง เที่ยง ควรมามอง หาจุดเข้า บ่ายหนึ่ง บ่ายสอง และบางครั้ง บ่ายสาม มักจะวิ่ง แต่ส่วนใหญ่จะบ่ายสอง บ่ายสาม กราฟวิ่งเสมอ
   ส่วนตลาดอเมริโกย(กา) หกโมงเย็นก็มา ส่องๆมองๆ เตรียมตัวเทรด ช่วงทุ่ม ถึงสามทุ่มครึ่ง มักจะวิ่ง แต่ที่ชัดเจน สามทุ่ม มักจะ วิ่งเสมอ
   
   ขอขอบคุณที่มา http://forextrader.igetweb.com
   
บจก.สยามเอวีเอส
63 Moo 2 แพรกษาใหม่ เมือง สมุทรปราการ
นำเข้า-จำหน่าย เครื่องจักร cnc มือสองญี่ปุ่น
ติดต่อ คุณ ธนเดช  084-387-2401
EMAIL kiattub@gmail.com
คลิกลิ้งแอดไลน์ได้เลย Line id : boysiamavs
http://line.me/ti/p/~boysiamavs

    

admin

//int Expert_ID =Period();//  copy from forex up and down and sideway
extern double Lot = 0.01; // deposit 1000 usd lot1.0 protit 1411 usd trade 18 times currency EURUSD M30  time 2015-11-01 to 2015-12-16 (46 days)
//extern double MAperiod = 10; // for Exness M30 EURUSD
//extern double K = 20;
//extern double D =4;
//extern double Slow = 4;
//extern int Movingback200 = 200; // old 320
//extern int Movingback100 = 100;
//extern int BBback = 180;
//extern int Movingbackvaryopen = 100;
//extern int Movingbackvaryclose = 100;
//extern int         TP =180;
//extern int         SL = 60;
 


extern double TrailingStop =0;// for time frame M1
extern double Shiftbackopenorder=26;



//  close all code //

// true for open oreder and false for no oopen order

bool  Openbuyandsell =  true ;    // for open oreder and false for no oopen order

// true for open oreder and false for no oopen order

extern double   ProfitTarget     =618.0;             // lot 0.01  set 6.18 usd for 1 order profit 60 days 19%
extern double    LossTarget     = -236.0;              // lot 0.01  set 2.36 usd for 1 order profit 60 days 19%

// closes all orders now//

bool   CloseAllNow      = false;          // closes all orders now//

// closes all orders now//

extern bool   CloseProfitableTradesOnly = false; // closes only profitable trades
extern double ProftableTradeAmount      = 15;     // Only trades above this amount close out
extern double Loss      = -5.0; // loss value for stop loss

//extern bool   ClosePendingOnly = false;          // closes pending orders only
//extern bool   UseAlerts        = false;

void CloseAll()
{
  for(int i=OrdersTotal()-1;i>=0;i--)
{
    OrderSelect(i, SELECT_BY_POS);
    bool result = false;
        if ( OrderType() == OP_BUY)  result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
        if ( OrderType() == OP_SELL)  result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
        if ( OrderType()== OP_BUYSTOP)  result = OrderDelete( OrderTicket() );
        if ( OrderType()== OP_SELLSTOP)  result = OrderDelete( OrderTicket() );
      //  if (UseAlerts) PlaySound("alert.wav");
}
  return;
}
   
//+------------------------------------------------------------------------+
//| cancels all orders that are in profit
//+------------------------------------------------------------------------+
void CloseAllinProfit()
{
  for(int i=OrdersTotal()-1;i>=0;i--)
{
    OrderSelect(i, SELECT_BY_POS);
    bool result = false;
        if ( OrderType() == OP_BUY && OrderProfit()+OrderSwap()>ProftableTradeAmount)  result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
        if ( OrderType() == OP_SELL && OrderProfit()+OrderSwap()>ProftableTradeAmount)  result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
       
            if ( OrderType() == OP_BUY && OrderProfit()+OrderSwap()<Loss)  result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
        if ( OrderType() == OP_SELL && OrderProfit()+OrderSwap()<Loss)  result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
       // if (UseAlerts) PlaySound("alert.wav");
}
  return;
}

//+------------------------------------------------------------------------+
//| cancels all pending orders
//+------------------------------------------------------------------------+
void ClosePendingOrdersOnly()
{
  for(int i=OrdersTotal()-1;i>=0;i--)
{
    OrderSelect(i, SELECT_BY_POS);
    bool result = false;
        if ( OrderType()== OP_BUYSTOP)   result = OrderDelete( OrderTicket() );
        if ( OrderType()== OP_SELLSTOP)  result = OrderDelete( OrderTicket() );
  }
  return;
  }
// close all code //

int start()

{
// close all code //
int      OrdersBUY;
   int      OrdersSELL;
   double   BuyLots, SellLots, BuyProfit, SellProfit;
   
   bool Openorder;
   
   int Expert_ID =Period();
   
//  double Profit1 =ProfitTarget*0.02;
//double Profit3 =ProfitTarget*0.06;

//Print("Symbol",Symbol());

//Print("Order Symbol",OrderSymbol());

//Print("OrderMagicNumber = ",OrderMagicNumber());

//if(OrderMagicNumber()==22222) Print("buy now");


 
   






//+------------------------------------------------------------------+
//  Determine last order price                                       |
//-------------------------------------------------------------------+
      for(int i=0;i<OrdersTotal();i++)
      {
         OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
           if(OrderType()==OP_BUY)  OrdersBUY++;
           if(OrderType()==OP_SELL) OrdersSELL++;
           if(OrderType()==OP_BUY)  BuyLots += OrderLots();
           if(OrderType()==OP_SELL) SellLots += OrderLots();
           if(OrderType() == OP_BUY)  BuyProfit += OrderProfit() + OrderCommission() + OrderSwap();
           if(OrderType() == OP_SELL)  SellProfit += OrderProfit() + OrderCommission() + OrderSwap();
      }               
   
    if(CloseAllNow  ) CloseAll();

   
if(CloseAllNow  )
{ Openorder = false;}
else
{Openorder = true;}

if(Openorder)

{Print ( "Openorder = true "); }
else
{Print ( "Openorder = false "); }



//Print("Period =",Period());

if(Openbuyandsell)

{Print ( "Openbuyandsell = true "); }
else
{Print ( "Openbuyandsell = false "); }




   
   
   
   
   
   
    //closed all time 13.00-20.00
   
    if( Hour()==20 && DayOfWeek()==5 ) CloseAll();
   
//   Print ( "Close all = every friday 20:40 ");
   
//  if(   ( Hour() >0 && Hour() < 6  ) || ( Hour() >9 && Hour()<12 ) ) CloseAll();
   
 
   
    if(CloseProfitableTradesOnly) CloseAllinProfit();
   
  if(BuyProfit+SellProfit >= ProfitTarget  ) CloseAll();
   
   if(BuyProfit+SellProfit <=  LossTarget  ) CloseAll();
   
   // if(ClosePendingOnly) ClosePendingOrdersOnly();
   
   
 
Print("BuyProfit+SellProfit =  ",(BuyProfit+SellProfit));

  Print("OrdersTotal()=",OrdersTotal());   

/////  close all code///   





    //---- Remember the indicator's values for further analysis
    //---- Note that we use the 1st and the 2nd bar. This allows a 1-bar delay
    //---- (i.e., the signal will appear later), but protects against repeated opening and closing
    //---- positions within a bar
    double MACD_1 = iMACD( Symbol(), 0, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, 1 );
    double MACD_S = iMACD( Symbol(), 0, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 1 );


double   Ma1201=iMA(NULL,0,12,0,MODE_SMA,PRICE_CLOSE,1);
double   Ma1226=iMA(NULL,0,12,0,MODE_SMA,PRICE_CLOSE,26);
double   Ma1252=iMA(NULL,0,12,0,MODE_SMA,PRICE_CLOSE,52);

double   Ma12=iMA(NULL,0,12,0,MODE_SMA,PRICE_CLOSE,0);
double     Ma26=iMA(NULL,0,26,0,MODE_SMA,PRICE_CLOSE,0);

double     EMA50=iMA(NULL,0,50,0,MODE_EMA,PRICE_CLOSE,1);
double     EMA100=iMA(NULL,0,100,0,MODE_EMA,PRICE_CLOSE,1);
double     EMA200=iMA(NULL,0,200,0,MODE_EMA,PRICE_CLOSE,1);
double     EMA300=iMA(NULL,0,300,0,MODE_EMA,PRICE_CLOSE,1);
double     EMA400=iMA(NULL,0,400,0,MODE_EMA,PRICE_CLOSE,1);


double      Sto = iStochastic(NULL,0,12,3,3,MODE_SMA,0,MODE_MAIN,  1);// 1st bar
 
     int BarHighest60 = iHighest(NULL,0,MODE_HIGH,60,30);
  double  PHighest60=iHigh(NULL,0,BarHighest60);   
  int BarLowest60 = iLowest(NULL,0,MODE_LOW,60,30);   
   double  PLowest60=iLow(NULL,0,BarLowest60);
     
      int BarHighest26 = iHighest(NULL,0,MODE_HIGH,26,0);
  double  PHighest26=iHigh(NULL,0,BarHighest26);   
  int BarLowest26 = iLowest(NULL,0,MODE_LOW,26,0);   
   double  PLowest26=iLow(NULL,0,BarLowest26);
   
   int BarHighest30 = iHighest(NULL,0,MODE_HIGH,30,0);
  double  PHighest30=iHigh(NULL,0,BarHighest30);   
  int BarLowest30 = iLowest(NULL,0,MODE_LOW,30,0);   
   double  PLowest30=iLow(NULL,0,BarLowest30);
   
   //RSI highest
  double RSIHi60=iRSI(NULL,0,12,PRICE_CLOSE,BarHighest60);
  double RSIHi30=iRSI(NULL,0,12,PRICE_CLOSE,BarHighest30);
   
    //RSI LOwest
  double RSILow60=iRSI(NULL,0,12,PRICE_CLOSE, BarLowest60);   
  double RSILow30=iRSI(NULL,0,12,PRICE_CLOSE,BarLowest30);



  double  PClose15=iClose(NULL,0,15);
double  PClose30=iClose(NULL,0,30);
double  PClose60=iClose(NULL,0,60);

     double  PClose0=iClose(NULL,0,0);
double  PClose1=iClose(NULL,0,1);
double  PClose2=iClose(NULL,0,2);
double  PClose3=iClose(NULL,0,3);

double  POpen1=iOpen(NULL,0,1);
double  POpen2=iOpen(NULL,0,2);
  double  POpen3=iOpen(NULL,0,3);

double PLow1= iLow(NULL,0,1);
double PLow2= iLow(NULL,0,2);
  double PLow3= iLow(NULL,0,3);

double PHigh1= iHigh(NULL,0,1);
  double PHigh2= iHigh(NULL,0,2);
  double PHigh3= iHigh(NULL,0,3);








 
int BarHighest = iHighest(NULL,0,MODE_HIGH,Shiftbackopenorder,12);
  int BariLowest = iLowest(NULL,0,MODE_LOW,Shiftbackopenorder,12); 
   double  PLowest=iLow(NULL,0,BariLowest);
double  PHighest=iHigh(NULL,0,BarHighest);


  int BarHighest240 = iHighest(NULL,0,MODE_HIGH,240,0);
  int BarLowest240 = iLowest(NULL,0,MODE_LOW,240,0); 
   double  PLowest240=iLow(NULL,0,BarLowest240);
double  PHighest240=iHigh(NULL,0,BarHighest240);


// if(PClose0 <= PHighest || PClose0 >= PLowest) Openbuyandsell=false;
   

    int _GetLastError = 0, _OrdersTotal = OrdersTotal();
    //---- search in all open positions
    for ( int z = _OrdersTotal - 1; z >= 0; z -- )
    {
        //---- if an error occurs when searching for a position, go to the next one
        if ( !OrderSelect( z, SELECT_BY_POS ) )
        {
            _GetLastError = GetLastError();
            Print( "OrderSelect( ", z, ", SELECT_BY_POS ) - Error #", _GetLastError );
            continue;
        }

        //---- if a position is closed not for the current symbol, skip it
        if ( OrderSymbol() != Symbol() ) continue;

        //---- if the MagicNumber is not equal to the Expert_ID, skip this position
        if ( OrderMagicNumber() != Expert_ID ) continue;

        //---- if a BUY position is opened,
       
       
       if ( OrderType() == OP_BUY )
        {
       
         if(TrailingStop>0) 
              {                 
               if(Bid-OrderOpenPrice()>Point*TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-Point*TrailingStop)
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
                     return(0);
                    }
                 }
              }
       
       
           //---- close buy position
           
   //  if(Ask==0)
       
  //    if ( EMA50 < EMA100 && EMA100 < EMA200 && MACD_1 <0  )
     
     
     
  if ( PClose1 < EMA200 && MACD_1 <0 )
 

       
   
     
     
   
            {
                //---- close the position
               
                if ( !OrderClose( OrderTicket(), OrderLots(), Bid, 5, Green ) )
                {
                    _GetLastError = GetLastError();
                  //  Alert( "Error OrderClose # ", _GetLastError );
                    return(-1);
                }                                   
                             
             
               
               
               
            }
            //---- if the alert has not changed, exit: it is too early to open a new position
            else
            { return(0); } 
           
           
       
           
        }
        //---- if a SELL position is opened,
        if ( OrderType() == OP_SELL )
        {
         if(TrailingStop>0) 
              {                 
               if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
                 {
                  if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
                     return(0);
                    }
                 }
              }
       
       
       
       
            //---- close sell position
             
     //    if(Ask==0)
           
        //  if  ( EMA50 > EMA100 && EMA100 > EMA200 && MACD_1 >0 )
         
         
           
           if  ( PClose1 > EMA200 && MACD_1 >0 )
           
         
           
           
     
            {
                //---- close the position
                if ( !OrderClose( OrderTicket(), OrderLots(), Ask, 5, Red ) )
                {
                    _GetLastError = GetLastError();
                   // Alert( "Error OrderClose № ", _GetLastError );
                    return(-1);
                }
            }
            //---- if the alert has not changed, exit: it is too early to open a new position
            else return(0);
        }
       
       
   
             
    }



  ///////////   //---- open a BUY positiont/////////////
   
   
     
     
       

     
      if  (  EMA50 > EMA100 && EMA100 > EMA200 && (MACD_1 >0 || MACD_1 > MACD_S)   && Hour() >5 && Hour() < 20&& Openorder && Openbuyandsell  && PClose1 >= PHighest )
   
    {
    //  double slb=Ask-SL*Point;
   
   //   double tpb=Ask+TP*Point;
   
   double stoploss=Ask*0.99618;   // SL percentage   
        double takeprofit=Ask*1.00764; // TP percentage
     
      double sl=Ask-(PHighest-PLowest)/2;
     double tp=Ask+(PHighest-PLowest)*1.236  ;
     
        //---- open a BUY positiont
        if ( OrderSend( Symbol(), OP_BUY, Lot, Ask, 5,stoploss , 0 , "forex candle",
              Expert_ID, 0, Green ) < 0 )
        {
            _GetLastError = GetLastError();
           // Alert( "Error OrderSend # ", _GetLastError );
            return(-1);
        }
        return(0);
    }
   
   
   
    ////////////////---- open a SELL position///////////////////
 
   
 
   
   if ( EMA50 < EMA100 && EMA100 < EMA200 && (MACD_1 <0 || MACD_1 < MACD_S)  && Hour() >5 && Hour()<20 && Openorder  && Openbuyandsell && PClose1 <= PLowest  )
   
    {
   
   // double sls=Bid+SL*Point;
    //  double tps=Bid-TP*Point;
   
     double stop=Bid*1.00382;
     double take=Bid*0.99236;
     
       double s=Bid+(PHighest-PLowest)/2;
      double t=Bid-(PHighest-PLowest)*1.236;
     
        //---- open a SELL position
        if ( OrderSend( Symbol(), OP_SELL, Lot, Bid, 5,stop ,0, "forex candle",
              Expert_ID, 0, Red ) < 0 )
        {
            _GetLastError = GetLastError();
          //  Alert( "Error OrderSend # ", _GetLastError );
            return(-1);
        }
        return(0);
    }

    return(0);
}
บจก.สยามเอวีเอส
63 Moo 2 แพรกษาใหม่ เมือง สมุทรปราการ
นำเข้า-จำหน่าย เครื่องจักร cnc มือสองญี่ปุ่น
ติดต่อ คุณ ธนเดช  084-387-2401
EMAIL kiattub@gmail.com
คลิกลิ้งแอดไลน์ได้เลย Line id : boysiamavs
http://line.me/ti/p/~boysiamavs

    

admin

//int Expert_ID =Period();//  copy from forex up and down and sideway
extern double Lot = 0.01; // deposit 1000 usd lot1.0 protit 1411 usd trade 18 times currency EURUSD M30  time 2015-11-01 to 2015-12-16 (46 days)
//extern double MAperiod = 10; // for Exness M30 EURUSD
//extern double K = 20;
//extern double D =4;
//extern double Slow = 4;
//extern int Movingback200 = 200; // old 320
//extern int Movingback100 = 100;
//extern int BBback = 180;
//extern int Movingbackvaryopen = 100;
//extern int Movingbackvaryclose = 100;
//extern int         TP =180;
//extern int         SL = 60;
 


extern double TrailingStop =0;// for time frame M1
extern double Shiftbackopenorder=26;



//  close all code //

// true for open oreder and false for no oopen order

bool  Openbuyandsell =  true ;    // for open oreder and false for no oopen order

// true for open oreder and false for no oopen order

extern double   ProfitTarget     =618.0;             // lot 0.01  set 6.18 usd for 1 order profit 60 days 19%
extern double    LossTarget     = -236.0;              // lot 0.01  set 2.36 usd for 1 order profit 60 days 19%

// closes all orders now//

bool   CloseAllNow      = false;          // closes all orders now//

// closes all orders now//

extern bool   CloseProfitableTradesOnly = false; // closes only profitable trades
extern double ProftableTradeAmount      = 15;     // Only trades above this amount close out
extern double Loss      = -5.0; // loss value for stop loss

//extern bool   ClosePendingOnly = false;          // closes pending orders only
//extern bool   UseAlerts        = false;

void CloseAll()
{
  for(int i=OrdersTotal()-1;i>=0;i--)
{
    OrderSelect(i, SELECT_BY_POS);
    bool result = false;
        if ( OrderType() == OP_BUY)  result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
        if ( OrderType() == OP_SELL)  result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
        if ( OrderType()== OP_BUYSTOP)  result = OrderDelete( OrderTicket() );
        if ( OrderType()== OP_SELLSTOP)  result = OrderDelete( OrderTicket() );
      //  if (UseAlerts) PlaySound("alert.wav");
}
  return;
}
   
//+------------------------------------------------------------------------+
//| cancels all orders that are in profit
//+------------------------------------------------------------------------+
void CloseAllinProfit()
{
  for(int i=OrdersTotal()-1;i>=0;i--)
{
    OrderSelect(i, SELECT_BY_POS);
    bool result = false;
        if ( OrderType() == OP_BUY && OrderProfit()+OrderSwap()>ProftableTradeAmount)  result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
        if ( OrderType() == OP_SELL && OrderProfit()+OrderSwap()>ProftableTradeAmount)  result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
       
            if ( OrderType() == OP_BUY && OrderProfit()+OrderSwap()<Loss)  result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
        if ( OrderType() == OP_SELL && OrderProfit()+OrderSwap()<Loss)  result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
       // if (UseAlerts) PlaySound("alert.wav");
}
  return;
}

//+------------------------------------------------------------------------+
//| cancels all pending orders
//+------------------------------------------------------------------------+
void ClosePendingOrdersOnly()
{
  for(int i=OrdersTotal()-1;i>=0;i--)
{
    OrderSelect(i, SELECT_BY_POS);
    bool result = false;
        if ( OrderType()== OP_BUYSTOP)   result = OrderDelete( OrderTicket() );
        if ( OrderType()== OP_SELLSTOP)  result = OrderDelete( OrderTicket() );
  }
  return;
  }
// close all code //

int start()

{
// close all code //
int      OrdersBUY;
   int      OrdersSELL;
   double   BuyLots, SellLots, BuyProfit, SellProfit;
   
   bool Openorder;
   
   int Expert_ID =Period();
   
//  double Profit1 =ProfitTarget*0.02;
//double Profit3 =ProfitTarget*0.06;

//Print("Symbol",Symbol());

//Print("Order Symbol",OrderSymbol());

//Print("OrderMagicNumber = ",OrderMagicNumber());

//if(OrderMagicNumber()==22222) Print("buy now");


 
   






//+------------------------------------------------------------------+
//  Determine last order price                                       |
//-------------------------------------------------------------------+
      for(int i=0;i<OrdersTotal();i++)
      {
         OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
           if(OrderType()==OP_BUY)  OrdersBUY++;
           if(OrderType()==OP_SELL) OrdersSELL++;
           if(OrderType()==OP_BUY)  BuyLots += OrderLots();
           if(OrderType()==OP_SELL) SellLots += OrderLots();
           if(OrderType() == OP_BUY)  BuyProfit += OrderProfit() + OrderCommission() + OrderSwap();
           if(OrderType() == OP_SELL)  SellProfit += OrderProfit() + OrderCommission() + OrderSwap();
      }               
   
    if(CloseAllNow  ) CloseAll();

   
if(CloseAllNow  )
{ Openorder = false;}
else
{Openorder = true;}

if(Openorder)

{Print ( "Openorder = true "); }
else
{Print ( "Openorder = false "); }



//Print("Period =",Period());

if(Openbuyandsell)

{Print ( "Openbuyandsell = true "); }
else
{Print ( "Openbuyandsell = false "); }




   
   
   
   
   
   
    //closed all time 13.00-20.00
   
    if( Hour()==20 && DayOfWeek()==5 ) CloseAll();
   
//   Print ( "Close all = every friday 20:40 ");
   
//  if(   ( Hour() >0 && Hour() < 6  ) || ( Hour() >9 && Hour()<12 ) ) CloseAll();
   
 
   
    if(CloseProfitableTradesOnly) CloseAllinProfit();
   
  if(BuyProfit+SellProfit >= ProfitTarget  ) CloseAllNow      = true;
   
   if(BuyProfit+SellProfit <=  LossTarget  ) CloseAllNow      = true;
   
   // if(ClosePendingOnly) ClosePendingOrdersOnly();
   
   
 
Print("BuyProfit+SellProfit =  ",(BuyProfit+SellProfit));

  Print("OrdersTotal()=",OrdersTotal());   

/////  close all code///   





    //---- Remember the indicator's values for further analysis
    //---- Note that we use the 1st and the 2nd bar. This allows a 1-bar delay
    //---- (i.e., the signal will appear later), but protects against repeated opening and closing
    //---- positions within a bar
    double MACD_1 = iMACD( Symbol(), 0, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, 1 );
    double MACD_S = iMACD( Symbol(), 0, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 1 );


double   Ma1201=iMA(NULL,0,12,0,MODE_SMA,PRICE_CLOSE,1);
double   Ma1226=iMA(NULL,0,12,0,MODE_SMA,PRICE_CLOSE,26);
double   Ma1252=iMA(NULL,0,12,0,MODE_SMA,PRICE_CLOSE,52);

double   Ma12=iMA(NULL,0,12,0,MODE_SMA,PRICE_CLOSE,0);
double     Ma26=iMA(NULL,0,26,0,MODE_SMA,PRICE_CLOSE,0);

double     EMA50=iMA(NULL,0,50,0,MODE_EMA,PRICE_CLOSE,1);
double     EMA100=iMA(NULL,0,100,0,MODE_EMA,PRICE_CLOSE,1);
double     EMA200=iMA(NULL,0,200,0,MODE_EMA,PRICE_CLOSE,1);
double     EMA300=iMA(NULL,0,300,0,MODE_EMA,PRICE_CLOSE,1);
double     EMA400=iMA(NULL,0,400,0,MODE_EMA,PRICE_CLOSE,1);


double      Sto = iStochastic(NULL,0,12,3,3,MODE_SMA,0,MODE_MAIN,  1);// 1st bar
 
     int BarHighest60 = iHighest(NULL,0,MODE_HIGH,60,30);
  double  PHighest60=iHigh(NULL,0,BarHighest60);   
  int BarLowest60 = iLowest(NULL,0,MODE_LOW,60,30);   
   double  PLowest60=iLow(NULL,0,BarLowest60);
     
      int BarHighest26 = iHighest(NULL,0,MODE_HIGH,26,0);
  double  PHighest26=iHigh(NULL,0,BarHighest26);   
  int BarLowest26 = iLowest(NULL,0,MODE_LOW,26,0);   
   double  PLowest26=iLow(NULL,0,BarLowest26);
   
   int BarHighest30 = iHighest(NULL,0,MODE_HIGH,30,0);
  double  PHighest30=iHigh(NULL,0,BarHighest30);   
  int BarLowest30 = iLowest(NULL,0,MODE_LOW,30,0);   
   double  PLowest30=iLow(NULL,0,BarLowest30);
   
   //RSI highest
  double RSIHi60=iRSI(NULL,0,12,PRICE_CLOSE,BarHighest60);
  double RSIHi30=iRSI(NULL,0,12,PRICE_CLOSE,BarHighest30);
   
    //RSI LOwest
  double RSILow60=iRSI(NULL,0,12,PRICE_CLOSE, BarLowest60);   
  double RSILow30=iRSI(NULL,0,12,PRICE_CLOSE,BarLowest30);



  double  PClose15=iClose(NULL,0,15);
double  PClose30=iClose(NULL,0,30);
double  PClose60=iClose(NULL,0,60);

     double  PClose0=iClose(NULL,0,0);
double  PClose1=iClose(NULL,0,1);
double  PClose2=iClose(NULL,0,2);
double  PClose3=iClose(NULL,0,3);

double  POpen1=iOpen(NULL,0,1);
double  POpen2=iOpen(NULL,0,2);
  double  POpen3=iOpen(NULL,0,3);

double PLow1= iLow(NULL,0,1);
double PLow2= iLow(NULL,0,2);
  double PLow3= iLow(NULL,0,3);

double PHigh1= iHigh(NULL,0,1);
  double PHigh2= iHigh(NULL,0,2);
  double PHigh3= iHigh(NULL,0,3);








 
int BarHighest = iHighest(NULL,0,MODE_HIGH,Shiftbackopenorder,12);
  int BariLowest = iLowest(NULL,0,MODE_LOW,Shiftbackopenorder,12); 
   double  PLowest=iLow(NULL,0,BariLowest);
double  PHighest=iHigh(NULL,0,BarHighest);


  int BarHighest240 = iHighest(NULL,0,MODE_HIGH,240,0);
  int BarLowest240 = iLowest(NULL,0,MODE_LOW,240,0); 
   double  PLowest240=iLow(NULL,0,BarLowest240);
double  PHighest240=iHigh(NULL,0,BarHighest240);



  if(  PClose1 > EMA400 || PClose1 < EMA400  )
  { CloseAllNow      = false;
   Openbuyandsell = true ;
  }




// if(PClose0 <= PHighest || PClose0 >= PLowest) Openbuyandsell=false;
   

    int _GetLastError = 0, _OrdersTotal = OrdersTotal();
    //---- search in all open positions
    for ( int z = _OrdersTotal - 1; z >= 0; z -- )
    {
        //---- if an error occurs when searching for a position, go to the next one
        if ( !OrderSelect( z, SELECT_BY_POS ) )
        {
            _GetLastError = GetLastError();
            Print( "OrderSelect( ", z, ", SELECT_BY_POS ) - Error #", _GetLastError );
            continue;
        }

        //---- if a position is closed not for the current symbol, skip it
        if ( OrderSymbol() != Symbol() ) continue;

        //---- if the MagicNumber is not equal to the Expert_ID, skip this position
        if ( OrderMagicNumber() != Expert_ID ) continue;

        //---- if a BUY position is opened,
       
       
       if ( OrderType() == OP_BUY )
        {
       
         if(TrailingStop>0) 
              {                 
               if(Bid-OrderOpenPrice()>Point*TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-Point*TrailingStop)
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
                     return(0);
                    }
                 }
              }
       
       
           //---- close buy position
           
     if(Ask==0)
   
 
       
  //   if ( EMA50 < EMA100 && EMA100 < EMA200 && MACD_1 <0  )
     
     
     
// if ( EMA50 < EMA100 && MACD_1 <0 )


       
   
     
     
   
            {
       
         Openbuyandsell = false ;
          CloseAllNow      = true; 
           
                //---- close the position
               
                if ( !OrderClose( OrderTicket(), OrderLots(), Bid, 5, Green ) )
                {
                    _GetLastError = GetLastError();
                  //  Alert( "Error OrderClose # ", _GetLastError );
                    return(-1);
                }                                   
                             
             
               
               
               
            }
            //---- if the alert has not changed, exit: it is too early to open a new position
            else
            { return(0); } 
           
           
       
           
        }
        //---- if a SELL position is opened,
        if ( OrderType() == OP_SELL )
        {
         if(TrailingStop>0) 
              {                 
               if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
                 {
                  if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
                     return(0);
                    }
                 }
              }
       
       
       
       
            //---- close sell position
             
        if(Ask==0)
     
   
           
       //  if  ( EMA50 > EMA100 && EMA100 > EMA200 && MACD_1 >0 )
         
         
           
       //    if  ( EMA50 > EMA100 && MACD_1 >0 )
           
         
           
           
     
            {
           
             Openbuyandsell = false ;
           
             CloseAllNow      = true;   
             
             
                //---- close the position
                if ( !OrderClose( OrderTicket(), OrderLots(), Ask, 5, Red ) )
                {
                    _GetLastError = GetLastError();
                   // Alert( "Error OrderClose № ", _GetLastError );
                    return(-1);
                }
            }
            //---- if the alert has not changed, exit: it is too early to open a new position
            else return(0);
        }
       
       
   
             
    }



  ///////////   //---- open a BUY positiont/////////////
   
   
     
     
       

     
      if  (  EMA50 > EMA100 && EMA100 > EMA200 && (MACD_1 >0 || MACD_1 > MACD_S)   && Hour() >5 && Hour() < 20&& Openorder && Openbuyandsell && PClose1 >= PHighest  )
   
    {
   
     Sleep(1000);
    //  double slb=Ask-SL*Point;
   
   //   double tpb=Ask+TP*Point;
   
   double stoploss=Ask*0.99618;   // SL percentage   
        double takeprofit=Ask*1.00764; // TP percentage
     
      double sl=Ask-(PHighest-PLowest)/2;
     double tp=Ask+(PHighest-PLowest)*1.236  ;
     
        //---- open a BUY positiont
        if ( OrderSend( Symbol(), OP_BUY, Lot, Ask, 5,stoploss , 0 , "forex candle",
              Expert_ID, 0, Green ) < 0 )
        {
            _GetLastError = GetLastError();
           // Alert( "Error OrderSend # ", _GetLastError );
            return(-1);
        }
        return(0);
    }
   
   
   
    ////////////////---- open a SELL position///////////////////
 
   
 
   
   if ( EMA50 < EMA100 && EMA100 < EMA200 && (MACD_1 <0 || MACD_1 < MACD_S)  && Hour() >5 && Hour()<20 && Openorder  && Openbuyandsell && PClose1 <= PLowest )
   
    {
   
     Sleep(1000);
   
   // double sls=Bid+SL*Point;
    //  double tps=Bid-TP*Point;
   
     double stop=Bid*1.00382;
     double take=Bid*0.99236;
     
       double s=Bid+(PHighest-PLowest)/2;
      double t=Bid-(PHighest-PLowest)*1.236;
     
        //---- open a SELL position
        if ( OrderSend( Symbol(), OP_SELL, Lot, Bid, 5,stop ,0, "forex candle",
              Expert_ID, 0, Red ) < 0 )
        {
            _GetLastError = GetLastError();
          //  Alert( "Error OrderSend # ", _GetLastError );
            return(-1);
        }
        return(0);
    }

    return(0);
}
บจก.สยามเอวีเอส
63 Moo 2 แพรกษาใหม่ เมือง สมุทรปราการ
นำเข้า-จำหน่าย เครื่องจักร cnc มือสองญี่ปุ่น
ติดต่อ คุณ ธนเดช  084-387-2401
EMAIL kiattub@gmail.com
คลิกลิ้งแอดไลน์ได้เลย Line id : boysiamavs
http://line.me/ti/p/~boysiamavs