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

ใครใจดีช่วยเขียน Indicator ง่ายๆให้สักตัวได้ไหม

  • 16 replies
  • 5,205 views
*

iRuler

  • 1,282
Re: ใครใจดีช่วยเขียน Indicator ง่ายๆให้สักตัวได้ไหม
« ตอบกลับ #15 เมื่อ: 02, กันยายน 2019, 08:37:45 AM »
โค๊ด [Select]
//+------------------------------------------------------------------+
//|                                       Indicator: Trand Trade.mq4 |
//|                                       Created with EABuilder.com |
//|                                             http://eabuilder.com |
//|                                 Modified by [email protected]|
//+------------------------------------------------------------------+
#property copyright "Created with EABuilder.com"
#property link      "http://eabuilder.com"
#property version   "1.00"
#property description ""

#include <stdlib.mqh>
#include <stderror.mqh>

//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 2

#property indicator_type1 DRAW_ARROW
#property indicator_width1 4
#property indicator_color1 0xFFAA00
#property indicator_label1 "Buy"

#property indicator_type2 DRAW_ARROW
#property indicator_width2 4
#property indicator_color2 0x0000FF
#property indicator_label2 "Sell"

//--- indicator buffers
double Buffer1[];
double Buffer2[];

double myPoint; //initialized in OnInit
int latest_low_index=0;
int latest_hi_index=0;
int hilow=-1;

input int MinDistance=10;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void myAlert(string type,string message)
  {
   if(type=="print")
      Print(message);
   else if(type=="error")
     {
      Print(type+" | Trand Trade @ "+Symbol()+","+IntegerToString(Period())+" | "+message);
     }
   else if(type=="order")
     {
     }
   else if(type=="modify")
     {
     }
  }
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   IndicatorBuffers(2);
   SetIndexBuffer(0,Buffer1);
   SetIndexEmptyValue(0,0);
   SetIndexArrow(0,241);
   SetIndexBuffer(1,Buffer2);
   SetIndexEmptyValue(1,0);
   SetIndexArrow(1,242);
//initialize myPoint
   myPoint=Point();
   if(Digits()==5 || Digits()==3)
     {
      myPoint*=10;
     }
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   int limit=rates_total-prev_calculated;
//--- counting from 0 to rates_total
   ArraySetAsSeries(Buffer1,true);
   ArraySetAsSeries(Buffer2,true);
//--- initial zero
   if(prev_calculated<1)
     {
      ArrayInitialize(Buffer1,0);
      ArrayInitialize(Buffer2,0);
     }
   else
      limit++;

