Navigation:Home > Content >

Bogie-NeuralNetwork-1.mq4

Time: 2014-07-05 | Download file:Bogie-NeuralNetwork-1.mq4

#property copyright "Copyright © 2008, Bogie Enterprises"
#property link      "http://www.metaquotes.net/"



#import "shell32.dll"
   int ShellExecuteA(int a0, string a1, string a2, string a3, string a4, int a5);
#import


extern bool UseMM = TRUE;
extern bool MiniAcct = FALSE;
extern double Risk = 5.0;
extern double Lots = 0.0;
extern int StartTime = 20;
extern int TakeProfit = 100;
extern int StopLoss = 100;
extern int MaxOrders = 1;
extern double avg = 2.8;
extern int HiLi = 28;
extern int LoLi = 20;
extern int x2 = 14;
extern int x3 = 30;
extern double MinMarginLevel = 100.0;
extern int Server_Local_Difference = 6;
extern int MagicNumber = 12345;
int gi_160 = 1;
double range;
int trail_size = 0;
int gi_176 = 1;
double g_price_180;
string gs_dummy_188;
int gi_196;
int day_of_week = 0;
int gi_unused_204 = 0;
double sl_price = 0.0;
double tp_price = 0.0;
string str_name = "";
int day = 0;
double gd_236 = 1.0;
int Range = 0;
int g_ticket_248 = 0;
int orders = 0;
double gd_256;

int gi_268 = 777;
string time_to_str;

bool gi_288 = FALSE;
bool gi_unused_292 = FALSE;
int g_datetime_296 = 0;
bool gi_300 = FALSE;
bool gi_304 = FALSE;

int init() {
  
   return (0);
}

