Jump to content

KG GGH Signal EA


ido370

Recommended Posts

Hello,

currently i am using the KG GGH Signal indicator on Daily TF with MA 8 setting on EURUSD. I wanted to create an EA of this indicator but since i have never done this before, i don't get it working correctly like the indicator.

Who can take a look at the files and convert it to an EA (maybe with iCustom) so that it takes all buy and sell orders when the arrows appear on the indicator?

This is the code from the indicator:

 

#property copyright "Copyright © 2007, Kang_Gun"
#property link      ""

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_color2 Red

extern bool Alert_ON = TRUE;
extern int MA = 8;
double g_ibuf_84[];
double g_ibuf_88[];
int gi_92 = 0;
int gi_96 = 0;

int init() {
  SetIndexStyle(0, DRAW_ARROW, EMPTY);
  SetIndexArrow(0, 233);
  SetIndexBuffer(0, g_ibuf_84);
  SetIndexStyle(1, DRAW_ARROW, EMPTY);
  SetIndexArrow(1, 234);
  SetIndexBuffer(1, g_ibuf_88);
  return (0);
}

int deinit() {
  return (0);
}

int start() {
  int li_8;
  double l_ima_20;
  double l_ima_28;
  double l_ima_36;
  double l_ima_44;
  double ld_52;
  double ld_60;
  double ld_unused_12 = 0;
  int li_68 = IndicatorCounted();
  if (li_68 < 0) return (-1);
  if (li_68 > 0) li_68--;
  int li_0 = Bars - li_68;
  for (int li_4 = 1; li_4 <= li_0; li_4++) {
     li_8 = li_4;
     ld_52 = 0;
     ld_60 = 0;
     for (li_8 = li_4; li_8 <= li_4 + 9; li_8++) ld_60 += MathAbs(High[li_8] - Low[li_8]);
     ld_52 = ld_60 / 10.0;
     l_ima_20 = iMA(NULL, 0, MA, -1, MODE_LWMA, PRICE_TYPICAL, li_4);
     l_ima_36 = iMA(NULL, 0, MA, -1, MODE_LWMA, PRICE_TYPICAL, li_4 + 1);
     l_ima_28 = iMA(NULL, 0, MA, 0, MODE_LWMA, PRICE_TYPICAL, li_4);
     l_ima_44 = iMA(NULL, 0, MA, 0, MODE_LWMA, PRICE_TYPICAL, li_4 + 1);
     g_ibuf_84[li_4] = 0;
     g_ibuf_88[li_4] = 0;
     if (l_ima_20 > l_ima_28 && l_ima_36 < l_ima_44) {
        if (li_4 == 1 && gi_92 == FALSE) {
           gi_92 = TRUE;
           gi_96 = FALSE;
           if (Alert_ON) {
              Alert("BUY signal at Ask=", Ask, 
                 "\n Bid=", Bid, 
                 "\n Time=", TimeToStr(TimeCurrent(), TIME_DATE), " ", TimeHour(TimeCurrent()), ":", TimeMinute(TimeCurrent()), 
              "\n Symbol=", Symbol(), " Period=", Period());
           }
        }
        g_ibuf_84[li_4] = Low[li_4] - ld_52 / 2.0;
     } else {
        if (l_ima_20 < l_ima_28 && l_ima_36 > l_ima_44) {
           if (li_4 == 1 && gi_96 == FALSE) {
              gi_96 = TRUE;
              gi_92 = FALSE;
              if (Alert_ON) {
                 Alert("SELL signal at Ask=", Ask, 
                    "\n Bid=", Bid, 
                    "\n Date=", TimeToStr(TimeCurrent(), TIME_DATE), " ", TimeHour(TimeCurrent()), ":", TimeMinute(TimeCurrent()), 
                 "\n Symbol=", Symbol(), " Period=", Period());
              }
           }
           g_ibuf_88[li_4] = High[li_4] + ld_52 / 2.0;
        }
     }
  }
  return (0);
}

 

An this is my first try for an EA, but its not working exactly the same somehow... :

 

//+------------------------------------------------------------------+
//|                                                   KG GGH EA.mq4 |
//|                                      Copyright © 2007, Kang_Gun |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, Kang_Gun"
#property link      ""

