กองทุน SPDR GOLD SHARES
ถือทองก่อนหน้า
ถือทองล่าสุด
0.00
*หน่วยตัน / ราคาอ้างอิงล่าสุดจากสมาคมค้าทองคำ
สถิติกองทุน SPDR
ราคาทองคำแท่ง 96.5%
ราคาอ้างอิงล่าสุดจากสมาคมค้าทองคำ
ครั้งที่
ราคาก่อนหน้า
ราคาล่าสุด
0
(หน่วย บาท*) / อัปเดตล่าสุดเมื่อวันที่ 13 ก.ค. 2566 เวลา 13:04 น.
สถิติราคาทองคำ ไทย

ช่วยโมอินดี้ Forex ArrowFibo EP.1 ให้มี Alert

  • 1 replies
  • 2,330 views
ช่วยโมอินดี้ Forex ArrowFibo EP.1 ให้มี Alert
« เมื่อ: 09, ตุลาคม 2018, 08:09:14 PM »

รบกวนช่วยโมอินดี้  Forex ArrowFibo EP.1
https://traderider.com/index.php/topic,11759.0.html

แล้วใส่ Alert PopUp เข้าไป  และใส่ Line notify เข้าไปให้หน่อยได้ใหมครับ

โค๊ด  Line notify จากในกระทู้นี้ครับ
https://medium.com/@peeradonmekup/มาเขียน-mql4-ส่ง-line-notify-กันเถอะ-15c573a33c9

เวลามีลูกศรก็ส่ง alert เตือนครับ

เวลาใช้ก็เปิดใส่ไว้ใน VPS ทิ้งไว้ไว้แล้วให้ส่ง line มาบอกครับ

*

annope56

Re: ช่วยโมอินดี้ Forex ArrowFibo EP.1 ให้มี Alert
« ตอบกลับ #1 เมื่อ: 24, มกราคม 2019, 08:55:48 PM »
อ้างจาก: forcebewithyou ที่ 09, ตุลาคม  2018, 08:09:14 PM

รบกวนช่วยโมอินดี้  Forex ArrowFibo EP.1
https://traderider.com/index.php/topic,11759.0.html

แล้วใส่ Alert PopUp เข้าไป  และใส่ Line notify เข้าไปให้หน่อยได้ใหมครับ

โค๊ด  Line notify จากในกระทู้นี้ครับ
https://medium.com/@peeradonmekup/มาเขียน-mql4-ส่ง-line-notify-กันเถอะ-15c573a33c9

เวลามีลูกศรก็ส่ง alert เตือนครับ

เวลาใช้ก็เปิดใส่ไว้ใน VPS ทิ้งไว้ไว้แล้วให้ส่ง line มาบอกครับ

สอบถามหน่อยครับ ถ้าต้องการไปประยุกต์ใช้กับ code ข้างล่างให้ส่ง alert ผ่าน line ตามเงื่อนไข ต้องแก้ไขบรรทัดไหนครับ
ผมทำแล้วมันไม่แจ้งเตือนผ่าน line

//========= A_InputParam =========//
input int Magic = 88888; // Magic number
input double FixedLots = 0.0;   // if > 0.0 fixed lots used
input bool AutoLots = False;
input double Lot = 0.1;
input double RETURN_FACTOR = 2;
input double RISK_FACTOR = 1;
input double Risk = 0.01;       // per cent of free margin of a single offer
input int SHIFTSL = 40;
input int MaxSpread = 20;
input int MaxOrders = 1; // How many orders script can open on current symbol
input int Slippage = 30;
input int FAST_MA = 18;
input int SLOW_MA = 50;
input int SL_BAR = 7;
input bool ENABLEPUSH = TRUE;
input bool ENABLETRADE = TRUE ;
input string Token = "";

//========= A_InputParam =========//

int Ticket, LastOrder = 2;
string OPSTATE = "HOLD";
double BUY_SL = 0;
double SELL_SL = 0;

