edgar1713006556 Posted January 9, 2012 Report Posted January 9, 2012 here is the code of !e-forexy !e#property copyright "Copyright © 2005-2007, BJF Trading Group" #property link "www.iticsoftware.com" #include <stdlib.mqh> #include <stderror.mqh> #define major 3 #define minor 1 extern double Lots = 0.1; extern int Slippage = 3; extern int Magic = 20070922; extern int Swing = 10; extern int dy1 = 3; extern int dy2 = 3; extern double kSL = 0; extern double kTP = 0; extern int H = 0; extern int N = 0; extern int T1 = 8; extern int T2 = 11; extern int T3 = 14; extern int T4 = 17; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ datetime Time0 = 0; int init () { return(0); } int deinit() { return(0); } int start() { T1 = 8; T2 = 14; T3 = 17; T4 = 23; kSL = 1.9; kTP = 0.5; Swing = 20; dy1 = 2; dy2 = 2; if (!IsTesting()) Comment("Version: ", major, ".", minor); if (Time0 == Time[0]) return; Time0 = Time[0]; //Is it work time now? bool work_time = ((TimeHour(Time[0]) >= T1) && (TimeHour(Time[0]) < T2)) || ((TimeHour(Time[0]) >= T3) && (TimeHour(Time[0]) < T4)); //It is non-work time now //We should delete all the pending orders if (!work_time) { int cnt = OrdersTotal(); for (int i = cnt-1; i >= 0; i--) { if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue; if (OrderSymbol() != Symbol()) continue; if (OrderMagicNumber() != Magic) continue; int type = OrderType(); if (type == OP_BUYSTOP || type == OP_SELLSTOP) DeleteOrder(OrderTicket()); if (type == OP_BUYLIMIT || type == OP_SELLLIMIT) DeleteOrder(OrderTicket()); } return(0); } //It is work time now //In case we have an opened orders do nothing cnt = OrdersTotal(); for (i = 0; i < cnt; i++) { if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue; if (OrderSymbol() != Symbol()) continue; if (OrderMagicNumber() != Magic) continue; type = OrderType(); if (type == OP_BUY || type == OP_SELL) return(0); } //We need last opened order int ticket = GetLastOrder(); int LastTime = -1; //Last time is the OpenTime of last opened order if (ticket > 0) { OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES); LastTime = StrToInteger(OrderComment()); } //We check a new bar (Time[0] is the open time of current 0 bar) //Then we set a pending order once per bar if (LastTime < Time[0]) { int res = SetOrders(); return (res); } return (0); } //Function sets the EA pending orders int SetOrders() { /* for (int i=0; i < Bars; i++) { if (TimeHour(Time) == H && TimeMinute(Time) == 0) break; } */ int i = iBarShift(NULL, 0, iTime(NULL, PERIOD_D1, 0)); //We determine High and Low values, the time interval is [0:00 - now] //W is an amplitude //Avr is an average value double H = High[iHighest(NULL, 0, MODE_HIGH, i-1, 1)]; double L = Low[iLowest(NULL, 0, MODE_LOW, i-1, 1)]; double W = H - L; double Avr = (H + L)/2; //Swing is the parameter related to a calculation value W //We should throw off all the days with an amplitude less then Swing value if (W < Swing*Point) return (0); //Now in case the price < Avr - 1/2*Buffer we set BUYSTOP order at Avr + 1/2*Buffer //in case the price > Avr + 1/2*Buffer we set SELLSTOP order at Avr - 1/2*Buffer //The meaning of EA is the price breaks the 50% of daily range //Buffer parameter helps to cut off all the wrong breakdowns //BUYSTOP order it the same as BUY at order price //SELLSTOP order it the same as SELL at order price if (DayOfWeek() == 1) return; int StopLevel = MarketInfo(Symbol(), MODE_STOPLEVEL) + 1; if (Open[0] < Avr - dy1*Point) { double Price = Avr - dy2*Point; if (Price < Ask + StopLevel*Point) Price = Ask + StopLevel*Point; double SL = L - W*kSL; double TP = H + W*kTP; //SL = 0; int res = SetBuyStop(Symbol(), Lots, Price, Slippage, SL, TP, Magic, TimeCurrent()); return (res); } if (Open[0] > Avr + dy1*Point) { Price = Avr - dy2*Point; if (Price > Bid - StopLevel*Point) Price = Bid - StopLevel*Point; SL = H + W*kSL; TP = L - W*kTP; //SL = 0; res = SetSellStop(Symbol(), Lots, Price, Slippage, SL, TP, Magic, TimeCurrent()); return (res); } return (0); } //Gets the last opened orders int GetLastOrder() { int ticket = -1; int tm0 = 0; int cnt = OrdersTotal(); for (int i = 0; i < cnt; i++) { if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue; if (OrderSymbol() != Symbol()) continue; if (OrderMagicNumber() != Magic) continue; int type = OrderType(); if (type != OP_BUYSTOP && type != OP_SELLSTOP) continue; int LastTime = StrToInteger(OrderComment()); if (LastTime > tm0) { ticket = OrderTicket(); tm0 = OrderOpenTime(); } } return (ticket); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ int SleepOk = 2000; int SleepErr = 6000; //Service functions int SetBuyStop(string symbol, double lot, double price, int slip, double sl, double tp, int magic, string comment="", datetime exp = 0) { int dig = MarketInfo(symbol, MODE_DIGITS); price = NormalizeDouble(price, dig); sl = NormalizeDouble(sl, dig); tp = NormalizeDouble(tp, dig); string _lot = DoubleToStr(lot, 1); string _price = DoubleToStr(price, dig); string _sl = DoubleToStr(sl, dig); string _tp = DoubleToStr(tp, dig); Print("SetBuyStop \"", symbol, "\", ", _lot, ", ", _price, ", ", slip, ", ", _sl, ", ", _tp, ", ", magic, ", \"", comment, "\""); int res = OrderSend(symbol, OP_BUYSTOP, lot, price, slip, sl, tp, comment, magic, exp); if (res >= 0) { Sleep(SleepOk); return (res); } int code = GetLastError(); Print("Error setting BUYSTOP order: ", ErrorDescription(code), " (", code, ")"); Sleep(SleepErr); return (-1); } int SetSellStop(string symbol, double lot, double price, int slip, double sl, double tp, int magic, string comment="", datetime exp = 0) { int dig = MarketInfo(symbol, MODE_DIGITS); price = NormalizeDouble(price, dig); sl = NormalizeDouble(sl, dig); tp = NormalizeDouble(tp, dig); string _lot = DoubleToStr(lot, 1); string _price = DoubleToStr(price, dig); string _sl = DoubleToStr(sl, dig); string _tp = DoubleToStr(tp, dig); Print("SetSellStop \"", symbol, "\", ", _lot, ", ", _price, ", ", slip, ", ", _sl, ", ", _tp, ", ", magic, ", \"", comment, "\""); int res = OrderSend(symbol, OP_SELLSTOP, lot, price, slip, sl, tp, comment, magic, exp); if (res >= 0) { Sleep(SleepOk); return (res); } int code = GetLastError(); Print("Error setting SELLSTOP order: ", ErrorDescription(code), " (", code, ")"); Sleep(SleepErr); return (-1); } bool DeleteOrder(int ticket) { bool res = OrderDelete(ticket); if (res) { Sleep(SleepOk); return (res); } int code = GetLastError(); Print("DeleteOrder failed: ", ErrorDescription(code), " (", code, ")"); Sleep(SleepErr); return (false); } from 14decembre 2011 to Today it grow from 500$to 16184$ with setting:0.8lot!!! on backtest it work but doesn't work on demo help please
edgar1713006556 Posted January 9, 2012 Author Report Posted January 9, 2012 http://www.megaupload.com/?d=TYQJOEH1 link I have no trade on demo live
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now