//+------------------------------------------------------------------+
//| Global Variables / Includes                                      |
//+------------------------------------------------------------------+
extern int MA = 8;
double g_ibuf_84[];
double g_ibuf_88[];
int gi_92 = 0;
int gi_96 = 0;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
 {
//----
  SetIndexStyle(0, DRAW_ARROW, EMPTY);
  SetIndexArrow(0, 233);
  SetIndexBuffer(0, g_ibuf_84);
  SetIndexStyle(1, DRAW_ARROW, EMPTY);
  SetIndexArrow(1, 234);
  SetIndexBuffer(1, g_ibuf_88);
//----
  return(0);
 }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
 {
//----
  
//----
  return(0);
 }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
 {
//----
  int li_8;
  double l_ima_20;
  double l_ima_28;
  double l_ima_36;
  double l_ima_44;
  double ld_52;
  double ld_60;
  double ld_unused_12 = 0;
  int li_68 = Bars - 1;
  if (li_68 < 0) return (-1);
  if (li_68 > 0) li_68--;
  int li_0 = Bars - li_68;
  for (int li_4 = 1; li_4 <= li_0; li_4++) {
     li_8 = li_4;
     ld_52 = 0;
     ld_60 = 0;
     for (li_8 = li_4; li_8 <= li_4 + 9; li_8++) ld_60 += MathAbs(High[li_8] - Low[li_8]);
     ld_52 = ld_60 / 10.0;
     l_ima_20 = iMA(NULL, 0, MA, -1, MODE_LWMA, PRICE_TYPICAL, li_4);
     l_ima_36 = iMA(NULL, 0, MA, -1, MODE_LWMA, PRICE_TYPICAL, li_4 + 1);
     l_ima_28 = iMA(NULL, 0, MA, 0, MODE_LWMA, PRICE_TYPICAL, li_4);
     l_ima_44 = iMA(NULL, 0, MA, 0, MODE_LWMA, PRICE_TYPICAL, li_4 + 1);
     g_ibuf_84[li_4] = 0;
     g_ibuf_88[li_4] = 0;
     if (l_ima_20 > l_ima_28 && l_ima_36 < l_ima_44) {
        if (li_4 == 1 && gi_92 == FALSE) {
           gi_92 = TRUE;
           gi_96 = FALSE;
                          // CLOSE ALL OPEN AND PENDING ORDERS
                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);
   }  
 }
 // END CLOSING ORDERS
           OrderSend("EURUSD",OP_BUY,0.1,Ask,10,NULL,NULL,NULL,5582,0,Blue);
           
        }
        g_ibuf_84[li_4] = Low[li_4] - ld_52 / 2.0;
     } else {
        if (l_ima_20 < l_ima_28 && l_ima_36 > l_ima_44) {
           if (li_4 == 1 && gi_96 == FALSE) {
              gi_96 = TRUE;
              gi_92 = FALSE;
              // CLOSE ALL OPEN AND PENDING ORDERS
   OrderSelect(i, SELECT_BY_POS);
   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);
   }  
 }
 // END OF CLOSING ORDERS
              OrderSend("EURUSD",OP_SELL,0.1,Bid,10,NULL,NULL,NULL,5582,0,Blue);
             
           }
           g_ibuf_88[li_4] = High[li_4] + ld_52 / 2.0;
        }
     }
  }
//----
  return(0);

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

Edited by ido370
Link to comment
Share on other sites

I think you should post this in the coding section. Moreover, you can't work with buffers in EAs.

 

See MQL website: http://www.mql4.com/

 

Here's a simple solution. Use the MACD EA that's included default in MT4.

Use iCustom() to call the indicator and get the signals.

Set signal as variable. If signal ==0, then no trade. If signal==1, enter long, etc.

Thanks for the kudos...much appreciated!
Link to comment
Share on other sites

hmm seems that i dont have the default macd ea not anymore on my system. can you help me on my way how to set the signal as a variable and what icustom command i should use then?

right now i have updated it, but its just not the same as the indicator... strange...

//+------------------------------------------------------------------+
//|                                                   KG GGH EA.mq4 |
//|                                      Copyright © 2010, Kang_Gun |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, Kang_Gun"
#property link      ""