//--- main loop
   latest_low_index=limit;
   latest_hi_index=limit;

   for(int i=limit-1; i>=0; i--)
     {
      if(i>=MathMin(5000-1,rates_total-1-50)) continue; //omit some old rates to prevent "Array out of range" or slow calculation   
                                                        //Indicator Buffer 1
      if(iMA(NULL,PERIOD_CURRENT,20,0,MODE_EMA,PRICE_CLOSE,i)>iMA(NULL,PERIOD_CURRENT,50,0,MODE_EMA,PRICE_CLOSE,i) //Moving Average > Moving Average
         && Low[i]<=iMA(NULL,PERIOD_CURRENT,50,0,MODE_EMA,PRICE_CLOSE,i) //Candlestick Low <= Moving Average
         && latest_low_index-i>MinDistance
         && (hilow==1 || hilow==-1)
         )
        {
         Buffer1[i]=Low[i]; //Set indicator value at Candlestick Low
         latest_low_index=i;
         hilow=0;
        }
      else
        {
         Buffer1[i]=0;
        }
      //Indicator Buffer 2
      if(iMA(NULL,PERIOD_CURRENT,20,0,MODE_EMA,PRICE_CLOSE,i)<iMA(NULL,PERIOD_CURRENT,50,0,MODE_EMA,PRICE_CLOSE,i) //Moving Average < Moving Average
         && High[i]>=iMA(NULL,PERIOD_CURRENT,50,0,MODE_EMA,PRICE_CLOSE,i) //Candlestick High >= Moving Average
         && latest_hi_index-i>MinDistance
         && (hilow==0 || hilow==-1)
         )
        {
         Buffer2[i]=High[i]; //Set indicator value at Candlestick High
         latest_hi_index=i;
         hilow=1;
        }
      else
        {
         Buffer2[i]=0;
        }
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+

Re: ใครใจดีช่วยเขียน Indicator ง่ายๆให้สักตัวได้ไหม
« ตอบกลับ #16 เมื่อ: 02, กันยายน 2019, 08:50:37 AM »
อ้างจาก: iRuler ที่ 02, กันยายน  2019, 08:37:45 AM
โค๊ด [Select]
//+------------------------------------------------------------------+
//|                                       Indicator: Trand Trade.mq4 |
//|                                       Created with EABuilder.com |
//|                                             http://eabuilder.com |
//|                                 Modified by [email protected]|
//+------------------------------------------------------------------+
#property copyright "Created with EABuilder.com"
#property link      "http://eabuilder.com"
#property version   "1.00"
#property description ""

#include <stdlib.mqh>
#include <stderror.mqh>

//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 2

#property indicator_type1 DRAW_ARROW
#property indicator_width1 4
#property indicator_color1 0xFFAA00
#property indicator_label1 "Buy"

#property indicator_type2 DRAW_ARROW
#property indicator_width2 4
#property indicator_color2 0x0000FF
#property indicator_label2 "Sell"

//--- indicator buffers
double Buffer1[];
double Buffer2[];

double myPoint; //initialized in OnInit
int latest_low_index=0;
int latest_hi_index=0;
int hilow=-1;

input int MinDistance=10;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void myAlert(string type,string message)
  {
   if(type=="print")
      Print(message);
   else if(type=="error")
     {
      Print(type+" | Trand Trade @ "+Symbol()+","+IntegerToString(Period())+" | "+message);
     }
   else if(type=="order")
     {
     }
   else if(type=="modify")
     {
     }
  }
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   IndicatorBuffers(2);
   SetIndexBuffer(0,Buffer1);
   SetIndexEmptyValue(0,0);
   SetIndexArrow(0,241);
   SetIndexBuffer(1,Buffer2);
   SetIndexEmptyValue(1,0);
   SetIndexArrow(1,242);
//initialize myPoint
   myPoint=Point();
   if(Digits()==5 || Digits()==3)
     {
      myPoint*=10;
     }
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   int limit=rates_total-prev_calculated;
//--- counting from 0 to rates_total
   ArraySetAsSeries(Buffer1,true);
   ArraySetAsSeries(Buffer2,true);
//--- initial zero
   if(prev_calculated<1)
     {
      ArrayInitialize(Buffer1,0);
      ArrayInitialize(Buffer2,0);
     }
   else
      limit++;

//--- main loop
   latest_low_index=limit;
   latest_hi_index=limit;

   for(int i=limit-1; i>=0; i--)
     {
      if(i>=MathMin(5000-1,rates_total-1-50)) continue; //omit some old rates to prevent "Array out of range" or slow calculation   
                                                        //Indicator Buffer 1
      if(iMA(NULL,PERIOD_CURRENT,20,0,MODE_EMA,PRICE_CLOSE,i)>iMA(NULL,PERIOD_CURRENT,50,0,MODE_EMA,PRICE_CLOSE,i) //Moving Average > Moving Average
         && Low[i]<=iMA(NULL,PERIOD_CURRENT,50,0,MODE_EMA,PRICE_CLOSE,i) //Candlestick Low <= Moving Average
         && latest_low_index-i>MinDistance
         && (hilow==1 || hilow==-1)
         )
        {
         Buffer1[i]=Low[i]; //Set indicator value at Candlestick Low
         latest_low_index=i;
         hilow=0;
        }
      else
        {
         Buffer1[i]=0;
        }
      //Indicator Buffer 2
      if(iMA(NULL,PERIOD_CURRENT,20,0,MODE_EMA,PRICE_CLOSE,i)<iMA(NULL,PERIOD_CURRENT,50,0,MODE_EMA,PRICE_CLOSE,i) //Moving Average < Moving Average
         && High[i]>=iMA(NULL,PERIOD_CURRENT,50,0,MODE_EMA,PRICE_CLOSE,i) //Candlestick High >= Moving Average
         && latest_hi_index-i>MinDistance
         && (hilow==0 || hilow==-1)
         )
        {
         Buffer2[i]=High[i]; //Set indicator value at Candlestick High
         latest_hi_index=i;
         hilow=1;
        }
      else
        {
         Buffer2[i]=0;
        }
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+


ขอบพระคุณมากมายครับ