int start() {
   int ticket;
 
   bool BUY_Sign = FALSE;
   bool SELL_Sign = FALSE;

 
   if (day != TimeDay(TimeCurrent())) day = 0;
   double red_line = iCustom(NULL, 0, "Bogie-NN-IND-v1", 0, 1);
   double blue_line = iCustom(NULL, 0, "Bogie-NN-IND-v1", 1, 1);
 
   range = (iHigh(Symbol(), PERIOD_D1, 0) - iLow(Symbol(), PERIOD_D1, 0)) / avg;
   if (day == 0 && Hour() == StartTime && iClose(Symbol(), PERIOD_D1, 0) > iHigh(Symbol(), PERIOD_D1, 0) - range && red_line > blue_line) BUY_Sign = TRUE;
   if (day == 0 && Hour() == StartTime && iClose(Symbol(), PERIOD_D1, 0) < iLow(Symbol(), PERIOD_D1, 0) + range && red_line < blue_line) SELL_Sign = TRUE;
   int time = StartTime - Server_Local_Difference;
   if (time < 0)time += 24;
   if (MyOrdersTotal() == 0) {
      gi_unused_204 = 0;
      gi_196 = 0;
   }
   if (MyOrdersTotal() == 0) {
      Range = range / Point;
      str_name = "EntryGap";
   }
   if (MyOrdersTotal() != 0) {
      Range = trail_size * gd_236;
      str_name = "ExitGap";
   }
   Comment(str_name, " = ", Range, "  --  Profit Pips = ", BuyGap(), 
      "\nVolume = ", Volume[0], "   ---   Server Time = ", TimeToStr(TimeCurrent(), TIME_MINUTES), 
      "\nServer Trade Time = ", StartTime, ":00", 
      "\nLocal Trade Time = ",time, ":00", 
      "\nAccount Balance = " + DoubleToStr(AccountBalance(), 2) + "   ===  Account Equity = " + DoubleToStr(AccountEquity(), 2));
   bool li_36 = FALSE;
   bool li_40 = FALSE;
   if (BuyGap() > gi_196) gi_196 = BuyGap();
   trail_size = MathRound((iHigh(Symbol(), PERIOD_D1, 0) - iLow(Symbol(), PERIOD_D1, 0)) / avg / Point);
   if (trail_size < LoLi) trail_size = x2;
   if (trail_size > HiLi) trail_size = x3;
   if (MyOrdersTotal() == 0 && AccountEquity() / (AccountMargin() + 0.0001) > MinMarginLevel / 100.0) {
      sl_price = 0;
      tp_price = 0;
      if (BUY_Sign == TRUE) {
         day_of_week = DayOfWeek();
         gi_unused_204 = 1;
         g_price_180 = 0;
         gd_236 = 1;
         day = TimeDay(TimeCurrent());
         if (StopLoss > 0) sl_price = iClose(Symbol(), PERIOD_D1, 0) - StopLoss * Point;
         if (TakeProfit > 0) tp_price = iClose(Symbol(), PERIOD_D1, 0) + TakeProfit * Point;
         for (orders = MaxOrders - 1; orders >= 0; orders--) {
            ticket = 0;
            while (!IsTradeAllowed()) Sleep(5000);
            RefreshRates();
            ticket = OrderSend(Symbol(), OP_BUY, LotsOptimized(), Ask, 3, sl_price, tp_price, "BUYSignal", MagicNumber, 0, Blue);
            if (ticket > 0) {
               if (OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES)) Print("BUY order opened : ", OrderOpenPrice());
            } else Print("Error opening BUY order : ", GetLastError());
         }
        
         return (0);
      }
      if (SELL_Sign == TRUE) {
         day_of_week = DayOfWeek();
         gi_unused_204 = 2;
         g_price_180 = 0;
         gd_236 = 1;
         day = TimeDay(TimeCurrent());
         if (StopLoss > 0) sl_price = iClose(Symbol(), PERIOD_D1, 0) + StopLoss * Point;
         if (TakeProfit > 0) tp_price = iClose(Symbol(), PERIOD_D1, 0) - TakeProfit * Point;
         for (orders = MaxOrders - 1; orders >= 0; orders--) {
            ticket = 0;
            while (!IsTradeAllowed()) Sleep(5000);
            RefreshRates();
            ticket = OrderSend(Symbol(), OP_SELL, LotsOptimized(), Bid, 3, sl_price, tp_price, "SELLSignal", MagicNumber, 0, Red);
            if (ticket > 0) {
               if (OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES)) Print("SELL order opened : ", OrderOpenPrice());
            } else Print("Error opening SELL order : ", GetLastError());
         }
        
         return (0);
      }
   }
   gd_256 = MarketInfo(Symbol(), MODE_STOPLEVEL) + gi_160;
   if (gd_256 < 4.0) gd_256 = 4;
   int l_ord_total_48 = OrdersTotal();
   for (int l_pos_52 = 0; l_pos_52 < l_ord_total_48; l_pos_52++) {
      OrderSelect(l_pos_52, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
         g_ticket_248 = OrderTicket();
         if (OrderType() == OP_BUY) {
            if (gi_176 == 1) {
               if (OrderClosePrice() - OrderOpenPrice() > trail_size * gd_236 * Point) {
                  g_price_180 = NormalizeDouble(OrderOpenPrice() + trail_size * gd_236 * Point - gd_256 * Point, Digits);
                  gd_236 += 0.5;
               }
               if (g_price_180 > OrderStopLoss() + Point && g_price_180 > 0.0 && g_price_180 != OrderStopLoss()) OrderModify(OrderTicket(), OrderOpenPrice(), g_price_180, OrderTakeProfit(), 0, GreenYellow);
            }
            if (li_36 == TRUE) {
               OrderClose(OrderTicket(), OrderLots(), Bid, 3, Violet);
              
            }
         }
         if (OrderType() == OP_SELL) {
            if (gi_176 == 1) {
               if (OrderOpenPrice() - OrderClosePrice() > trail_size * gd_236 * Point) {
                  g_price_180 = NormalizeDouble(OrderOpenPrice() - trail_size * gd_236 * Point + gd_256 * Point, Digits);
                  gd_236 += 0.5;
               }
               if (g_price_180 < OrderStopLoss() - Point && g_price_180 > 0.0 && g_price_180 != OrderStopLoss()) OrderModify(OrderTicket(), OrderOpenPrice(), g_price_180, OrderTakeProfit(), 0, Red);
            }
            if (li_40 == TRUE) {
               OrderClose(OrderTicket(), OrderLots(), Ask, 3, Violet);
             
            }
         }
      }
   }
   return (0);
}

int MyOrdersTotal() {
   int l_count_0 = 0;
   for (int l_pos_4 = 0; l_pos_4 < OrdersTotal(); l_pos_4++) {
      if (OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES))
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) l_count_0++;
   }
   return (l_count_0);
}

int BuyGap() {
   double ld_ret_0 = 0;
   for (int l_pos_8 = 0; l_pos_8 < OrdersTotal(); l_pos_8++) {
      if (OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
            if (OrderType() == OP_BUY) ld_ret_0 = (OrderClosePrice() - OrderOpenPrice()) / Point;
            if (OrderType() == OP_SELL) ld_ret_0 = (OrderOpenPrice() - OrderClosePrice()) / Point;
         }
      }
   }
   return (ld_ret_0);
}


double LotsOptimized() {
   if (UseMM == FALSE) return (Lots);
   double l_lots_0 = Lots;
   int li_unused_8 = OrdersHistoryTotal();
   double ld_unused_12 = 0;
   int li_20 = 1;
   if (MarketInfo(Symbol(), MODE_LOTSTEP) == 1.0) li_20 = 1;
   if (MiniAcct == TRUE) li_20 = 2;
   l_lots_0 = NormalizeDouble(AccountFreeMargin() * Risk / 100.0 / 1000.0, li_20);
   if (l_lots_0 < 0.1 && MiniAcct == FALSE) l_lots_0 = 0.1;
   if (l_lots_0 < 0.01 && MiniAcct == TRUE) l_lots_0 = 0.01;
   if (l_lots_0 > 50.0) l_lots_0 = 50;
   return (l_lots_0);
}

Recommend