/* * touch_top - Touch the line in all windows * which is visible above a given line */ static void touch_top(PANEL *panel, int line, _obscured_list *obs, int start_x, int end_x) { PANEL *pnl; _obscured_list *next_obs; do { pnl = obs -> panel_p; if ((next_obs = obs->next) == panel -> obscured -> next) next_obs = 0; if (line >= obs -> start && line <= obs -> end && pnl->wstartx <= end_x && pnl->wendx >= start_x) { (void) touchline(pnl->win, line - pnl->wstarty, 1); if (pnl->wstartx > start_x && pnl->wendx < end_x) { if (next_obs) touch_top(panel, line, next_obs, pnl->wendx+1, end_x); end_x = pnl -> wstartx - 1; } else { if (pnl->wstartx <= start_x) start_x = pnl -> wendx + 1; if (pnl->wendx >= end_x) end_x = pnl -> wstartx - 1; if (start_x > end_x) return; } } } while ((obs = next_obs) != 0); }
//+------------------------------------------------------------------+ //| Check for open order conditions | //+------------------------------------------------------------------+ void CheckForOpen() { double ma_cur; double ma_prev1; double ma_prev2; //---- go trading only for first tiks of new bar if(Volume[0] > 1){ return; } //---- get Moving Average ma_cur = iMA(NULL, 0, MA_PERIOD, 0, MODE_SMA, PRICE_CLOSE, 0); ma_prev1 = iMA(NULL, 0, MA_PERIOD, 0, MODE_SMA, PRICE_CLOSE, 1); ma_prev2 = iMA(NULL, 0, MA_PERIOD, 0, MODE_SMA, PRICE_CLOSE, 2); //---- buy conditions if(touch_bottom(ma_cur, ma_prev1, ma_prev2)) { OrderSend(Symbol(), OP_SELL, NormalizeDouble(AccountFreeMargin()*0.1/1000.0,1), Bid, 3, 0, 0, "", MAGICMA, 0, Blue); return; } //---- sell conditions if(touch_top(ma_cur, ma_prev1, ma_prev2)) { OrderSend(Symbol(), OP_BUY, NormalizeDouble(AccountFreeMargin()*0.1/1000.0,1), Ask, 3, 0, 0, "", MAGICMA, 0, Red); return; } //---- }
/* touchup - Touch lines in obscuring panals as necessary */ static void touchup(PANEL *panel) { int screen_y, i; /* * for each line in the window which has been touched, * touch lines in panals above it. */ screen_y = panel->wendy; for (i = panel->wendy - panel->wstarty; i >= 0; screen_y--, i--) { if (is_linetouched(panel -> win, i) == TRUE) touch_top(panel, screen_y, panel->obscured->next, panel->wstartx, panel->wendx); } }
//+------------------------------------------------------------------+ //| Check for close order conditions | //+------------------------------------------------------------------+ void CheckForClose() { double ma_cur; double ma_prev1; double ma_prev2; //---- go trading only for first tiks of new bar if(Volume[0] > 1) { return; } //---- get Moving Average ma_cur = iMA(NULL, 0, MA_PERIOD, 0, MODE_SMA, PRICE_CLOSE, 0); ma_prev1 = iMA(NULL, 0, MA_PERIOD, 0, MODE_SMA, PRICE_CLOSE, 1); ma_prev2 = iMA(NULL, 0, MA_PERIOD, 0, MODE_SMA, PRICE_CLOSE, 2); //---- for(int i = 0;i < OrdersTotal();i++) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == false){ break; } if(OrderMagicNumber() != MAGICMA || OrderSymbol() != Symbol()){ continue; } //---- check order type if(OrderType() == OP_BUY) { if(cross_below(ma_cur, ma_prev1) || touch_bottom(ma_cur, ma_prev1, ma_prev2) || OrderProfit() > AccountFreeMargin()*(-0.07)){ OrderClose(OrderTicket(), OrderLots(), Bid, 3, White); } break; } if(OrderType() == OP_SELL) { if(cross_above(ma_cur, ma_prev1) || touch_top(ma_cur, ma_prev1, ma_prev2)|| OrderProfit() > AccountFreeMargin()*(-0.07)){ OrderClose(OrderTicket(), OrderLots(), Ask, 3, White); } break; } } //---- }