int start() { // Executed when there is new tick.
   
   //========= B_Start =========//
   static datetime Close_Time;
   
   if (Close_Time != Time[0])
   {
   int m = 0; // m is a number of opened orders on current symbol.

   for ( int n = 0; n < OrdersTotal(); n++ ) {  // That loop search if there is opened order on current symbol.

      if ( OrderSelect ( n, SELECT_BY_POS ) ) { 

         if ( OrderSymbol() == Symbol() ) { 
         
            if ( OrderMagicNumber() == Magic ) { 
   
               Ticket = OrderTicket(); 
               if ( OrderSelect ( Ticket, SELECT_BY_TICKET ) == True ) { close(); } // If it found opened order, script jump to close() function which close orders and make trailing stops.
               m++;
            }

         }

      }

   }
   
   if ( m == 0 ) { LastOrder = 2; }
   if ( m < MaxOrders ) { open(); } // If MaxOrders are not reached it allow script to open one more order in order() function.
   
   Close_Time=Time[0];
   }
   
   //========= B_Start =========//
   
return ( 0 );
}

int entryCondition(){

  //========= C_EntryCondition =========//

    OPSTATE = "HOLD";
 
  int countHr = TimeHour(Time[1]);

  double FASTEMA = iMA(NULL,0,FAST_MA,0,MODE_EMA,PRICE_CLOSE,1);
  double SLOWEMA = iMA(NULL,0,SLOW_MA,0,MODE_EMA,PRICE_CLOSE,1);
 
  double bFASTEMA = iMA(NULL,0,FAST_MA,0,MODE_EMA,PRICE_CLOSE,2);
  double bSLOWEMA = iMA(NULL,0,SLOW_MA,0,MODE_EMA,PRICE_CLOSE,2);
 
  string FLAG = "HOLD";
 
  if ((bFASTEMA >= bSLOWEMA) && (FASTEMA < SLOWEMA)){
   FLAG = "BEAR";
  }else if ((bFASTEMA <= bSLOWEMA) && (FASTEMA > SLOWEMA)){
   FLAG = "BULL";
  }
 
  double val_close = iClose(NULL,0,1);
 
  double val_High = iHigh(NULL,0,iHighest(NULL,0,MODE_HIGH,SL_BAR,1));
  double val_low = iLow(NULL,0,iLowest(NULL,0,MODE_LOW,SL_BAR,1));
 
   if(FLAG == "BULL"){
      OPSTATE = "BUY";
   }else if(FLAG == "BEAR"){
      OPSTATE = "SELL";
   }else{
      OPSTATE = "HOLD";
   } 
   
   SELL_SL = val_High + (SHIFTSL * Point);
   BUY_SL = val_low - (SHIFTSL * Point);
   Print("|BUY_SL:"+BUY_SL+"|SELL_SL:"+SELL_SL);
   //========= C_EntryCondition =========//
  return(0);
}

