ido370 Posted December 24, 2010 Report Share Posted December 24, 2010 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); //+------------------------------------------------------------------+ Quote Link to comment Share on other sites More sharing options...
ido370 Posted December 25, 2010 Author Report Share Posted December 25, 2010 according to San4x he mentioned: 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. Can someone help me to do so? 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); //+------------------------------------------------------------------+ Quote Link to comment Share on other sites More sharing options...
stovedude Posted December 25, 2010 Report Share Posted December 25, 2010 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.htmlHere 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. Quote Link to comment Share on other sites More sharing options...
ido370 Posted December 25, 2010 Author Report Share Posted December 25, 2010 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? Quote Link to comment Share on other sites More sharing options...
ido370 Posted December 25, 2010 Author Report Share Posted December 25, 2010 (edited) i attached image from backtesting from 01.01.2010 to 01.12.2010, you can see the trades it make, but i want it to trade according to the arrows from the indicator, so it should look like what i draw with the white lines: http://i56.tinypic.com/htuqgw.jpg full size image: http://i51.tinypic.com/iqg2m0.jpg Edited December 25, 2010 by ido370 Quote Link to comment Share on other sites More sharing options...
ido370 Posted December 25, 2010 Author Report Share Posted December 25, 2010 i think the problem is that the icustom command to read the signals from the indicator is not good. right now it is: double EntryUp = iCustom(Symbol(),0,"KG GGH Signal",false,MA,0,SignalCandle); double EntryDn = iCustom(Symbol(),0,"KG GGH Signal",false,MA,1,SignalCandle); what should be the right code to get the signals from the indicator? Quote Link to comment Share on other sites More sharing options...
stovedude Posted December 25, 2010 Report Share Posted December 25, 2010 (edited) http://img190.imageshack.us/i/stovedude1.gif/I just backtested the same currency and TF and got this result. I watched it visually and it was definitely trading each arrow, but however, the arrows will sometimes disappear when price reverses. Also, are you sure you are using the same MA period on the indy as in the EA? http://img190.imageshack.us/img190/4940/stovedude1.gif http://img190.imageshack.us/i/stovedude1.gif/ Edited December 25, 2010 by stovedude Quote Link to comment Share on other sites More sharing options...
ido370 Posted December 26, 2010 Author Report Share Posted December 26, 2010 (edited) can you upload the images somewhere else? because right now i cannot see them. and with which model do you backtest? open prices only, every tick or control points. Also it seems i only get trades when MM is ON, and UseClosedCadle is True. but i dont want any options in it. Just buy when a buy signal appears (and close only open sell trades with same magicnumber), and Sell when sell signal appears (and only close open buy orders with same magicnumber) could you adjust it maybe? i purely want it to trade based on the indicator arrows. open trades MAY be closed when signal arrow dissapears. this is what i have with your edition: http://i52.tinypic.com/14bm45j.png big version: http://i52.tinypic.com/14bm45j.png http://img190.imageshack.us/i/stovedude1.gif/I just backtested the same currency and TF and got this result. I watched it visually and it was definitely trading each arrow, but however, the arrows will sometimes disappear when price reverses. Also, are you sure you are using the same MA period on the indy as in the EA? http://img190.imageshack.us/img190/4940/stovedude1.gif http://img190.imageshack.us/i/stovedude1.gif/ Edited December 26, 2010 by ido370 Quote Link to comment Share on other sites More sharing options...
stovedude Posted December 26, 2010 Report Share Posted December 26, 2010 I used every tick. Can you copy and paste the parameters you used in your test or are they defaults? http://img190.imageshack.us/img190/4940/stovedude1.gif Quote Link to comment Share on other sites More sharing options...
ido370 Posted December 26, 2010 Author Report Share Posted December 26, 2010 I used every tick. Can you copy and paste the parameters you used in your test or are they defaults? http://img190.imageshack.us/img190/4940/stovedude1.gif i changed almost everything to off, since i dont want any options, just trade from indicator arrow to arrow. except when arrow dissapears, orders should be closed. here your screenshot with some errors marked: -at the white line it should have bought -at the yellow line, it should not have stopped until the next green arrow up around 10 may or so.. -at the red line, it should have bought and kept open until next red arrow on around august 9, now it closes already earlier (dont know why) -at the blue line it should buy . now it already buys before, and closes too late the buy order around september 12 looks good , but is also closed before red arrow appears http://i52.tinypic.com/2exq7g4.jpg bigger version: http://i52.tinypic.com/2exq7g4.jpg right now i have my code like this (without any options, just like the indicator) but also it wont buy/sell at the right position: //+------------------------------------------------------------------+ //| KG GGH IDO.mq4 | //| Copyright © 2010, Ido Kasse | //| | //+------------------------------------------------------------------+ #property copyright "Copyright © 2010, Ido Kasse" #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; //CloseAll orders void CloseAll() { int total = OrdersTotal(); for (int cnt = 0 ; cnt < total ; cnt++) { OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); if(OrderType()==OP_BUY&& OrderMagicNumber()==5582) OrderClose(OrderTicket(),OrderLots(),Bid,NULL, Yellow); if(OrderType()==OP_SELL&& OrderMagicNumber()==5582) OrderClose(OrderTicket(),OrderLots(),Ask,NULL, Yellow); } } //+------------------------------------------------------------------+ //| 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; 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; CloseAll(); 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; CloseAll(); 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); //+------------------------------------------------------------------+ Quote Link to comment Share on other sites More sharing options...
ido370 Posted December 26, 2010 Author Report Share Posted December 26, 2010 right now i am backtesting my code from above at every tick, and first trades seems to become the same as your version, going to sleep now, will see how it went tommorow morning when the backtest is finished (takes a long time.... especially in virtual machine :). see you tommorow Quote Link to comment Share on other sites More sharing options...
stovedude Posted December 26, 2010 Report Share Posted December 26, 2010 Looks like there is a perfect explanation of what's happening: At the white line, it did buy on the next candle (you can set UseClosedCandle=false if you don't want to wait for the candle to close before entering the trade). Also note that the signal may not come immediately on the next candle open. Sometimes the arrow will show somewhere in the middle of the candle. At the yellow line it sold on the next candle, but at the next lower fractal, an Up arrow appeared and triggered a buy (you can see on visual backtest) and the sell closed, but the arrow later disappeared as price continued down, which killed the buy trade. So what we're experiencing here is a repainting problem. If you visually backtest the indicator, you will see how these arrows disappear. As you explained in the last post, the orders should be closed if the arrows disappear. That is our only solution. Entering the opposite trade again when they disappear is probably not a good option. At the red line, it bought and, like before, had a Down arrow which closed the buy and opened the sell. The Down arrow disappeared, which orphaned the sell. Quote Link to comment Share on other sites More sharing options...
stovedude Posted December 26, 2010 Report Share Posted December 26, 2010 BTW, your version has the Ordersend inside the for () function, so it will try to trade all arrows in past history the moment you attach the EA. You will also need to code for the disappearing trick. I'll put that in my version. Quote Link to comment Share on other sites More sharing options...
stovedude Posted December 26, 2010 Report Share Posted December 26, 2010 Here is the one for the disappearing act, but that also presents another problem, because if the arrow disappears, the trade closes (at a loss), and sometimes the arrow will reappear, and the lost trade could have been continued for a profit. Perhaps we should check at the next bar for the missing arrow... http://www.4shared.com/file/yEz6YE1L/KG_GGH_Signal_EA10.html Quote Link to comment Share on other sites More sharing options...
ido370 Posted December 26, 2010 Author Report Share Posted December 26, 2010 (edited) i noticed this too :) but by adding the CCI (see below) its not opening a trade inmediately anymore, since it has to be in line with the CCI value. if it does open a trade order when attaching the EA, i think it can be considered a good signal. Right now, im just finishing adding CCI(14) in it (CCI value can be changed in EA options). When CCI value > 100 then sell is allowed, when CCI < -100 then buy is allowed. will backtest now and see if it makes any difference. Also when a sell order is open, and the CCI value becomes > 200 then it closes the order. Same for open buy orders, when for a open buy order the CCI value drops below -200 it closes too. also i made a check for existing buy or sell orders, so that when the buy arrow disappears, and later comes back, it wont open a second buy order but continues the already open order. Only when buy order reaches CCI value of -200 or an opposite valid signal(ggh singal and cci value) kicks in, it gets closed, and existing orders variable is reset :) i will post result and code later when backtesting is finished. *new* -added small print message to journal when buy or sell signal is received with the current CCI value, to see better why trade is taken / not taken. -display current date onscreen with time, to see better where it is when backtesting -display current CCI value onscreen with arial, size 14 -check for existing orders (like mentioned above) to keep current order open until valid opposite signal or cci value of 200 or -200 -added customizable soundfile when buy/sell order is taken (standard file is alert.wav) BTW, your version has the Ordersend inside the for () function, so it will try to trade all arrows in past history the moment you attach the EA. You will also need to code for the disappearing trick. I'll put that in my version. Edited December 26, 2010 by ido370 Quote Link to comment Share on other sites More sharing options...
ido370 Posted December 26, 2010 Author Report Share Posted December 26, 2010 (edited) ok. finished first backtest for this year. html report: http://people.zeelandnet.nl/famkasse/StrategyTester.htm seems like it was lucky :) only 1 big trade in profit. i think im gonna have to change the some values where the trade should stop, since this one kept going... here my latest code update: //+------------------------------------------------------------------+ //| KG GGH IDO.mq4 | //| Copyright © 2010, Ido Kasse | //| | //+------------------------------------------------------------------+ #property copyright "Copyright © 2010, Ido Kasse" #property link "" //+------------------------------------------------------------------+ //| Global Variables / Includes | //+------------------------------------------------------------------+ extern int MagicNumber = 5582; extern int MA = 8; extern int CCI = 14; extern double Lots = 0.1; extern string SoundFilename = "alert.wav"; double g_ibuf_84[]; double g_ibuf_88[]; int gi_92 = 0; int gi_96 = 0; string trend; double CciVal; double GetCci; int exist = 0; //CHECK EXISTING ORDERS void CheckOrders() { int total = OrdersTotal(); for (int cnt = 0 ; cnt < total ; cnt++) { OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); if(OrderType()==OP_BUY&& OrderMagicNumber()==5582) exist = 1; if(OrderType()==OP_SELL&& OrderMagicNumber()==5582) exist = 1; } } //CLOSE BUY ORDER void CloseBuy() { int total = OrdersTotal(); for (int cnt = 0 ; cnt < total ; cnt++) { OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); if(OrderType()==OP_BUY&& OrderMagicNumber()==5582) OrderClose(OrderTicket(),OrderLots(),Bid,NULL, Yellow); exist = 0; } } //CLOSE SELL ORDER void CloseSell() { int total = OrdersTotal(); for (int cnt = 0 ; cnt < total ; cnt++) { OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); if(OrderType()==OP_SELL&& OrderMagicNumber()==5582) OrderClose(OrderTicket(),OrderLots(),Ask,NULL, Yellow); exist = 0; } } //CLOSE ORDER BY CCI VALUE void ClosebyCci() { int total = OrdersTotal(); for (int cnt = 0 ; cnt < total ; cnt++) { OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); //CLOSE SELL ORDER WHEN CCI VALUE IS > 200 if(OrderType()==OP_SELL&& OrderMagicNumber()==5582&&(CciVal > 200)) OrderClose(OrderTicket(),OrderLots(),Ask,NULL, Yellow); //CLOSE BUY ORDER WHEN CCI VALUE IS > -200 if(OrderType()==OP_BUY&& OrderMagicNumber()==5582&&(CciVal > -200)) OrderClose(OrderTicket(),OrderLots(),Bid,NULL, Yellow); exist = 0; } } //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- IndicatorBuffers(2); 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); //CREATE CCI LABEL ObjectCreate("CCI_label",OBJ_LABEL,0,0,0); ObjectSet("CCI_label",OBJPROP_XDISTANCE,10); ObjectSet("CCI_label",OBJPROP_YDISTANCE,20); //CREATE DATE LABEL ObjectCreate("date_label",OBJ_LABEL,0,0,0); ObjectSet("date_label",OBJPROP_XDISTANCE,10); ObjectSet("date_label",OBJPROP_YDISTANCE,40); //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //DELETE DATE AND CCI LABEL ObjectDelete("CCI_label"); ObjectDelete("date_label"); //---- 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; 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; //CHECK CCI VALUES FOR TREND VARIABLE double GetCci = iCCI(Symbol(),1440,CCI,PRICE_CLOSE,0); CciVal = GetCci; if (CciVal > 100) trend = "Up"; if (CciVal < -100) trend = "Down"; //WRITE CCI VALUE AND DATE ONSCREEN Comment(ObjectSetText("CCI_label", StringConcatenate("CCI: ", CciVal),14,"Arial",White)); Comment(ObjectSetText("date_label", StringConcatenate("Date: ", Day() ,"-", Month(), "-", Year(), " Time: ", Hour(), ":",Minute(), " or ", " @ ",TimeToStr(CurTime())),14,"Arial",White)); //CLOSE OPEN ORDERS BY CCI VALUE OF 200 OR -200 ClosebyCci(); 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; //CHECK FOR EXISTING BUY ORDER CheckOrders(); //WRITE SIGNAL AND CCI VALUE TO JOURNAL Print("BUY SIGNAL with CCI value: ", CciVal); //OPEN BUY ORDER if (trend=="Down"&&exist==0) {CloseSell(); OrderSend(Symbol(),OP_BUY,Lots,Ask,10,NULL,NULL,NULL,MagicNumber,0,Blue); PlaySound(SoundFilename);} } 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; //CHECK FOR EXISTING SELL ORDER CheckOrders(); //WRITE SIGNAL AND CCI VALUE TO JOURNAL Print("SELL SIGNAL with CCI value: ", CciVal); //OPEN SELL ORDER if (trend=="Up"&&exist==0) {CloseBuy(); OrderSend(Symbol(),OP_SELL,Lots,Bid,10,NULL,NULL,NULL,MagicNumber,0,Red); PlaySound(SoundFilename);} } } g_ibuf_88[li_4] = High[li_4] + ld_52 / 2.0; } } } //---- return(0); //+------------------------------------------------------------------+ CCI stopout value in this code is still at 200 / -200 according to strategytester report. P.S. just made a mistake with the checkorder function. i now separated it in checkbuyorder and checksellorder, and also the exist variable is now changed to existsell and existbuy. right now, im running optimize function to find good cci value Edited December 26, 2010 by ido370 Quote Link to comment Share on other sites More sharing options...
precision_trader Posted April 5, 2011 Report Share Posted April 5, 2011 Updates? Any new progress on this EA? Would like to know the test results. Thanks !!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.