//+------------------------------------------------------------------+
//| Global Variables / Includes                                      |
//+------------------------------------------------------------------+
extern int MagicNumber = 5582;
extern int MA = 8;
extern double Lots = 0.1;
double g_ibuf_84[];
double g_ibuf_88[];
int gi_92 = 0;
int gi_96 = 0;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
 {
//----
  SetIndexStyle(0, DRAW_ARROW, EMPTY);
  SetIndexArrow(0, 233);
  SetIndexBuffer(0, g_ibuf_84);
  SetIndexStyle(1, DRAW_ARROW, EMPTY);
  SetIndexArrow(1, 234);
  SetIndexBuffer(1, g_ibuf_88);
//----
  return(0);
 }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
 {
//----
  
//----
  return(0);
 }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
 {
//----
  int total  = OrdersTotal();
  int li_8;
  double l_ima_20;
  double l_ima_28;
  double l_ima_36;
  double l_ima_44;
  double ld_52;
  double ld_60;
  double ld_unused_12 = 0;
  int li_68 = Bars - 1;
  if (li_68 < 0) return (-1);
  if (li_68 > 0) li_68--;
  int li_0 = Bars - li_68;
  for (int li_4 = 1; li_4 <= li_0; li_4++) {
     li_8 = li_4;
     ld_52 = 0;
     ld_60 = 0;
     for (li_8 = li_4; li_8 <= li_4 + 9; li_8++) ld_60 += MathAbs(High[li_8] - Low[li_8]);
     ld_52 = ld_60 / 10.0;
     l_ima_20 = iMA(NULL, 0, MA, -1, MODE_LWMA, PRICE_TYPICAL, li_4);
     l_ima_36 = iMA(NULL, 0, MA, -1, MODE_LWMA, PRICE_TYPICAL, li_4 + 1);
     l_ima_28 = iMA(NULL, 0, MA, 0, MODE_LWMA, PRICE_TYPICAL, li_4);
     l_ima_44 = iMA(NULL, 0, MA, 0, MODE_LWMA, PRICE_TYPICAL, li_4 + 1);
     g_ibuf_84[li_4] = 0;
     g_ibuf_88[li_4] = 0;
     if (l_ima_20 > l_ima_28 && l_ima_36 < l_ima_44) {
        if (li_4 == 1 && gi_92 == FALSE) {
           gi_92 = TRUE;
           gi_96 = FALSE;
         
              OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
              if ((total>0)&& OrderMagicNumber() == MagicNumber)
              {
                 if(OrderType()==OP_SELL) 
                    OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),3);
                    if(OrderType()==OP_BUY) 
                    OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),3);
              }
              OrderSend(Symbol(),OP_BUY,Lots,Ask,10,NULL,NULL,NULL,MagicNumber,0,Blue); 
           
           
        }
        g_ibuf_84[li_4] = Low[li_4] - ld_52 / 2.0;
     } else {
        if (l_ima_20 < l_ima_28 && l_ima_36 > l_ima_44) {
           if (li_4 == 1 && gi_96 == FALSE) {
              gi_96 = TRUE;
              gi_92 = FALSE;
              
              OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
              if ((total>0)&& OrderMagicNumber() == MagicNumber)
              {
                 if(OrderType()==OP_BUY)
                    OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),3);
                 if(OrderType()==OP_SELL) 
                 OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),3);
              }
              OrderSend(Symbol(),OP_SELL,Lots,Bid,10,NULL,NULL,NULL,MagicNumber,0,Red); 

 }
              
             
           }
           g_ibuf_88[li_4] = High[li_4] + ld_52 / 2.0;
        }
     }
  }
//----
  return(0);

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

Link to comment
Share on other sites

Try this one. I'm not sure what you actually named the indicator, but here is the indy with the same name the EA is using (or just change the name in the EA).

 

http://www.4shared.com/file/0SKXCguG/KG_GGH_Signal.html

 

Here are some of the settings that need explaining:

UseClosedCandle = wait until candle is closed.

MA - period from indicator.

UseStdSL = fixed SL.

UseSRStopLoss = set SL to previous fractal level.

UseStdTP = fixed TP.

UseStdBE = break even at x number of pips (see below).

BreakEvenPips = how many pips after entry for BE

LockInPips = how many pips to lock in profit after BE

UseSRTrailStop = moves SL to previous fractal +/- SLPipDiff (plus spread if AddSpread = true)

UseCandleTrail = moves SL to previous (defined by TrailCandlesBack) candle H/L +/- SLPipDiff (and spread).

UseNewsFilter = news avoidance.

MinsBeforeNews = how many minutes before news to stop trading.

MinsAfterNews = how many minutes after news to stop trading.

NewsImpact = 1-low , 2-medium , 3=high

UseHourTrade1/2 = two different trading sessions can be used.

Link to comment
Share on other sites

Try this one. I'm not sure what you actually named the indicator, but here is the indy with the same name the EA is using (or just change the name in the EA).

 

http://www.4shared.com/file/0SKXCguG/KG_GGH_Signal.html

 

Here are some of the settings that need explaining:

UseClosedCandle = wait until candle is closed.

MA - period from indicator.

UseStdSL = fixed SL.

UseSRStopLoss = set SL to previous fractal level.

UseStdTP = fixed TP.

UseStdBE = break even at x number of pips (see below).

BreakEvenPips = how many pips after entry for BE

LockInPips = how many pips to lock in profit after BE

UseSRTrailStop = moves SL to previous fractal +/- SLPipDiff (plus spread if AddSpread = true)

UseCandleTrail = moves SL to previous (defined by TrailCandlesBack) candle H/L +/- SLPipDiff (and spread).

UseNewsFilter = news avoidance.

MinsBeforeNews = how many minutes before news to stop trading.

MinsAfterNews = how many minutes after news to stop trading.

NewsImpact = 1-low , 2-medium , 3=high

UseHourTrade1/2 = two different trading sessions can be used.

 

 

thanks for your input, but when i want to backtest, i cannot change all settings (like MM to false). Why is that? And is it only trading when an arrow appears on the indicator?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...