int open() {

   //========= D_Open =========//
   double Lots;
 
   RefreshRates();  // RefreshRate() update Bid and Ask value.
   
   double SL = 0;
   double TP = 0;
   double ET = 0;
   double sellSLPoint = 0;
   double buySLPoint = 0; 
   
   static datetime Close_Time;
   
   OPSTATE = "HOLD";
   
   entryCondition();
   
   if ( ( Ask - Bid ) / Point < MaxSpread ) { // Checking, if spread is less than MaxSpread from inputs. If its Bigger, orders wont open

      if ( OPSTATE == "BUY" && LastOrder != 1 && isBUYPositionOpen() == false) { // LastOrder!= 1 prevent script from making a lot of same buy orders
         buySLPoint = ((Ask - BUY_SL) / Point);
         if (buySLPoint < 80){
          buySLPoint = 80;
          BUY_SL = Ask - (80 * Point);
         }
         Print("Ask - BUY_SL:" + (Ask - BUY_SL) + "buySLPoint:" + buySLPoint + "|BUY_SL:" + BUY_SL + "|Point:" + Point);
         SL = BUY_SL;
         TP = (Ask + (( buySLPoint * Point)* RETURN_FACTOR)) ;
         Lots = CalculateLotSize(buySLPoint);
         if(ENABLETRADE){
         Ticket = OrderSend ( Symbol(), OP_BUY, Lots, Ask, Slippage, SL, TP, NULL, Magic, 0, Green);
         }
         if(ENABLEPUSH){
          string headers;
char data[], result[];

headers="Authorization: Bearer "+Token+"\r\n   application/x-www-form-urlencoded\r\n";
Print(("Buy: Symbol(),"+ Ask + "|" + "Lots:" + Lots + "|SL:" + SL + "|TP:"));

int res = WebRequest("POST", "https://notify-api.line.me/api/notify", headers, 0, data, data, headers);
   if(res==-1)
     {
      Print("Error in WebRequest. Error code  =",GetLastError());
      MessageBox("Add the address 'https://notify-api.line.me' in the list of allowed URLs on tab 'Expert Advisors'","Error",MB_ICONINFORMATION);
     }
    return(INIT_SUCCEEDED);
          }
         
         LastOrder = 1; // It prevent script from making a lot of same buy orders
         OPSTATE = "HOLD";
      }
 
      if ( OPSTATE == "SELL" && LastOrder != 0 && isSELLPositionOpen() == false) { // LastOrder!= 0 prevent script from making a lot of same sell orders
         sellSLPoint = ((SELL_SL - Bid) / Point);
         if (sellSLPoint < 80){
          sellSLPoint = 80;
          SELL_SL = Bid + (80 * Point);
         }
         Print("Bid + SELL_SL:" + (Bid + SELL_SL) + "sellSLPoint:" + sellSLPoint + "|SELL_SL:" + SELL_SL + "|Point:" + Point);
         SL = SELL_SL;
         TP = (Bid - ((sellSLPoint * Point) * RETURN_FACTOR)) ;
         Lots = CalculateLotSize(sellSLPoint);
         if(ENABLETRADE){
         Ticket = OrderSend ( Symbol(), OP_SELL, Lots, Bid, Slippage, SL, TP, NULL, Magic, 0, Red);
         }
         
         if(ENABLEPUSH){string headers;
char data[], result[];

headers="Authorization: Bearer "+Token+"\r\n   application/x-www-form-urlencoded\r\n";

Print("SELL:"+ Bid + "|" + "Lots:" + Lots + "|SL:" + SL + "|TP:");


int res = WebRequest("POST", "https://notify-api.line.me/api/notify", headers, 0, data, data, headers);
   if(res==-1)
     {
      Print("Error in WebRequest. Error code  =",GetLastError());
      MessageBox("Add the address 'https://notify-api.line.me' in the list of allowed URLs on tab 'Expert Advisors'","Error",MB_ICONINFORMATION);
     }
     }
         LastOrder = 0; // It prevent script from making a lot of same sell orders
         OPSTATE = "HOLD";
      }     
   }
   
   //========= D_Open =========//
return ( 0 );
}

int close() {

return ( 0 );
}

double CalculateLotSize(double StopLoss)
{
    if(FixedLots > 0.0)
        return (FixedLots);

    double pipValue = MarketInfo(Symbol(), MODE_TICKVALUE);
    double lots = AccountFreeMargin() * Risk / (StopLoss * pipValue);
   
    double lotStep = MarketInfo(Symbol(), MODE_LOTSTEP);
    int digits = 0;
    if(lotStep <= 0.01)
        digits = 2;
    else if(lotStep <= 0.1)
        digits = 1;
    lots = NormalizeDouble(lots, digits);
     
      double minLots = MarketInfo(Symbol(), MODE_MINLOT);
      if(lots < minLots)
          lots = minLots;
     
      double maxLots = MarketInfo(Symbol(), MODE_MAXLOT);
      if(lots > maxLots)
          lots = maxLots;
     
      return (lots);
}

bool isSELLPositionOpen()
  {
   for(int i=0; i<OrdersTotal(); i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderMagicNumber()==Magic && OrderSymbol()==Symbol())
        {
         if(OrderType() == OP_SELL){
            return true;
         }else{
            return false;
         }
        }
     }
   return false;
  } 
 
bool isBUYPositionOpen()
  {
   for(int i=0; i<OrdersTotal(); i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderMagicNumber()==Magic && OrderSymbol()==Symbol())
        {
         if(OrderType() == OP_BUY){
            return true;
         }else{
            return false;
         }
        }
     }
   return false;
  }